UNPKG

@babylonjs/viewer

Version:

The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.

1 lines 97.2 kB
import{b as e,bw as t,V as s,u as n,v as o,bx as i,O as r,by as a,bz as l,M as h,bA as c,bB as d,aa as u,a7 as _,bk as p,R as m,H as y,Y as f,bj as g,m as b,T as v,C as A,b2 as x,L as w,bC as C,bD as M,bE as T,bF as O,bG as E,bH as S,aG as R,bI as k,bJ as P,t as L,bK as I,g as N,ap as D,br as $,bL as U,aI as V,Q as F,a2 as B,al as G,bM as W,aH as Y,bN as X,bO as Z,bP as K,bQ as z,bR as j,aS as H,a4 as q}from"./index-Bw2N6w1y.esm.min.js";import{B as J}from"./bone-BwMp7T0B.esm.min.js";import{S as Q}from"./skeleton-CkTZwWbM.esm.min.js";import{A as ee}from"./assetContainer-21j7tcC8.esm.min.js";import{G as te}from"./objectModelMapping-DX92iJ8M.esm.min.js";import"./rawTexture-CPAqHIA7.esm.min.js";class se{constructor(){this.keysUp=[38],this.keysUpward=[33],this.keysDown=[40],this.keysDownward=[34],this.keysLeft=[37],this.keysRight=[39],this.rotationSpeed=.5,this.keysRotateLeft=[],this.keysRotateRight=[],this.keysRotateUp=[],this.keysRotateDown=[],this._keys=new Array}attachControl(s){s=e.BackCompatCameraNoPreventDefault(arguments),this._onCanvasBlurObserver||(this._scene=this.camera.getScene(),this._engine=this._scene.getEngine(),this._onCanvasBlurObserver=this._engine.onCanvasBlurObservable.add((()=>{this._keys.length=0})),this._onKeyboardObserver=this._scene.onKeyboardObservable.add((e=>{const n=e.event;if(!n.metaKey)if(e.type===t.KEYDOWN){if(-1!==this.keysUp.indexOf(n.keyCode)||-1!==this.keysDown.indexOf(n.keyCode)||-1!==this.keysLeft.indexOf(n.keyCode)||-1!==this.keysRight.indexOf(n.keyCode)||-1!==this.keysUpward.indexOf(n.keyCode)||-1!==this.keysDownward.indexOf(n.keyCode)||-1!==this.keysRotateLeft.indexOf(n.keyCode)||-1!==this.keysRotateRight.indexOf(n.keyCode)||-1!==this.keysRotateUp.indexOf(n.keyCode)||-1!==this.keysRotateDown.indexOf(n.keyCode)){-1===this._keys.indexOf(n.keyCode)&&this._keys.push(n.keyCode),s||n.preventDefault()}}else if(-1!==this.keysUp.indexOf(n.keyCode)||-1!==this.keysDown.indexOf(n.keyCode)||-1!==this.keysLeft.indexOf(n.keyCode)||-1!==this.keysRight.indexOf(n.keyCode)||-1!==this.keysUpward.indexOf(n.keyCode)||-1!==this.keysDownward.indexOf(n.keyCode)||-1!==this.keysRotateLeft.indexOf(n.keyCode)||-1!==this.keysRotateRight.indexOf(n.keyCode)||-1!==this.keysRotateUp.indexOf(n.keyCode)||-1!==this.keysRotateDown.indexOf(n.keyCode)){const e=this._keys.indexOf(n.keyCode);e>=0&&this._keys.splice(e,1),s||n.preventDefault()}})))}detachControl(){this._scene&&(this._onKeyboardObserver&&this._scene.onKeyboardObservable.remove(this._onKeyboardObserver),this._onCanvasBlurObserver&&this._engine.onCanvasBlurObservable.remove(this._onCanvasBlurObserver),this._onKeyboardObserver=null,this._onCanvasBlurObserver=null),this._keys.length=0}checkInputs(){if(this._onKeyboardObserver){const e=this.camera;for(let t=0;t<this._keys.length;t++){const n=this._keys[t],o=e._computeLocalCameraSpeed();-1!==this.keysLeft.indexOf(n)?e._localDirection.copyFromFloats(-o,0,0):-1!==this.keysUp.indexOf(n)?e._localDirection.copyFromFloats(0,0,o):-1!==this.keysRight.indexOf(n)?e._localDirection.copyFromFloats(o,0,0):-1!==this.keysDown.indexOf(n)?e._localDirection.copyFromFloats(0,0,-o):-1!==this.keysUpward.indexOf(n)?e._localDirection.copyFromFloats(0,o,0):-1!==this.keysDownward.indexOf(n)?e._localDirection.copyFromFloats(0,-o,0):-1!==this.keysRotateLeft.indexOf(n)?(e._localDirection.copyFromFloats(0,0,0),e.cameraRotation.y-=this._getLocalRotation()):-1!==this.keysRotateRight.indexOf(n)?(e._localDirection.copyFromFloats(0,0,0),e.cameraRotation.y+=this._getLocalRotation()):-1!==this.keysRotateUp.indexOf(n)?(e._localDirection.copyFromFloats(0,0,0),e.cameraRotation.x-=this._getLocalRotation()):-1!==this.keysRotateDown.indexOf(n)&&(e._localDirection.copyFromFloats(0,0,0),e.cameraRotation.x+=this._getLocalRotation()),e.getScene().useRightHandedSystem&&(e._localDirection.z*=-1),e.getViewMatrix().invertToRef(e._cameraTransformMatrix),s.TransformNormalToRef(e._localDirection,e._cameraTransformMatrix,e._transformedDirection),e.cameraDirection.addInPlace(e._transformedDirection)}}}getClassName(){return"FreeCameraKeyboardMoveInput"}_onLostFocus(){this._keys.length=0}getSimpleName(){return"keyboard"}_getLocalRotation(){const e=this.camera._calculateHandednessMultiplier();return this.rotationSpeed*this._engine.getDeltaTime()/1e3*e}}n([o()],se.prototype,"keysUp",void 0),n([o()],se.prototype,"keysUpward",void 0),n([o()],se.prototype,"keysDown",void 0),n([o()],se.prototype,"keysDownward",void 0),n([o()],se.prototype,"keysLeft",void 0),n([o()],se.prototype,"keysRight",void 0),n([o()],se.prototype,"rotationSpeed",void 0),n([o()],se.prototype,"keysRotateLeft",void 0),n([o()],se.prototype,"keysRotateRight",void 0),n([o()],se.prototype,"keysRotateUp",void 0),n([o()],se.prototype,"keysRotateDown",void 0),i.FreeCameraKeyboardMoveInput=se;class ne{constructor(e=!0){this.touchEnabled=e,this.buttons=[0,1,2],this.angularSensibility=2e3,this._previousPosition=null,this.onPointerMovedObservable=new r,this._allowCameraRotation=!0,this._currentActiveButton=-1,this._activePointerId=-1}attachControl(t){t=e.BackCompatCameraNoPreventDefault(arguments);const s=this.camera.getEngine(),n=s.getInputElement();this._pointerInput||(this._pointerInput=e=>{const o=e.event,i="touch"===o.pointerType;if(!this.touchEnabled&&i)return;if(e.type!==a.POINTERMOVE&&-1===this.buttons.indexOf(o.button))return;const r=o.target;if(e.type===a.POINTERDOWN){if(i&&-1!==this._activePointerId||!i&&-1!==this._currentActiveButton)return;this._activePointerId=o.pointerId;try{r?.setPointerCapture(o.pointerId)}catch(e){}-1===this._currentActiveButton&&(this._currentActiveButton=o.button),this._previousPosition={x:o.clientX,y:o.clientY},t||(o.preventDefault(),n&&n.focus()),s.isPointerLock&&this._onMouseMove&&this._onMouseMove(e.event)}else if(e.type===a.POINTERUP){if(i&&this._activePointerId!==o.pointerId||!i&&this._currentActiveButton!==o.button)return;try{r?.releasePointerCapture(o.pointerId)}catch(e){}this._currentActiveButton=-1,this._previousPosition=null,t||o.preventDefault(),this._activePointerId=-1}else if(e.type===a.POINTERMOVE&&(this._activePointerId===o.pointerId||!i))if(s.isPointerLock&&this._onMouseMove)this._onMouseMove(e.event);else if(this._previousPosition){const e=this.camera._calculateHandednessMultiplier(),s=(o.clientX-this._previousPosition.x)*e,n=o.clientY-this._previousPosition.y;this._allowCameraRotation&&(this.camera.cameraRotation.y+=s/this.angularSensibility,this.camera.cameraRotation.x+=n/this.angularSensibility),this.onPointerMovedObservable.notifyObservers({offsetX:s,offsetY:n}),this._previousPosition={x:o.clientX,y:o.clientY},t||o.preventDefault()}}),this._onMouseMove=e=>{if(!s.isPointerLock)return;const n=this.camera._calculateHandednessMultiplier(),o=e.movementX*n;this.camera.cameraRotation.y+=o/this.angularSensibility;const i=e.movementY;this.camera.cameraRotation.x+=i/this.angularSensibility,this._previousPosition=null,t||e.preventDefault()},this._observer=this.camera.getScene()._inputManager._addCameraPointerObserver(this._pointerInput,a.POINTERDOWN|a.POINTERUP|a.POINTERMOVE),n&&(this._contextMenuBind=e=>this.onContextMenu(e),n.addEventListener("contextmenu",this._contextMenuBind,!1))}onContextMenu(e){e.preventDefault()}detachControl(){if(this._observer){if(this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer),this._contextMenuBind){const e=this.camera.getEngine().getInputElement();e&&e.removeEventListener("contextmenu",this._contextMenuBind)}this.onPointerMovedObservable&&this.onPointerMovedObservable.clear(),this._observer=null,this._onMouseMove=null,this._previousPosition=null}this._activePointerId=-1,this._currentActiveButton=-1}getClassName(){return"FreeCameraMouseInput"}getSimpleName(){return"mouse"}}n([o()],ne.prototype,"buttons",void 0),n([o()],ne.prototype,"angularSensibility",void 0),i.FreeCameraMouseInput=ne;class oe{constructor(){this.wheelPrecisionX=3,this.wheelPrecisionY=3,this.wheelPrecisionZ=3,this.onChangedObservable=new r,this._wheelDeltaX=0,this._wheelDeltaY=0,this._wheelDeltaZ=0,this._ffMultiplier=12,this._normalize=120}attachControl(t){t=e.BackCompatCameraNoPreventDefault(arguments),this._wheel=e=>{if(e.type!==a.POINTERWHEEL)return;const s=e.event,n=s.deltaMode===l.DOM_DELTA_LINE?this._ffMultiplier:1;this._wheelDeltaX+=this.wheelPrecisionX*n*s.deltaX/this._normalize,this._wheelDeltaY-=this.wheelPrecisionY*n*s.deltaY/this._normalize,this._wheelDeltaZ+=this.wheelPrecisionZ*n*s.deltaZ/this._normalize,s.preventDefault&&(t||s.preventDefault())},this._observer=this.camera.getScene()._inputManager._addCameraPointerObserver(this._wheel,a.POINTERWHEEL)}detachControl(){this._observer&&(this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer),this._observer=null,this._wheel=null),this.onChangedObservable&&this.onChangedObservable.clear()}checkInputs(){this.onChangedObservable.notifyObservers({wheelDeltaX:this._wheelDeltaX,wheelDeltaY:this._wheelDeltaY,wheelDeltaZ:this._wheelDeltaZ}),this._wheelDeltaX=0,this._wheelDeltaY=0,this._wheelDeltaZ=0}getClassName(){return"BaseCameraMouseWheelInput"}getSimpleName(){return"mousewheel"}}var ie,re,ae,le;n([o()],oe.prototype,"wheelPrecisionX",void 0),n([o()],oe.prototype,"wheelPrecisionY",void 0),n([o()],oe.prototype,"wheelPrecisionZ",void 0),function(e){e[e.MoveRelative=0]="MoveRelative",e[e.RotateRelative=1]="RotateRelative",e[e.MoveScene=2]="MoveScene"}(ie||(ie={}));class he extends oe{constructor(){super(...arguments),this._moveRelative=s.Zero(),this._rotateRelative=s.Zero(),this._moveScene=s.Zero(),this._wheelXAction=ie.MoveRelative,this._wheelXActionCoordinate=0,this._wheelYAction=ie.MoveRelative,this._wheelYActionCoordinate=2,this._wheelZAction=null,this._wheelZActionCoordinate=null}getClassName(){return"FreeCameraMouseWheelInput"}set wheelXMoveRelative(e){null===e&&this._wheelXAction!==ie.MoveRelative||(this._wheelXAction=ie.MoveRelative,this._wheelXActionCoordinate=e)}get wheelXMoveRelative(){return this._wheelXAction!==ie.MoveRelative?null:this._wheelXActionCoordinate}set wheelYMoveRelative(e){null===e&&this._wheelYAction!==ie.MoveRelative||(this._wheelYAction=ie.MoveRelative,this._wheelYActionCoordinate=e)}get wheelYMoveRelative(){return this._wheelYAction!==ie.MoveRelative?null:this._wheelYActionCoordinate}set wheelZMoveRelative(e){null===e&&this._wheelZAction!==ie.MoveRelative||(this._wheelZAction=ie.MoveRelative,this._wheelZActionCoordinate=e)}get wheelZMoveRelative(){return this._wheelZAction!==ie.MoveRelative?null:this._wheelZActionCoordinate}set wheelXRotateRelative(e){null===e&&this._wheelXAction!==ie.RotateRelative||(this._wheelXAction=ie.RotateRelative,this._wheelXActionCoordinate=e)}get wheelXRotateRelative(){return this._wheelXAction!==ie.RotateRelative?null:this._wheelXActionCoordinate}set wheelYRotateRelative(e){null===e&&this._wheelYAction!==ie.RotateRelative||(this._wheelYAction=ie.RotateRelative,this._wheelYActionCoordinate=e)}get wheelYRotateRelative(){return this._wheelYAction!==ie.RotateRelative?null:this._wheelYActionCoordinate}set wheelZRotateRelative(e){null===e&&this._wheelZAction!==ie.RotateRelative||(this._wheelZAction=ie.RotateRelative,this._wheelZActionCoordinate=e)}get wheelZRotateRelative(){return this._wheelZAction!==ie.RotateRelative?null:this._wheelZActionCoordinate}set wheelXMoveScene(e){null===e&&this._wheelXAction!==ie.MoveScene||(this._wheelXAction=ie.MoveScene,this._wheelXActionCoordinate=e)}get wheelXMoveScene(){return this._wheelXAction!==ie.MoveScene?null:this._wheelXActionCoordinate}set wheelYMoveScene(e){null===e&&this._wheelYAction!==ie.MoveScene||(this._wheelYAction=ie.MoveScene,this._wheelYActionCoordinate=e)}get wheelYMoveScene(){return this._wheelYAction!==ie.MoveScene?null:this._wheelYActionCoordinate}set wheelZMoveScene(e){null===e&&this._wheelZAction!==ie.MoveScene||(this._wheelZAction=ie.MoveScene,this._wheelZActionCoordinate=e)}get wheelZMoveScene(){return this._wheelZAction!==ie.MoveScene?null:this._wheelZActionCoordinate}checkInputs(){if(0===this._wheelDeltaX&&0===this._wheelDeltaY&&0==this._wheelDeltaZ)return;this._moveRelative.setAll(0),this._rotateRelative.setAll(0),this._moveScene.setAll(0),this._updateCamera(),this.camera.getScene().useRightHandedSystem&&(this._moveRelative.z*=-1);const e=h.Zero();this.camera.getViewMatrix().invertToRef(e);const t=s.Zero();s.TransformNormalToRef(this._moveRelative,e,t),this.camera.cameraRotation.x+=this._rotateRelative.x/200,this.camera.cameraRotation.y+=this._rotateRelative.y/200,this.camera.cameraDirection.addInPlace(t),this.camera.cameraDirection.addInPlace(this._moveScene),super.checkInputs()}_updateCamera(){this._updateCameraProperty(this._wheelDeltaX,this._wheelXAction,this._wheelXActionCoordinate),this._updateCameraProperty(this._wheelDeltaY,this._wheelYAction,this._wheelYActionCoordinate),this._updateCameraProperty(this._wheelDeltaZ,this._wheelZAction,this._wheelZActionCoordinate)}_updateCameraProperty(e,t,s){if(0===e)return;if(null===t||null===s)return;let n=null;switch(t){case ie.MoveRelative:n=this._moveRelative;break;case ie.RotateRelative:n=this._rotateRelative;break;case ie.MoveScene:n=this._moveScene}switch(s){case 0:n.set(e,0,0);break;case 1:n.set(0,e,0);break;case 2:n.set(0,0,e)}}}n([o()],he.prototype,"wheelXMoveRelative",null),n([o()],he.prototype,"wheelYMoveRelative",null),n([o()],he.prototype,"wheelZMoveRelative",null),n([o()],he.prototype,"wheelXRotateRelative",null),n([o()],he.prototype,"wheelYRotateRelative",null),n([o()],he.prototype,"wheelZRotateRelative",null),n([o()],he.prototype,"wheelXMoveScene",null),n([o()],he.prototype,"wheelYMoveScene",null),n([o()],he.prototype,"wheelZMoveScene",null),i.FreeCameraMouseWheelInput=he;class ce{constructor(t=!1){this.allowMouse=t,this.touchAngularSensibility=2e5,this.touchMoveSensibility=250,this.singleFingerRotate=!1,this._offsetX=null,this._offsetY=null,this._pointerPressed=new Array,this._isSafari=e.IsSafari()}attachControl(t){t=e.BackCompatCameraNoPreventDefault(arguments);let s=null;if(void 0===this._pointerInput&&(this._onLostFocus=()=>{this._offsetX=null,this._offsetY=null},this._pointerInput=e=>{const n=e.event,o="mouse"===n.pointerType||this._isSafari&&void 0===n.pointerType;if(this.allowMouse||!o)if(e.type===a.POINTERDOWN){if(t||n.preventDefault(),this._pointerPressed.push(n.pointerId),1!==this._pointerPressed.length)return;s={x:n.clientX,y:n.clientY}}else if(e.type===a.POINTERUP){t||n.preventDefault();const e=this._pointerPressed.indexOf(n.pointerId);if(-1===e)return;if(this._pointerPressed.splice(e,1),0!=e)return;s=null,this._offsetX=null,this._offsetY=null}else if(e.type===a.POINTERMOVE){if(t||n.preventDefault(),!s)return;if(0!=this._pointerPressed.indexOf(n.pointerId))return;this._offsetX=n.clientX-s.x,this._offsetY=-(n.clientY-s.y)}}),this._observer=this.camera.getScene()._inputManager._addCameraPointerObserver(this._pointerInput,a.POINTERDOWN|a.POINTERUP|a.POINTERMOVE),this._onLostFocus){const e=this.camera.getEngine().getInputElement();e&&e.addEventListener("blur",this._onLostFocus)}}detachControl(){if(this._pointerInput){if(this._observer&&(this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer),this._observer=null),this._onLostFocus){const e=this.camera.getEngine().getInputElement();e&&e.removeEventListener("blur",this._onLostFocus),this._onLostFocus=null}this._pointerPressed.length=0,this._offsetX=null,this._offsetY=null}}checkInputs(){if(null===this._offsetX||null===this._offsetY)return;if(0===this._offsetX&&0===this._offsetY)return;const e=this.camera,t=e._calculateHandednessMultiplier();e.cameraRotation.y=t*this._offsetX/this.touchAngularSensibility;if(this.singleFingerRotate&&1===this._pointerPressed.length||!this.singleFingerRotate&&this._pointerPressed.length>1)e.cameraRotation.x=-this._offsetY/this.touchAngularSensibility;else{const t=e._computeLocalCameraSpeed(),n=new s(0,0,0!==this.touchMoveSensibility?t*this._offsetY/this.touchMoveSensibility:0);h.RotationYawPitchRollToRef(e.rotation.y,e.rotation.x,0,e._cameraRotationMatrix),e.cameraDirection.addInPlace(s.TransformCoordinates(n,e._cameraRotationMatrix))}}getClassName(){return"FreeCameraTouchInput"}getSimpleName(){return"touch"}}n([o()],ce.prototype,"touchAngularSensibility",void 0),n([o()],ce.prototype,"touchMoveSensibility",void 0),i.FreeCameraTouchInput=ce;class de extends c{constructor(e){super(e),this._mouseInput=null,this._mouseWheelInput=null}addKeyboard(){return this.add(new se),this}addMouse(e=!0){return this._mouseInput||(this._mouseInput=new ne(e),this.add(this._mouseInput)),this}removeMouse(){return this._mouseInput&&this.remove(this._mouseInput),this}addMouseWheel(){return this._mouseWheelInput||(this._mouseWheelInput=new he,this.add(this._mouseWheelInput)),this}removeMouseWheel(){return this._mouseWheelInput&&this.remove(this._mouseWheelInput),this}addTouch(){return this.add(new ce),this}clear(){super.clear(),this._mouseInput=null}}class ue extends d{get angularSensibility(){const e=this.inputs.attached.mouse;return e?e.angularSensibility:0}set angularSensibility(e){const t=this.inputs.attached.mouse;t&&(t.angularSensibility=e)}get keysUp(){const e=this.inputs.attached.keyboard;return e?e.keysUp:[]}set keysUp(e){const t=this.inputs.attached.keyboard;t&&(t.keysUp=e)}get keysUpward(){const e=this.inputs.attached.keyboard;return e?e.keysUpward:[]}set keysUpward(e){const t=this.inputs.attached.keyboard;t&&(t.keysUpward=e)}get keysDown(){const e=this.inputs.attached.keyboard;return e?e.keysDown:[]}set keysDown(e){const t=this.inputs.attached.keyboard;t&&(t.keysDown=e)}get keysDownward(){const e=this.inputs.attached.keyboard;return e?e.keysDownward:[]}set keysDownward(e){const t=this.inputs.attached.keyboard;t&&(t.keysDownward=e)}get keysLeft(){const e=this.inputs.attached.keyboard;return e?e.keysLeft:[]}set keysLeft(e){const t=this.inputs.attached.keyboard;t&&(t.keysLeft=e)}get keysRight(){const e=this.inputs.attached.keyboard;return e?e.keysRight:[]}set keysRight(e){const t=this.inputs.attached.keyboard;t&&(t.keysRight=e)}get keysRotateLeft(){const e=this.inputs.attached.keyboard;return e?e.keysRotateLeft:[]}set keysRotateLeft(e){const t=this.inputs.attached.keyboard;t&&(t.keysRotateLeft=e)}get keysRotateRight(){const e=this.inputs.attached.keyboard;return e?e.keysRotateRight:[]}set keysRotateRight(e){const t=this.inputs.attached.keyboard;t&&(t.keysRotateRight=e)}get keysRotateUp(){const e=this.inputs.attached.keyboard;return e?e.keysRotateUp:[]}set keysRotateUp(e){const t=this.inputs.attached.keyboard;t&&(t.keysRotateUp=e)}get keysRotateDown(){const e=this.inputs.attached.keyboard;return e?e.keysRotateDown:[]}set keysRotateDown(e){const t=this.inputs.attached.keyboard;t&&(t.keysRotateDown=e)}constructor(e,t,n,o=!0){super(e,t,n,o),this.ellipsoid=new s(.5,1,.5),this.ellipsoidOffset=new s(0,0,0),this.checkCollisions=!1,this.applyGravity=!1,this._needMoveForGravity=!1,this._oldPosition=s.Zero(),this._diffPosition=s.Zero(),this._newPosition=s.Zero(),this._collisionMask=-1,this._onCollisionPositionChange=(e,t,s=null)=>{this._newPosition.copyFrom(t),this._newPosition.subtractToRef(this._oldPosition,this._diffPosition),this._diffPosition.length()>u.CollisionsEpsilon&&(this.position.addToRef(this._diffPosition,this._deferredPositionUpdate),this._deferOnly?this._deferredUpdated=!0:this.position.copyFrom(this._deferredPositionUpdate),this.onCollide&&s&&this.onCollide(s))},this.inputs=new de(this),this.inputs.addKeyboard().addMouse()}attachControl(t,s){s=e.BackCompatCameraNoPreventDefault(arguments),this.inputs.attachElement(s)}detachControl(){this.inputs.detachElement(),this.cameraDirection=new s(0,0,0),this.cameraRotation=new _(0,0)}get collisionMask(){return this._collisionMask}set collisionMask(e){this._collisionMask=isNaN(e)?-1:e}_collideWithWorld(e){let t;t=this.parent?s.TransformCoordinates(this.position,this.parent.getWorldMatrix()):this.position,t.subtractFromFloatsToRef(0,this.ellipsoid.y,0,this._oldPosition),this._oldPosition.addInPlace(this.ellipsoidOffset);const n=this.getScene().collisionCoordinator;this._collider||(this._collider=n.createCollider()),this._collider._radius=this.ellipsoid,this._collider.collisionMask=this._collisionMask;let o=e;this.applyGravity&&(o=e.add(this.getScene().gravity)),n.getNewPosition(this._oldPosition,o,this._collider,3,null,this._onCollisionPositionChange,this.uniqueId)}_checkInputs(){this._localDirection||(this._localDirection=s.Zero(),this._transformedDirection=s.Zero()),this.inputs.checkInputs(),super._checkInputs()}set needMoveForGravity(e){this._needMoveForGravity=e}get needMoveForGravity(){return this._needMoveForGravity}_decideIfNeedsToMove(){return this._needMoveForGravity||Math.abs(this.cameraDirection.x)>0||Math.abs(this.cameraDirection.y)>0||Math.abs(this.cameraDirection.z)>0}_updatePosition(){this.checkCollisions&&this.getScene().collisionsEnabled?this._collideWithWorld(this.cameraDirection):super._updatePosition()}dispose(){this.inputs.clear(),super.dispose()}getClassName(){return"FreeCamera"}}n([p()],ue.prototype,"ellipsoid",void 0),n([p()],ue.prototype,"ellipsoidOffset",void 0),n([o()],ue.prototype,"checkCollisions",void 0),n([o()],ue.prototype,"applyGravity",void 0),m("BABYLON.FreeCamera",ue);class _e{get influence(){return this._influence}set influence(e){if(this._influence===e)return;const t=this._influence;this._influence=e,this.onInfluenceChanged.hasObservers()&&this.onInfluenceChanged.notifyObservers(0===t||0===e)}get animationPropertiesOverride(){return!this._animationPropertiesOverride&&this._scene?this._scene.animationPropertiesOverride:this._animationPropertiesOverride}set animationPropertiesOverride(e){this._animationPropertiesOverride=e}constructor(e,t=0,s=null){this.name=e,this.animations=[],this._positions=null,this._normals=null,this._tangents=null,this._uvs=null,this._uv2s=null,this._colors=null,this._uniqueId=0,this.onInfluenceChanged=new r,this._onDataLayoutChanged=new r,this._animationPropertiesOverride=null,this.id=e,this._scene=s||y.LastCreatedScene,this.influence=t,this._scene&&(this._uniqueId=this._scene.getUniqueId())}get uniqueId(){return this._uniqueId}get hasPositions(){return!!this._positions}get hasNormals(){return!!this._normals}get hasTangents(){return!!this._tangents}get hasUVs(){return!!this._uvs}get hasUV2s(){return!!this._uv2s}get hasColors(){return!!this._colors}get vertexCount(){return this._positions?this._positions.length/3:this._normals?this._normals.length/3:this._tangents?this._tangents.length/3:this._uvs?this._uvs.length/2:this._uv2s?this._uv2s.length/2:this._colors?this._colors.length/4:0}setPositions(e){const t=this.hasPositions;this._positions=e,t!==this.hasPositions&&this._onDataLayoutChanged.notifyObservers(void 0)}getPositions(){return this._positions}setNormals(e){const t=this.hasNormals;this._normals=e,t!==this.hasNormals&&this._onDataLayoutChanged.notifyObservers(void 0)}getNormals(){return this._normals}setTangents(e){const t=this.hasTangents;this._tangents=e,t!==this.hasTangents&&this._onDataLayoutChanged.notifyObservers(void 0)}getTangents(){return this._tangents}setUVs(e){const t=this.hasUVs;this._uvs=e,t!==this.hasUVs&&this._onDataLayoutChanged.notifyObservers(void 0)}getUVs(){return this._uvs}setUV2s(e){const t=this.hasUV2s;this._uv2s=e,t!==this.hasUV2s&&this._onDataLayoutChanged.notifyObservers(void 0)}getUV2s(){return this._uv2s}setColors(e){const t=this.hasColors;this._colors=e,t!==this.hasColors&&this._onDataLayoutChanged.notifyObservers(void 0)}getColors(){return this._colors}clone(){const e=f.Clone((()=>new _e(this.name,this.influence,this._scene)),this);return e._positions=this._positions,e._normals=this._normals,e._tangents=this._tangents,e._uvs=this._uvs,e._uv2s=this._uv2s,e._colors=this._colors,e}serialize(){const e={};return e.name=this.name,e.influence=this.influence,e.positions=Array.prototype.slice.call(this.getPositions()),null!=this.id&&(e.id=this.id),this.hasNormals&&(e.normals=Array.prototype.slice.call(this.getNormals())),this.hasTangents&&(e.tangents=Array.prototype.slice.call(this.getTangents())),this.hasUVs&&(e.uvs=Array.prototype.slice.call(this.getUVs())),this.hasUV2s&&(e.uv2s=Array.prototype.slice.call(this.getUV2s())),this.hasColors&&(e.colors=Array.prototype.slice.call(this.getColors())),f.AppendSerializedAnimations(this,e),e}getClassName(){return"MorphTarget"}static Parse(e,t){const s=new _e(e.name,e.influence);if(s.setPositions(e.positions),null!=e.id&&(s.id=e.id),e.normals&&s.setNormals(e.normals),e.tangents&&s.setTangents(e.tangents),e.uvs&&s.setUVs(e.uvs),e.uv2s&&s.setUV2s(e.uv2s),e.colors&&s.setColors(e.colors),e.animations){for(let t=0;t<e.animations.length;t++){const n=e.animations[t],o=g("BABYLON.Animation");o&&s.animations.push(o.Parse(n))}e.autoAnimate&&t&&t.beginAnimation(s,e.autoAnimateFrom,e.autoAnimateTo,e.autoAnimateLoop,e.autoAnimateSpeed||1)}return s}static FromMesh(e,t,s){t||(t=e.name);const n=new _e(t,s,e.getScene());return n.setPositions(e.getVerticesData(b.PositionKind)),e.isVerticesDataPresent(b.NormalKind)&&n.setNormals(e.getVerticesData(b.NormalKind)),e.isVerticesDataPresent(b.TangentKind)&&n.setTangents(e.getVerticesData(b.TangentKind)),e.isVerticesDataPresent(b.UVKind)&&n.setUVs(e.getVerticesData(b.UVKind)),e.isVerticesDataPresent(b.UV2Kind)&&n.setUV2s(e.getVerticesData(b.UV2Kind)),e.isVerticesDataPresent(b.ColorKind)&&n.setColors(e.getVerticesData(b.ColorKind)),n}}n([o()],_e.prototype,"id",void 0);class pe extends v{get depth(){return this._depth}constructor(e,t,s,n,o,i,r=!0,a=!1,l=v.TRILINEAR_SAMPLINGMODE,h=A.TEXTURETYPE_UNSIGNED_BYTE,c){super(null,i,!r,a),this.format=o,this._texture=i.getEngine().createRawTexture2DArray(e,t,s,n,o,r,a,l,null,h,c),this._depth=n,this.is2DArray=!0}update(e){this._texture&&this._getEngine().updateRawTexture2DArray(this._texture,e,this._texture.format,this._texture.invertY,null,this._texture.type)}static CreateRGBATexture(e,t,s,n,o,i=!0,r=!1,a=A.TEXTURE_TRILINEAR_SAMPLINGMODE,l=A.TEXTURETYPE_UNSIGNED_BYTE){return new pe(e,t,s,n,A.TEXTUREFORMAT_RGBA,o,i,r,a,l)}}class me{set areUpdatesFrozen(e){e?this._blockCounter++:(this._blockCounter--,this._blockCounter<=0&&(this._blockCounter=0,this._syncActiveTargets(this._forceUpdateWhenUnfrozen),this._forceUpdateWhenUnfrozen=!1))}get areUpdatesFrozen(){return this._blockCounter>0}constructor(e=null){if(this._targets=new Array,this._targetInfluenceChangedObservers=new Array,this._targetDataLayoutChangedObservers=new Array,this._activeTargets=new x(16),this._supportsPositions=!1,this._supportsNormals=!1,this._supportsTangents=!1,this._supportsUVs=!1,this._supportsUV2s=!1,this._supportsColors=!1,this._vertexCount=0,this._uniqueId=0,this._tempInfluences=new Array,this._canUseTextureForTargets=!1,this._blockCounter=0,this._mustSynchronize=!0,this._forceUpdateWhenUnfrozen=!1,this._textureVertexStride=0,this._textureWidth=0,this._textureHeight=1,this._parentContainer=null,this.optimizeInfluencers=!0,this.enablePositionMorphing=!0,this.enableNormalMorphing=!0,this.enableTangentMorphing=!0,this.enableUVMorphing=!0,this.enableUV2Morphing=!0,this.enableColorMorphing=!0,this._numMaxInfluencers=0,this._useTextureToStoreTargets=!0,e||(e=y.LastCreatedScene),this._scene=e,this._scene){this._scene.addMorphTargetManager(this),this._uniqueId=this._scene.getUniqueId();const e=this._scene.getEngine().getCaps();this._canUseTextureForTargets=e.canUseGLVertexID&&e.textureFloat&&e.maxVertexTextureImageUnits>0&&e.texture2DArrayMaxLayerCount>1}}get numMaxInfluencers(){return me.ConstantTargetCountForTextureMode>0&&this.isUsingTextureForTargets?me.ConstantTargetCountForTextureMode:this._numMaxInfluencers}set numMaxInfluencers(e){this._numMaxInfluencers!==e&&(this._numMaxInfluencers=e,this._mustSynchronize=!0,this._syncActiveTargets())}get uniqueId(){return this._uniqueId}get vertexCount(){return this._vertexCount}get supportsPositions(){return this._supportsPositions&&this.enablePositionMorphing}get supportsNormals(){return this._supportsNormals&&this.enableNormalMorphing}get supportsTangents(){return this._supportsTangents&&this.enableTangentMorphing}get supportsUVs(){return this._supportsUVs&&this.enableUVMorphing}get supportsUV2s(){return this._supportsUV2s&&this.enableUV2Morphing}get supportsColors(){return this._supportsColors&&this.enableColorMorphing}get hasPositions(){return this._supportsPositions}get hasNormals(){return this._supportsNormals}get hasTangents(){return this._supportsTangents}get hasUVs(){return this._supportsUVs}get hasUV2s(){return this._supportsUV2s}get hasColors(){return this._supportsColors}get numTargets(){return this._targets.length}get numInfluencers(){return this._activeTargets.length}get influences(){return this._influences}get useTextureToStoreTargets(){return this._useTextureToStoreTargets}set useTextureToStoreTargets(e){this._useTextureToStoreTargets!==e&&(this._useTextureToStoreTargets=e,this._mustSynchronize=!0,this._syncActiveTargets())}get isUsingTextureForTargets(){return me.EnableTextureStorage&&this.useTextureToStoreTargets&&this._canUseTextureForTargets&&!this._scene?.getEngine().getCaps().disableMorphTargetTexture}getActiveTarget(e){return this._activeTargets.data[e]}getTarget(e){return this._targets[e]}getTargetByName(e){for(const t of this._targets)if(t.name===e)return t;return null}addTarget(e){this._targets.push(e),this._targetInfluenceChangedObservers.push(e.onInfluenceChanged.add((e=>{this.areUpdatesFrozen&&e&&(this._forceUpdateWhenUnfrozen=!0),this._syncActiveTargets(e)}))),this._targetDataLayoutChangedObservers.push(e._onDataLayoutChanged.add((()=>{this._mustSynchronize=!0,this._syncActiveTargets()}))),this._mustSynchronize=!0,this._syncActiveTargets()}removeTarget(e){const t=this._targets.indexOf(e);t>=0&&(this._targets.splice(t,1),e.onInfluenceChanged.remove(this._targetInfluenceChangedObservers.splice(t,1)[0]),e._onDataLayoutChanged.remove(this._targetDataLayoutChangedObservers.splice(t,1)[0]),this._mustSynchronize=!0,this._syncActiveTargets()),this._scene&&this._scene.stopAnimation(e)}_bind(e){e.setFloat3("morphTargetTextureInfo",this._textureVertexStride,this._textureWidth,this._textureHeight),e.setFloatArray("morphTargetTextureIndices",this._morphTargetTextureIndices),e.setTexture("morphTargets",this._targetStoreTexture),e.setInt("morphTargetCount",this.numInfluencers)}clone(){const e=new me(this._scene);for(const t of this._targets)e.addTarget(t.clone());return e.enablePositionMorphing=this.enablePositionMorphing,e.enableNormalMorphing=this.enableNormalMorphing,e.enableTangentMorphing=this.enableTangentMorphing,e.enableUVMorphing=this.enableUVMorphing,e.enableUV2Morphing=this.enableUV2Morphing,e.enableColorMorphing=this.enableColorMorphing,e}serialize(){const e={};e.id=this.uniqueId,e.targets=[];for(const t of this._targets)e.targets.push(t.serialize());return e}_syncActiveTargets(e=!1){if(this.areUpdatesFrozen)return;const t=!!this._targetStoreTexture,s=this.isUsingTextureForTargets;(this._mustSynchronize||t!==s)&&(this._mustSynchronize=!1,this.synchronize());let n=0;this._activeTargets.reset(),this._morphTargetTextureIndices&&this._morphTargetTextureIndices.length===this._targets.length||(this._morphTargetTextureIndices=new Float32Array(this._targets.length));let o=-1;for(const e of this._targets)if(o++,0!==e.influence||!this.optimizeInfluencers){if(this._activeTargets.length>=me.MaxActiveMorphTargetsInVertexAttributeMode&&!this.isUsingTextureForTargets)break;this._activeTargets.push(e),this._morphTargetTextureIndices[n]=o,this._tempInfluences[n++]=e.influence}this._morphTargetTextureIndices.length!==n&&(this._morphTargetTextureIndices=this._morphTargetTextureIndices.slice(0,n)),this._influences&&this._influences.length===n||(this._influences=new Float32Array(n));for(let e=0;e<n;e++)this._influences[e]=this._tempInfluences[e];if(e&&this._scene)for(const e of this._scene.meshes)e.morphTargetManager===this&&(s?e._markSubMeshesAsAttributesDirty():e._syncGeometryWithMorphTargetManager())}synchronize(){if(!this._scene||this.areUpdatesFrozen)return;const e=this._scene.getEngine();this._supportsPositions=!0,this._supportsNormals=!0,this._supportsTangents=!0,this._supportsUVs=!0,this._supportsUV2s=!0,this._supportsColors=!0,this._vertexCount=0,this._targetStoreTexture?.dispose(),this._targetStoreTexture=null,this.isUsingTextureForTargets&&this._targets.length>e.getCaps().texture2DArrayMaxLayerCount&&(this.useTextureToStoreTargets=!1);for(const e of this._targets){this._supportsPositions=this._supportsPositions&&e.hasPositions,this._supportsNormals=this._supportsNormals&&e.hasNormals,this._supportsTangents=this._supportsTangents&&e.hasTangents,this._supportsUVs=this._supportsUVs&&e.hasUVs,this._supportsUV2s=this._supportsUV2s&&e.hasUV2s,this._supportsColors=this._supportsColors&&e.hasColors;const t=e.vertexCount;if(0===this._vertexCount)this._vertexCount=t;else if(this._vertexCount!==t)return void w.Error(`Incompatible target. Targets must all have the same vertices count. Current vertex count: ${this._vertexCount}, vertex count for target "${e.name}": ${t}`)}if(this.isUsingTextureForTargets){this._textureVertexStride=0,this._supportsPositions&&this._textureVertexStride++,this._supportsNormals&&this._textureVertexStride++,this._supportsTangents&&this._textureVertexStride++,this._supportsUVs&&this._textureVertexStride++,this._supportsUV2s&&this._textureVertexStride++,this._supportsColors&&this._textureVertexStride++,this._textureWidth=this._vertexCount*this._textureVertexStride||1,this._textureHeight=1;const t=e.getCaps().maxTextureSize;this._textureWidth>t&&(this._textureHeight=Math.ceil(this._textureWidth/t),this._textureWidth=t);const s=this._targets.length,n=new Float32Array(s*this._textureWidth*this._textureHeight*4);let o=0;for(let e=0;e<s;e++){const t=this._targets[e],s=t.getPositions(),i=t.getNormals(),r=t.getUVs(),a=t.getTangents(),l=t.getUV2s(),h=t.getColors();o=e*this._textureWidth*this._textureHeight*4;for(let e=0;e<this._vertexCount;e++)this._supportsPositions&&s&&(n[o]=s[3*e],n[o+1]=s[3*e+1],n[o+2]=s[3*e+2],o+=4),this._supportsNormals&&i&&(n[o]=i[3*e],n[o+1]=i[3*e+1],n[o+2]=i[3*e+2],o+=4),this._supportsUVs&&r&&(n[o]=r[2*e],n[o+1]=r[2*e+1],o+=4),this._supportsTangents&&a&&(n[o]=a[3*e],n[o+1]=a[3*e+1],n[o+2]=a[3*e+2],o+=4),this._supportsUV2s&&l&&(n[o]=l[2*e],n[o+1]=l[2*e+1],o+=4),this._supportsColors&&h&&(n[o]=h[4*e],n[o+1]=h[4*e+1],n[o+2]=h[4*e+2],n[o+3]=h[4*e+3],o+=4)}this._targetStoreTexture=pe.CreateRGBATexture(n,this._textureWidth,this._textureHeight,s,this._scene,!1,!1,A.TEXTURE_NEAREST_SAMPLINGMODE,A.TEXTURETYPE_FLOAT),this._targetStoreTexture.name=`Morph texture_${this.uniqueId}`}for(const e of this._scene.meshes)e.morphTargetManager===this&&e._syncGeometryWithMorphTargetManager()}dispose(){if(this._targetStoreTexture&&this._targetStoreTexture.dispose(),this._targetStoreTexture=null,this._scene){if(this._scene.removeMorphTargetManager(this),this._parentContainer){const e=this._parentContainer.morphTargetManagers.indexOf(this);e>-1&&this._parentContainer.morphTargetManagers.splice(e,1),this._parentContainer=null}for(const e of this._targets)this._scene.stopAnimation(e)}}static Parse(e,t){const s=new me(t);for(const n of e.targets)s.addTarget(_e.Parse(n,t));return s}}me.EnableTextureStorage=!0,me.MaxActiveMorphTargetsInVertexAttributeMode=8,me.ConstantTargetCountForTextureMode=0;class ye{constructor(e){this.byteOffset=0,this.buffer=e}async loadAsync(e){const t=await this.buffer.readAsync(this.byteOffset,e);this._dataView=new DataView(t.buffer,t.byteOffset,t.byteLength),this._dataByteOffset=0}readUint32(){const e=this._dataView.getUint32(this._dataByteOffset,!0);return this._dataByteOffset+=4,this.byteOffset+=4,e}readUint8Array(e){const t=new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+this._dataByteOffset,e);return this._dataByteOffset+=e,this.byteOffset+=e,t}readString(e){return C(this.readUint8Array(e))}skipBytes(e){this._dataByteOffset+=e,this.byteOffset+=e}}function fe(e,t,s,n){const o={externalResourceFunction:n};return s&&(o.uri="file:"===t?s:t+s),ArrayBuffer.isView(e)?GLTFValidator.validateBytes(e,o):GLTFValidator.validateString(e,o)}function ge(){const e=[];onmessage=t=>{const s=t.data;switch(s.id){case"init":importScripts(s.url);break;case"validate":fe(s.data,s.rootUrl,s.fileName,(t=>new Promise(((s,n)=>{const o=e.length;e.push({resolve:s,reject:n}),postMessage({id:"getExternalResource",index:o,uri:t})})))).then((e=>{postMessage({id:"validate.resolve",value:e})}),(e=>{postMessage({id:"validate.reject",reason:e})}));break;case"getExternalResource.resolve":e[s.index].resolve(s.value);break;case"getExternalResource.reject":e[s.index].reject(s.reason)}}}class be{static ValidateAsync(t,s,n,o){return"function"==typeof Worker?new Promise(((i,r)=>{const a=`${fe}(${ge})()`,l=URL.createObjectURL(new Blob([a],{type:"application/javascript"})),h=new Worker(l),c=e=>{h.removeEventListener("error",c),h.removeEventListener("message",d),r(e)},d=e=>{const t=e.data;switch(t.id){case"getExternalResource":o(t.uri).then((e=>{h.postMessage({id:"getExternalResource.resolve",index:t.index,value:e},[e.buffer])}),(e=>{h.postMessage({id:"getExternalResource.reject",index:t.index,reason:e})}));break;case"validate.resolve":h.removeEventListener("error",c),h.removeEventListener("message",d),i(t.value),h.terminate();break;case"validate.reject":h.removeEventListener("error",c),h.removeEventListener("message",d),r(t.reason),h.terminate()}};if(h.addEventListener("error",c),h.addEventListener("message",d),h.postMessage({id:"init",url:e.GetBabylonScriptURL(this.Configuration.url)}),ArrayBuffer.isView(t)){const e=t.slice();h.postMessage({id:"validate",data:e,rootUrl:s,fileName:n},[e.buffer])}else h.postMessage({id:"validate",data:t,rootUrl:s,fileName:n})})):(this._LoadScriptPromise||(this._LoadScriptPromise=e.LoadBabylonScriptAsync(this.Configuration.url)),this._LoadScriptPromise.then((()=>fe(t,s,n,o))))}}function ve(e,t,s){try{return Promise.resolve(new Uint8Array(e,t,s))}catch(e){return Promise.reject(e)}}be.Configuration={url:`${e._DefaultCdnUrl}/gltf_validator.js`},function(e){e[e.AUTO=0]="AUTO",e[e.FORCE_RIGHT_HANDED=1]="FORCE_RIGHT_HANDED"}(re||(re={})),function(e){e[e.NONE=0]="NONE",e[e.FIRST=1]="FIRST",e[e.ALL=2]="ALL"}(ae||(ae={})),function(e){e[e.LOADING=0]="LOADING",e[e.READY=1]="READY",e[e.COMPLETE=2]="COMPLETE"}(le||(le={}));class Ae{constructor(){this.coordinateSystemMode=re.AUTO,this.animationStartMode=ae.FIRST,this.loadNodeAnimations=!0,this.loadSkins=!0,this.loadMorphTargets=!0,this.compileMaterials=!1,this.useClipPlane=!1,this.compileShadowGenerators=!1,this.transparencyAsCoverage=!1,this.useRangeRequests=!1,this.createInstances=!0,this.alwaysComputeBoundingBox=!1,this.loadAllMaterials=!1,this.loadOnlyMaterials=!1,this.skipMaterials=!1,this.useSRGBBuffers=!0,this.targetFps=60,this.alwaysComputeSkeletonRootNode=!1,this.useGltfTextureNames=!1,this.preprocessUrlAsync=e=>Promise.resolve(e),this.extensionOptions={}}copyFrom(e){e&&(this.onParsed=e.onParsed,this.coordinateSystemMode=e.coordinateSystemMode??this.coordinateSystemMode,this.animationStartMode=e.animationStartMode??this.animationStartMode,this.loadNodeAnimations=e.loadNodeAnimations??this.loadNodeAnimations,this.loadSkins=e.loadSkins??this.loadSkins,this.loadMorphTargets=e.loadMorphTargets??this.loadMorphTargets,this.compileMaterials=e.compileMaterials??this.compileMaterials,this.useClipPlane=e.useClipPlane??this.useClipPlane,this.compileShadowGenerators=e.compileShadowGenerators??this.compileShadowGenerators,this.transparencyAsCoverage=e.transparencyAsCoverage??this.transparencyAsCoverage,this.useRangeRequests=e.useRangeRequests??this.useRangeRequests,this.createInstances=e.createInstances??this.createInstances,this.alwaysComputeBoundingBox=e.alwaysComputeBoundingBox??this.alwaysComputeBoundingBox,this.loadAllMaterials=e.loadAllMaterials??this.loadAllMaterials,this.loadOnlyMaterials=e.loadOnlyMaterials??this.loadOnlyMaterials,this.skipMaterials=e.skipMaterials??this.skipMaterials,this.useSRGBBuffers=e.useSRGBBuffers??this.useSRGBBuffers,this.targetFps=e.targetFps??this.targetFps,this.alwaysComputeSkeletonRootNode=e.alwaysComputeSkeletonRootNode??this.alwaysComputeSkeletonRootNode,this.useGltfTextureNames=e.useGltfTextureNames??this.useGltfTextureNames,this.preprocessUrlAsync=e.preprocessUrlAsync??this.preprocessUrlAsync,this.customRootNode=e.customRootNode,this.onMeshLoaded=e.onMeshLoaded,this.onSkinLoaded=e.onSkinLoaded,this.onTextureLoaded=e.onTextureLoaded,this.onMaterialLoaded=e.onMaterialLoaded,this.onCameraLoaded=e.onCameraLoaded,this.extensionOptions=e.extensionOptions??this.extensionOptions)}}class xe extends Ae{constructor(e){super(),this.onParsedObservable=new r,this.onMeshLoadedObservable=new r,this.onSkinLoadedObservable=new r,this.onTextureLoadedObservable=new r,this.onMaterialLoadedObservable=new r,this.onCameraLoadedObservable=new r,this.onCompleteObservable=new r,this.onErrorObservable=new r,this.onDisposeObservable=new r,this.onExtensionLoadedObservable=new r,this.validate=!1,this.onValidatedObservable=new r,this._loader=null,this._state=null,this._requests=new Array,this.name=M.name,this.extensions=M.extensions,this.onLoaderStateChangedObservable=new r,this._logIndentLevel=0,this._loggingEnabled=!1,this._log=this._logDisabled,this._capturePerformanceCounters=!1,this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled,this.copyFrom(e)}set onParsed(e){this._onParsedObserver&&this.onParsedObservable.remove(this._onParsedObserver),e&&(this._onParsedObserver=this.onParsedObservable.add(e))}set onMeshLoaded(e){this._onMeshLoadedObserver&&this.onMeshLoadedObservable.remove(this._onMeshLoadedObserver),e&&(this._onMeshLoadedObserver=this.onMeshLoadedObservable.add(e))}set onSkinLoaded(e){this._onSkinLoadedObserver&&this.onSkinLoadedObservable.remove(this._onSkinLoadedObserver),e&&(this._onSkinLoadedObserver=this.onSkinLoadedObservable.add((t=>e(t.node,t.skinnedNode))))}set onTextureLoaded(e){this._onTextureLoadedObserver&&this.onTextureLoadedObservable.remove(this._onTextureLoadedObserver),e&&(this._onTextureLoadedObserver=this.onTextureLoadedObservable.add(e))}set onMaterialLoaded(e){this._onMaterialLoadedObserver&&this.onMaterialLoadedObservable.remove(this._onMaterialLoadedObserver),e&&(this._onMaterialLoadedObserver=this.onMaterialLoadedObservable.add(e))}set onCameraLoaded(e){this._onCameraLoadedObserver&&this.onCameraLoadedObservable.remove(this._onCameraLoadedObserver),e&&(this._onCameraLoadedObserver=this.onCameraLoadedObservable.add(e))}set onComplete(e){this._onCompleteObserver&&this.onCompleteObservable.remove(this._onCompleteObserver),this._onCompleteObserver=this.onCompleteObservable.add(e)}set onError(e){this._onErrorObserver&&this.onErrorObservable.remove(this._onErrorObserver),this._onErrorObserver=this.onErrorObservable.add(e)}set onDispose(e){this._onDisposeObserver&&this.onDisposeObservable.remove(this._onDisposeObserver),this._onDisposeObserver=this.onDisposeObservable.add(e)}set onExtensionLoaded(e){this._onExtensionLoadedObserver&&this.onExtensionLoadedObservable.remove(this._onExtensionLoadedObserver),this._onExtensionLoadedObserver=this.onExtensionLoadedObservable.add(e)}get loggingEnabled(){return this._loggingEnabled}set loggingEnabled(e){this._loggingEnabled!==e&&(this._loggingEnabled=e,this._loggingEnabled?this._log=this._logEnabled:this._log=this._logDisabled)}get capturePerformanceCounters(){return this._capturePerformanceCounters}set capturePerformanceCounters(e){this._capturePerformanceCounters!==e&&(this._capturePerformanceCounters=e,this._capturePerformanceCounters?(this._startPerformanceCounter=this._startPerformanceCounterEnabled,this._endPerformanceCounter=this._endPerformanceCounterEnabled):(this._startPerformanceCounter=this._startPerformanceCounterDisabled,this._endPerformanceCounter=this._endPerformanceCounterDisabled))}set onValidated(e){this._onValidatedObserver&&this.onValidatedObservable.remove(this._onValidatedObserver),this._onValidatedObserver=this.onValidatedObservable.add(e)}dispose(){this._loader&&(this._loader.dispose(),this._loader=null);for(const e of this._requests)e.abort();this._requests.length=0,delete this._progressCallback,this.preprocessUrlAsync=e=>Promise.resolve(e),this.onMeshLoadedObservable.clear(),this.onSkinLoadedObservable.clear(),this.onTextureLoadedObservable.clear(),this.onMaterialLoadedObservable.clear(),this.onCameraLoadedObservable.clear(),this.onCompleteObservable.clear(),this.onExtensionLoadedObservable.clear(),this.onDisposeObservable.notifyObservers(void 0),this.onDisposeObservable.clear()}loadFile(t,s,n,o,i,a,l,h){if(ArrayBuffer.isView(s))return this._loadBinary(t,s,n,o,l,h),null;this._progressCallback=i;const c=s.name||e.GetFilename(s);if(a){if(this.useRangeRequests){this.validate&&w.Warn("glTF validation is not supported when range requests are enabled");const e={abort:()=>{},onCompleteObservable:new r},n={readAsync:(e,n)=>new Promise(((o,i)=>{this._loadFile(t,s,(e=>{o(new Uint8Array(e))}),!0,(e=>{i(e)}),(t=>{t.setRequestHeader("Range",`bytes=${e}-${e+n-1}`)}))})),byteLength:0};return this._unpackBinaryAsync(new ye(n)).then((t=>{e.onCompleteObservable.notifyObservers(e),o(t)}),l?e=>l(void 0,e):void 0),e}return this._loadFile(t,s,(e=>{this._validate(t,new Uint8Array(e,0,e.byteLength),n,c),this._unpackBinaryAsync(new ye({readAsync:(t,s)=>ve(e,t,s),byteLength:e.byteLength})).then((e=>{o(e)}),l?e=>l(void 0,e):void 0)}),!0,l)}return this._loadFile(t,s,(e=>{try{this._validate(t,e,n,c),o({json:this._parseJson(e)})}catch{l&&l()}}),!1,l)}_loadBinary(e,t,s,n,o,i){this._validate(e,new Uint8Array(t.buffer,t.byteOffset,t.byteLength),s,i),this._unpackBinaryAsync(new ye({readAsync:(e,s)=>function(e,t,s){try{if(t<0||t>=e.byteLength)throw new RangeError("Offset is out of range.");if(t+s>e.byteLength)throw new RangeError("Length is out of range.");return Promise.resolve(new Uint8Array(e.buffer,e.byteOffset+t,s))}catch(e){return Promise.reject(e)}}(t,e,s),byteLength:t.byteLength})).then((e=>{n(e)}),o?e=>o(void 0,e):void 0)}importMeshAsync(e,t,s,n,o,i){return Promise.resolve().then((()=>(this.onParsedObservable.notifyObservers(s),this.onParsedObservable.clear(),this._log(`Loading ${i||""}`),this._loader=this._getLoader(s),this._loader.importMeshAsync(e,t,null,s,n,o,i))))}loadAsync(e,t,s,n,o){return Promise.resolve().then((()=>(this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),this._log(`Loading ${o||""}`),this._loader=this._getLoader(t),this._loader.loadAsync(e,t,s,n,o))))}loadAssetContainerAsync(e,t,s,n,o){return Promise.resolve().then((()=>{this.onParsedObservable.notifyObservers(t),this.onParsedObservable.clear(),this._log(`Loading ${o||""}`),this._loader=this._getLoader(t);const i=new ee(e),r=[];this.onMaterialLoadedObservable.add((e=>{r.push(e)}));const a=[];this.onTextureLoadedObservable.add((e=>{a.push(e)}));const l=[];this.onCameraLoadedObservable.add((e=>{l.push(e)}));const h=[];return this.onMeshLoadedObservable.add((e=>{e.morphTargetManager&&h.push(e.morphTargetManager)})),this._loader.importMeshAsync(null,e,i,t,s,n,o).then((e=>(Array.prototype.push.apply(i.geometries,e.geometries),Array.prototype.push.apply(i.meshes,e.meshes),Array.prototype.push.apply(i.particleSystems,e.particleSystems),Array.prototype.push.apply(i.skeletons,e.skeletons),Array.prototype.push.apply(i.animationGroups,e.animationGroups),Array.prototype.push.apply(i.materials,r),Array.prototype.push.apply(i.textures,a),Array.prototype.push.apply(i.lights,e.lights),Array.prototype.push.apply(i.transformNodes,e.transformNodes),Array.prototype.push.apply(i.cameras,l),Array.prototype.push.apply(i.morphTargetManagers,h),i)))}))}canDirectLoad(e){return M.canDirectLoad(e)}directLoad(e,t){if(t.startsWith("base64,"+T)||t.startsWith(";base64,"+T)||t.startsWith("application/octet-stream;base64,"+T)||t.startsWith("model/gltf-binary;base64,"+T)){const s=O(t);return this._validate(e,new Uint8Array(s,0,s.byteLength)),this._unpackBinaryAsync(new ye({readAsync:(e,t)=>ve(s,e,t),byteLength:s.byteLength}))}return this._validate(e,t),Promise.resolve({json:this._parseJson(t)})}createPlugin(e){return new xe(e[M.name])}get loaderState(){return this._state}whenCompleteAsync(){return new Promise(((e,t)=>{this.onCompleteObservable.addOnce((()=>{e()})),this.onErrorObservable.addOnce((e=>{t(e)}))}))}_setState(e){this._state!==e&&(this._state=e,this.onLoaderStateChangedObservable.notifyObservers(this._state),this._log(le[this._state]))}_loadFile(e,t,s,n,o,i){const r=e._loadFile(t,s,(e=>{this._onProgress(e,r)}),!0,n,o,i);return r.onCompleteObservable.add((()=>{r._lengthComputable=!0,r._total=r._loaded})),this._requests.push(r),r}_onProgress(e,t){if(!this._progressCallback)return;t._lengthComputable=e.lengthComputable,t._loaded=e.loaded,t._total=e.total;let s=!0,n=0,o=0;for(const e of this._requests){if(void 0===e._lengthComputable||void 0===e._loaded||void 0===e._total)return;s=s&&e._lengthComputable,n+=e._loaded,o+=e._total}this._progressCallback({lengthComputable:s,loaded:n,total:s?o:0})}_validate(t,s,n="",o=""){this.validate&&(this._startPerformanceCounter("Validate JSON"),be.ValidateAsync(s,n,o,(e=>this.preprocessUrlAsync(n+e).then((e=>t._loadFileAsync(e,void 0,!0,!0).then((e=>new Uint8Array(e,0,e.byteLength))))))).then((e=>{this._endPerformanceCounter("Validate JSON"),this.onValidatedObservable.notifyObservers(e),this.onValidatedObservable.clear()}),(t=>{this._endPerformanceCounter("Validate JSON"),e.Warn(`Failed to validate: ${t.message}`),this.onValidatedObservable.clear()})))}_getLoader(e){const t=e.json.asset||{};this._log(`Asset version: ${t.version}`),t.minVersion&&this._log(`Asset minimum version: ${t.minVersion}`),t.generator&&this._log(`Asset generator: ${t.generator}`);const s=xe._parseVersion(t.version);if(!s)throw new Error("Invalid version: "+t.version);if(void 0!==t.minVersion){const e=xe._parseVersion(t.minVersion);if(!e)throw new Error("Invalid minimum version: "+t.minVersion);if(xe._compareVersion(e,{major:2,minor:0})>0)throw new Error("I