@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.
3 lines • 98 kB
JavaScript
import{b as e,bu as t,V as s,u as n,v as o,bv as i,O as r,bw as a,bx as l,M as h,by as c,bz as d,a4 as u,aC as _,bh as p,R as m,G as f,X as y,bg as g,m as b,T as v,C as A,a_ as x,L as w,bA as C,bB as M,bC as T,bD as O,bE as E,bF as S,aA as R,bG as P,bH as k,t as L,bI as I,g as N,aj as D,bo as $,bJ as U,aD as V,Q as F,aK as B,af as G,bK as W,aB as X,bL as Y,bM as Z,bN as z,bO as K,bP as j,aO as q,bQ as H}from"./index-yNtOWHHe.esm.min.js";import{B as J}from"./bone-WlJTsCYz.esm.min.js";import{S as Q}from"./skeleton-DrI_Z0uE.esm.min.js";import{A as ee}from"./assetContainer-Dkk4zkgP.esm.min.js";import{G as te}from"./objectModelMapping-DJGnHmCN.esm.min.js";import"./rawTexture-BOCcQuA1.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)*e;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();this.camera.cameraRotation.y+=e.movementX*n/this.angularSensibility,this.camera.cameraRotation.x+=e.movementY*n/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=this._offsetX*t/this.touchAngularSensibility;if(this.singleFingerRotate&&1===this._pointerPressed.length||!this.singleFingerRotate&&this._pointerPressed.length>1)e.cameraRotation.x=-this._offsetY*t/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||f.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=y.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())),y.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,this.metadata=null,e||(e=f.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.setFloat("morphTargetCount",this.numInfluencers)}clone(){const e=new me(this._scene);e.areUpdatesFrozen=!0;for(const t of this._targets)e.addTarget(t.clone());return e.areUpdatesFrozen=!1,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.metadata=this.metadata,e}serialize(){const e={};e.id=this.uniqueId,e.targets=[];for(const t of this._targets)e.targets.push(t.serialize());return this.metadata&&(e.metadata=this.metadata),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.metadata=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 e.metadata&&(s.metadata=e.metadata),s}}me.EnableTextureStorage=!0,me.MaxActiveMorphTargetsInVertexAttributeMode=8,me.ConstantTargetCountForTextureMode=0;class fe{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 ye(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":ye(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=`${ye}(${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((()=>ye(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.alwaysComputeBoundingBox=!1,this.alwaysComputeSkeletonRootNode=!1,this.animationStartMode=ae.FIRST,this.compileMaterials=!1,this.compileShadowGenerators=!1,this.coordinateSystemMode=re.AUTO,this.createInstances=!0,this.extensionOptions={},this.loadAllMaterials=!1,this.loadMorphTargets=!0,this.loadNodeAnimations=!0,this.loadOnlyMaterials=!1,this.loadSkins=!0,this.preprocessUrlAsync=e=>Promise.resolve(e),this.skipMaterials=!1,this.targetFps=60,this.transparencyAsCoverage=!1,this.useClipPlane=!1,this.useGltfTextureNames=!1,this.useRangeRequests=!1,this.useSRGBBuffers=!0,this.validate=!1}copyFrom(e){e&&(this.alwaysComputeBoundingBox=e.alwaysComputeBoundingBox??this.alwaysComputeBoundingBox,this.alwaysComputeSkeletonRootNode=e.alwaysComputeSkeletonRootNode??this.alwaysComputeSkeletonRootNode,this.animationStartMode=e.animationStartMode??this.animationStartMode,this.capturePerformanceCounters=e.capturePerformanceCounters??this.capturePerformanceCounters,this.compileMaterials=e.compileMaterials??this.compileMaterials,this.compileShadowGenerators=e.compileShadowGenerators??this.compileShadowGenerators,this.coordinateSystemMode=e.coordinateSystemMode??this.coordinateSystemMode,this.createInstances=e.createInstances??this.createInstances,this.customRootNode=e.customRootNode,this.extensionOptions=e.extensionOptions??this.extensionOptions,this.loadAllMaterials=e.loadAllMaterials??this.loadAllMaterials,this.loadMorphTargets=e.loadMorphTargets??this.loadMorphTargets,this.loadNodeAnimations=e.loadNodeAnimations??this.loadNodeAnimations,this.loadOnlyMaterials=e.loadOnlyMaterials??this.loadOnlyMaterials,this.loadSkins=e.loadSkins??this.loadSkins,this.loggingEnabled=e.loggingEnabled??this.loggingEnabled,this.onCameraLoaded=e.onCameraLoaded,this.onMaterialLoaded=e.onMaterialLoaded,this.onMeshLoaded=e.onMeshLoaded,this.onParsed=e.onParsed,this.onSkinLoaded=e.onSkinLoaded,this.onTextureLoaded=e.onTextureLoaded,this.onValidated=e.onValidated,this.preprocessUrlAsync=e.preprocessUrlAsync??this.preprocessUrlAsync,this.skipMaterials=e.skipMaterials??this.skipMaterials,this.targetFps=e.targetFps??this.targetFps,this.transparencyAsCoverage=e.transparencyAsCoverage??this.transparencyAsCoverage,this.useClipPlane=e.useClipPlane??this.useClipPlane,this.useGltfTextureNames=e.useGltfTextureNames??this.useGltfTextureNames,this.useRangeRequests=e.useRangeRequests??this.useRangeRequests,this.useSRGBBuffers=e.useSRGBBuffers??this.useSRGBBuffers,this.validate=e.validate??this.validate)}}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.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 fe(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 fe({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 fe({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 fe({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("Incompatible minimum version: "+t.minVersion)}const n={1:xe._CreateGLTF1Loader,2:xe._CreateGLTF2Loader}[s.major];if(!n)throw new Error("Unsupported version: "+t.version);return n(this)}_parseJson(e){this._startPerformanceCounter("Parse JSON"),this._log(`JSON length: ${e.length}`);const t=JSON.parse(e);return this._endPerformanceCounter("Parse JSON"),t}_unpackBinaryAsync(e){return this._startPerformanceCounter("Unpack Binary"),e.loadAsync(20).then((()=>{const t=e.readUint32();if(1179937895!==t)throw new E("Unexpected magic: "+t,S.GLTFLoaderUnexpectedMagicError);const s=e.readUint32();this.loggingEnabled&&this._log(`Binary version: ${s}`);const n=e.readUint32();let o;switch(this.useRangeRequests||n===e.buffer.byteLength||w.Warn(`Length in header does not match actual data length: ${n} != ${e.buffer.byteLength}`),s){case 1:o=this._unpackBinaryV1Async(e,n);break;case 2:o=this._unpackBinaryV2Async(e,n);break;default:throw new Error("Unsupported version: "+s)}return this._endPerformanceCounter("Unpack Binary"),o}))}_unpackBinaryV1Async(e,t){const s=e.readUint32(),n=e.readUint32();if(0!==n)throw new Error(`Unexpected content format: ${n}`);const o=t-e.byteOffset,i={json:this._parseJson(e.readString(s)),bin:null};if(0!==o){const t=e.byteOffset;i.bin={readAsync:(s,n)=>e.buffer.readAsync(t+s,n),byteLength:o}}return Promise.resolve(i)}_unpackBinaryV2Async(e,t){const s=1313821514,n=5130562,o=e.readUint32();if(e.readUint32()!==s)throw new Error("First chunk format is not JSON");return e.byteOffset+o===t?e.loadAsync(o).then((()=>({json:this._parseJson(e.readString(o)),bin:null}))):e.loadAsync(o+8).then((()=>{const i={json:this._parseJson(e.readString(o)),bin:null},r=()=>{const o=e.readUint32();switch(e.readUint32()){case s:throw new Error("Unexpected JSON chunk");case n:{const t=e.byteOffset;i.bin={readAsync:(s,n)=>e.buffer.readAsync(t+s,n),byteLength:o},e.skipBytes(o);break}default:e.skipBytes(o)}return e.byteOffset!==t?e.loadAsync(8).then(r):Promise.resolve(i)};return r()}))}static _parseVersion(e){if("1.0"===e||"1.0.1"===e)return{major:1,minor:0};const t=(e+"").match(/^(\d+)\.(\d+)/);return t?{major:parseInt(t[1]),minor:parseInt(t[2])}:null}static _compareVersion(e,t){return e.major>t.major?1:e.major<t.major?-1:e.minor>t.minor?1:e.minor<t.minor?-1:0}_logOpen(e){this._log(e),this._logIndentLevel++}_logClose(){--this._logIndentLevel}_logEnabled(e){const t=xe._logSpaces.substring(0,2*this._logIndentLevel);w.Log(`${t}${e}`)}_logDisabled(e){}_startPerformanceCounterEnabled(t){e.StartPerformanceCounter(t)}_startPerformanceCounterDisabled(e){}_endPerformanceCounterEnabled(t){e.EndPerformanceCounter(t)}_endPerformanceCounterDisabled(e){}}xe.IncrementalLoading=!0,xe.HomogeneousCoordinates=!1,xe._logSpaces=" ",R(new xe);class we{constructor(e){this._factory=e}get value(){return this._factory&&(this._value=this._factory(),this._factory=void 0),this._value}}const Ce=new we((()=>import("./animationGroup-CEOzLVCR.esm.min.js"))),Me=new we((()=>import("./glTFLoaderAnimation-vLdcgcMX.esm.min.js")));class Te{static Get(e,t,s){if(!t||null==s||!t[s])throw new Error(`${e}: Failed to find index (${s})`);return t[s]}static TryGet(e,t){return e&&null!=t&&e[t]?e[t]:null}static Assign(e){if(e)for(let t=0;t<e.length;t++)e[t].index=t}}function Oe(e){if(e.min&&e.max){const t=e.min,s=e.max,n=q.Vector3[0].copyFromFloats(t[0],t[1],t[2]),o=q.Vector3[1].copyFromFloats(s[0],s[1],s[2]);if(e.normalized&&5126!==e.componentType){let t=1;switch(e.componentType){case 5120:t=127;break;case 5121:t=255;break;case 5122:t=32767;break;case 5123:t=65535}const s=1/t;n.scaleInPlace(s),o.scaleInPlace(s)}return new H(n,o)}return null}class Ee{static RegisterExtension(e,t){P(e,!1,t)}static UnregisterExtension(e){return k(e)}get gltf(){if(!this._gltf)throw new Error("glTF JSON is not available");return this._gltf}get bin(){return this._bin}get parent(){return this._parent}get babylonScene(){if(!this._babylonScene)throw new Error("Scene is not available");return this._babylonScene}get rootBabylonMesh(){return this._rootBabylonMesh}get rootUrl(){return this._rootUrl}constructor(e){this._completePromises=new Array,this._assetContainer=null,this._babylonLights=[],this._disableInstancedMesh=0,this._allMaterialsDirtyRequired=!1,this._skipStartAnimationStep=!1,this._extensions=new Array,this._disposed=!1,this._rootUrl=null,this._fileName=null,this._uniqueRootUrl=null,this._bin=null,this._rootBabylonMesh=null,this._defaultBabylonMaterialData={},this._postSceneLoadActions=new Array,this._parent=e}dispose(){this._disposed||(this._disposed=!0,this._completePromises.length=0,this._extensions.forEach((e=>e.dispose&&e.dispose())),this._extensions.length=0,this._gltf=null,this._bin=null,this._babylonScene=null,this._rootBabylonMesh=null,this._defaultBabylonMaterialData={},this._postSceneLoadActions.length=0,this._parent.dispose())}async importMeshAsync(e,t,s,n,o,i,r=""){return await Promise.resolve().then((async()=>{this._babylonScene=t,this._assetContainer=s,this._loadData(n);let i=null;if(e){const t={};if(this._gltf.nodes)for(const e of this._gltf.nodes)e.name&&(t[e.name]=e.index);i=(e instanceof Array?e:[e]).map((e=>{const s=t[e];if(void 0===s)throw new Error(`Failed to find node '${e}'`);return s}))}return await this._loadAsync(o,r,i,(()=>({meshes:this._getMeshes(),particleSystems:[],skeletons:this._getSkeletons(),animationGroups:this._getAnimationGroups(),lights:this._babylonLights,transformNodes:this._getTransformNodes(),geometries:this._getGeometries(),spriteManagers:[]})))}))}async loadAsync(e,t,s,n,o=""){return this._babylonScene=e,this._loadData(t),await this._loadAsync(s,o,null,(()=>{}))}async _loadAsync(t,s,n,o){return await Promise.resolve().then((async()=>{this._rootUrl=t,this._uniqueRootUrl=!t.startsWith("file:")&&s?t:`${t}${Date.now()}/`,this._fileName=s,this._allMaterialsDirtyRequired=!1,await this._loadExtensionsAsync();const i=`${le[le.LOADING]} => ${le[le.READY]}`,r=`${le[le.LOADING]} => ${le[le.COMPLETE]}`;this._parent._startPerformanceCounter(i),this._parent._startPerformanceCounter(r),this._parent._setState(le.LOADING),this._extensionsOnLoading();const a=new Array,l=this._babylonScene.blockMaterialDirtyMechanism;if(this._babylonScene.blockMaterialDirtyMechanism=!0,!this.parent.loadOnlyMaterials)if(n)a.push(this.loadSceneAsync("/nodes",{nodes:n,index:-1}));else if(null!=this._gltf.scene||this._gltf.scenes&&this._gltf.scenes[0]){const e=Te.Get("/scene",this._gltf.scenes,this._gltf.scene||0);a.push(this.loadSceneAsync(`/scenes/${e.index}`,e))}if(!this.parent.skipMaterials&&this.parent.loadAllMaterials&&this._gltf.materials)for(let e=0;e<this._gltf.materials.length;++e){const t=this._gltf.materials[e],s="/materials/"+e,n=L.TriangleFillMode;a.push(this._loadMaterialAsync(s,t,null,n,(()=>{})))}this._allMaterialsDirtyRequired?this._babylonScene.blockMaterialDirtyMechanism=l:this._babylonScene._forceBlockMaterialDirtyMechanism(l),this._parent.compileMaterials&&a.push(this._compileMaterialsAsync()),this._parent.compileShadowGenerators&&a.push(this._compileShadowGeneratorsAsync());const h=Promise.all(a).then((()=>{this._rootBabylonMesh&&this._rootBabylonMesh!==this._parent.customRootNode&&this._rootBabylonMesh.setEnabled(!0);for(const e of this._babylonScene.materials){const t=e;void 0!==t.maxSimultaneousLights&&(t.maxSimultaneousLights=Math.max(t.maxSimultaneousLights,this._babylonScene.lights.length))}return this._extensionsOnReady(),this._parent._setState(le.READY),this._skipStartAnimationStep||this._startAnimations(),o()}));return await h.then((t=>(this._parent._endPerformanceCounter(i),e.SetImmediate((()=>{this._disposed||Promise.all(this._completePromises).then((()=>{this._parent._endPerformanceCounter(r),this._parent._setState(le.COMPLETE),this._parent.onCompleteObservable.notifyObservers(void 0),this._parent.onCompleteObservable.clear(),this.dispose()}),(e=>{this._parent.onErrorObservable.notifyObservers(e),this._parent.onErrorObservable.clear(),this.dispose()}))})),t)))})).catch((e=>{throw this._disposed||(this._parent.onErrorObservable.notifyObservers(e),this._parent.onErrorObservable.clear(),this.dispose()),e}))}_loadData(e){if(this._gltf=e.json,this._setupData(),e.bin){const t=this._gltf.buffers;if(t&&t[0]&&!t[0].uri){const s=t[0];(s.byteLength<e.bin.byteLength-3||s.byteLength>e.bin.byteLength)&&w.Warn(`Binary buffer length (${s.byteLength}) from JSON does not match chunk length (${e.bin.byteLength})`),this._bin=e.bin}else w.Warn("Unexpected BIN chunk")}}_setupData(){if(Te.Assign(this._gltf.accessors),Te.Assign(this._gltf.animations),Te.Assign(this._gltf.buffers),Te.Assign(this._gltf.bufferViews),Te.Assign(this._gltf.cameras),Te.Assign(this._gltf.images),Te.Assign(this._gltf.materials),Te.Assign(this._gltf.meshes),Te.Assign(this._gltf.nodes),Te.Assign(this._gltf.samplers),Te.Assign(this._gltf.scenes),Te.Assign(this._gltf.skins),Te.Assign(this._gltf.textures),this._gltf.nodes){const e={};for(const t of this._gltf.nodes)if(t.children)for(const s of t.children)e[s]=t.index;const t=this._createRootNode();for(const s of this._gltf.nodes){const n=e[s.index];s.parent=void 0===n?t:this._gltf.nodes[n]}}}async _loadExtensionsAsync(){const e=[];if(I.forEach(((t,s)=>{!1===this.parent.extensionOptions[s]?.enabled?t.isGLTFExtension&&this.isExtensionUsed(s)&&w.Warn(`Extension ${s} is used but has been explicitly disabled.`):t.isGLTFExtension&&!this.isExtensionUsed(s)||e.push((async()=>{const e=await t.factory(this);return e.name!==s&&w.Warn(`The name of the glTF loader extension instance does not match the registered name: ${e.name} !== ${s}`),this._parent.onExtensionLoadedObservable.notifyObservers(e),e})())})),this._extensions.push(...await Promise.all(e)),this._extensions.sort(((e,t)=>(e.order||Number.MAX_VALUE)-(t.order||Number.MAX_VALUE))),this._parent.onExtensionLoadedObservable.clear(),this._gltf.extensionsRequired)for(const e of this._gltf.extensionsRequired){if(!this._extensions.some((t=>t.name===e&&t.enabled))){if(!1===this.parent.extensionOptions[e]?.enabled)throw new Error(`Required extension ${e} is disabled`);throw new Error(`Required extension ${e} is not available`)}}}_createRootNode(){if(void 0!==this._parent.customRootNode)return this._rootBabylonMesh=this._parent.customRootNode,{_babylonTransformNode:null===this._rootBabylonMesh?void 0:this._rootBabylonMesh,index:-1};this._babylonScene._blockEntityCollection=!!this._assetContainer;const e=new N("__root__",this._babylonScene);this._rootBabylonMesh=e,this._rootBabylonMesh._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,this._rootBabylonMesh.setEnabled(!1);const t={_babylonTransformNode:this._rootBabylonMesh,index:-1};switch(this._parent.coordinateSystemMode){case re.AUTO:this._babylonScene.useRightHandedSystem||(t.rotation=[0,1,0,0],t.scale=[1,1,-1],Ee._LoadTransform(t,this._rootBabylonMesh));break;case re.FORCE_RIGHT_HANDED:this._babylonScene.useRightHandedSystem=!0;break;default:throw new Error(`Invalid coordinate system mode (${this._parent.coordinateSystemMode})`)}return this._parent.onMeshLoadedObservable.notifyObservers(e),t}loadSceneAsync(e,t){const s=this._extensionsLoadSceneAsync(e,t);if(s)return s;const n=new Array;if(this.logOpen(`${e} ${t.name||""}`),t.nodes)for(const s of t.nodes){const t=Te.Get(`${e}/nodes/${s}`,this._gltf.nodes,s);n.push(this.loadNodeAsync(`/nodes/${t.index}`,t,(e=>{e.parent=this._rootBabylonMesh})))}for(const e of this._postSceneLoadActions)e();return n.push(this._loadAnimationsAsync()),this.logClose(),Promise.all(n).then((()=>{}))}_forEachPrimitive(e,t){if(e._primitiveBabylonMeshes)for(const s of e._primitiveBabylonMeshes)t(s)}_getGeometries(){const e=[],t=this._gltf.nodes;if(t)for(const s of t)this._forEachPrimitive(s,(t=>{const s=t.geometry;s&&-1===e.indexOf(s)&&e.push(s)}));return e}_getMeshes(){const e=[];this._rootBabylonMesh instanceof D&&e.push(this._rootBabylonMesh);const t=this._gltf.nodes;if(t)for(const s of t)this._forEachPrimitive(s,(t=>{e.push(t)}));return e}_getTransformNodes(){const e=[],t=this._gltf.nodes;if(t)for(const s of t)s._babylonTransformNode&&"TransformNode"===s._babylonTransformNode.getClassName()&&e.push(s._babylonTransformNode),s._babylonTransformNodeForSkin&&e.push(s._babylonTransformNodeForSkin);return e}_getSkeletons(){const e=[],t=this._gltf.skins;if(t)for(const s of t)s._data&&e.push(s._data.babylonSkeleton);return e}_getAnimationGroups(){const e=[],t=this._gltf.animations;if(t)for(const s of t)s._babylonAnimationGroup&&e.push(s._babylonAnimationGroup);return e}_startAnimations(){switch(this._parent.animationStartMode){case ae.NONE:break;case ae.FIRST:{const e=this._getAnimationGroups();0!==e.length&&e[0].start(!0);break}case ae.ALL:{const e=this._getAnimationGroups();for(const t of e)t.start(!0);break}default:return void w.Error(`Invalid animation start mode (${this._parent.animationStartMode})`)}}loadNodeAsync(e,t,s=()=>{}){const n=this._extensionsLoadNodeAsync(e,t,s);if(n)return n;if(t._babylonTransformNode)throw new Error(`${e}: Invalid recursive node hierarchy`);const o=new Array;this.logOpen(`${e} ${t.name||""}`);const i=n=>{if(Ee.AddPointerMetadata(n,e),Ee._LoadTransform(t,n),null!=t.camera){const s=Te.Get(`${e}/camera`,this._gltf.cameras,t.camera);o.push(this.loadCameraAsync(`/cameras/${s.index}`,s,(e=>{e.parent=n,this._babylonScene.useRightHandedSystem||(n.scaling.x=-1)})))}if(t.children)for(const s of t.children){const t=Te.Get(`${e}/children/${s}`,this._gltf.nodes,s);o.push(this.loadNodeAsync(`/nodes/${t.index}`,t,(e=>{e.parent=n})))}s(n)},r=null!=t.mesh,a=this._parent.loadSkins&&null!=t.skin;if(!r||a){const e=t.name||`node${t.index}`;this._babylonScene._blockEntityCollection=!!this._assetContainer;const s=new $(e,this._babylonScene);s._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,null==t.mesh?t._babylonTransformNode=s:t._babylonTransformNodeForSkin=s,i(s)}if(r)if(a){const s=Te.Get(`${e}/mesh`,this._gltf.meshes,t.mesh);o.push(this._loadMeshAsync(`/meshes/${s.index}`,t,s,(s=>{const n=t._babylonTransformNodeForSkin;s.metadata=U(n.metadata,s.metadata||{});const i=Te.Get(`${e}/skin`,this._gltf.skins,t.skin);o.push(this._loadSkinAsync(`/skins/${i.index}`,t,i,(e=>{this._forEachPrimitive(t,(t=>{t.skeleton=e})),this._postSceneLoadActions.push((()=>{if(null!=i.skeleton){const e=Te.Get(`/skins/${i.index}/skeleton`,this._gltf.nodes,i.skeleton).parent;t.index===e.index?s.parent=n.parent:s.parent=e._babylonTransformNode}else s.parent=this._rootBabylonMesh;this._parent.onSkinLoadedObservable.notifyObservers({node:n,skinnedNode:s})}))})))})))}else{const s=Te.Get(`${e}/mesh`,this._gltf.meshes,t.mesh);o.push(this._loadMeshAsync(`/meshes/${s.index}`,t,s,i))}return this.logClose(),Promise.all(o).then((()=>(this._forEachPrimitive(t,(e=>{const t=e;!t.isAnInstance&&t.geometry&&t.geometry.useBoundingInfoFromGeometry?e._updateBoundingInfo():e.refreshBoundingInfo(!0,!0)})),t._babylonTransformNode)))}_loadMeshAsync(e,t,s,n){const o=s.primitives;if(!o||!o.length)throw new Error(`${e}: Primitives are missing`);null==o[0].index&&Te.Assign(o);const i=new Array;this.logOpen(`${e} ${s.name||""}`);const r=t.name||`node${t.index}`;if(1===o.length){const n=s.primitives[0];i.push(this._loadMeshPrimitiveAsync(`${e}/primitives/${n.index}`,r,t,s,n,(e=>{t._babylonTransformNode=e,t._primitiveBabylonMeshes=[e]})))}else{this._babylonScene._blockEntityCollection=!!this._assetContainer,t._babylonTransformNode=new $(r,this._babylonScene),t._babylonTransformNode._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,t._primitiveBabylonMeshes=[];for(const n of o)i.push(this._loadMeshPrimitiveAsync(`${e}/primitives/${n.index}`,`${r}_primitive${n.index}`,t,s,n,(e=>{e.parent=t._babylonTransformNode,t._primitiveBabylonMeshes.push(e)})))}return n(t._babylonTransformNode),this.logClose(),Promise.all(i).then((()=>t._babylonTransformNode))}_loadMeshPrimitiveAsync(e,t,s,n,o,i){const r=this._extensionsLoadMeshPrimitiveAsync(e,t,s,n,o,i);if(r)return r;this.logOpen(`${e}`);const a=0===this._disableInstancedMesh&&this._parent.createInstances&&null==s.skin&&!n.primitives[0].targets;let l,h;if(a&&o._instanceData)this._babylonScene._blockEntityCollection=!!this._assetContainer,l=o._instanceData.babylonSourceMesh.createInstance(t),l._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,h=o._instanceData.promise;else{const i=new Array;this._babylonScene._blockEntityCollection=!!this._assetContainer;const r=new N(t,this._babylonScene);r._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,r.sideOrientation=this._babylonScene.useRightHandedSystem?L.CounterClockWiseSideOrientation:L.ClockWiseSideOrientation,this._createMorphTargets(e,s,n,o,r),i.push(this._loadVertexDataAsync(e,o,r).then((async t=>await this._loadMorphTargetsAsync(e,o,r,t).then((()=>{this._disposed||(this._babylonScene._blockEntityCollection=!!this._assetContainer,t.applyToMesh(r),t._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1)})))));const c=Ee._GetDrawMode(e,o.mode);if(null==o.material){let e=this._defaultBabylonMaterialData[c];e||(e=this._createDefaultMaterial("__GLTFLoader._default",c),this._parent.onMaterialLoadedObservable.notifyObservers(e),this._defaultBabylonMaterialData[c]=e),r.material=e}else if(!this.parent.skipMaterials){const t=Te.Get(`${e}/material`,this._gltf.materials,o.material);i.push(this._loadMaterialAsync(`/materials/${t.index}`,t,r,c,(e=>{r.material=e})))}h=Promise.all(i),a&&(o._instanceData={babylonSourceMesh:r,promise:h}),l=r}return Ee.AddPointerMetadata(l,e),this._parent.onMeshLoadedObservable.notifyObservers(l),i(l),this.logClose(),h.then((()=>l))}_loadVertexDataAsync(e,t,s){const n=this._extensionsLoadVertexDataAsync(e,t,s);if(n)return n;const o=t.attributes;if(!o)throw new Error(`${e}: Attributes are missing`);const i=new Array,r=new V(s.name,this._babylonScene);if(null==t.indices)s.isUnIndexed=!0;else{const s=Te.Get(`${e}/indices`,this._gltf.accessors,t.indices);i.push(this._loadIndicesAccessorAsync(`/accessors/${s.index}`,s).then((e=>{r.setIndices(e)})))}const a=(t,n,a)=>{if(null==o[t])return;s._delayInfo=s._delayInfo||[],-1===s._delayInfo.indexOf(n)&&s._delayInfo.push(n);const l=Te.Get(`${e}/attributes/${t}`,this._gltf.accessors,o[t]);i.push(this._loadVertexAccessorAsync(`/accessors/${l.index}`,l,n).then((e=>{if(e.getKind()===b.PositionKind&&!this.parent.alwaysComputeBoundingBox&&!s.skeleton){const e=Oe(l);e&&(r._boundingInfo=e,r.useBoundingInfoFromGeometry=!0)}r.setVerticesBuffer(e,l.count)}))),n==b.MatricesIndicesExtraKind&&(s.numBoneInfluencers=8),a&&a(l)};return a("POSITION",b.PositionKind),a("NORMAL",b.NormalKind),a("TANGENT",b.TangentKind),a("TEXCOORD_0",b.UVKind),a("TEXCOORD_1",b.UV2Kind),a("TEXCOORD_2",b.UV3Kind),a("TEXCOORD_3",b.UV4Kind),a("TEXCOORD_4",b.UV5Kind),a("TEXCOORD_5",b.UV6Kind),a("JOINTS_0",b.MatricesIndicesKind),a("WEIGHTS_0",b.MatricesWeightsKind),a("JOINTS_1",b.MatricesIndicesExtraKind),a("WEIGHTS_1",b.MatricesWeightsExtraKind),a("COLOR_0",b.ColorKind,(e=>{"VEC4"===e.type&&(s.hasVertexAlpha=!0)})),Promise.all(i).then((()=>r))}_createMorphTargets(e,t,s,n,o){if(!n.targets||!this._parent.loadMorphTargets)return;if(null==t._numMorphTargets)t._numMorphTargets=n.targets.length;else if(n.targets.length!==t._numMorphTargets)throw new Error(`${e}: Primitives do not have the same number of targets`);const i=s.extras?s.extras.targetNames:null;this._babylonScene._blockEntityCollection=!!this._assetContainer,o.morphTargetManager=new me(this._babylonScene),o.morphTargetManager._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,o.morphTargetManager.areUpdatesFrozen=!0;for(let e=0;e<n.targets.length;e++){const n=t.weights?t.weights[e]:s.weights?s.weights[e]:0,r=i?i[e]:`morphTarget${e}`;o.morphTargetManager.addTarget(new _e(r,n,o.getScene()))}}_loadMorphTargetsAsync(e,t,s,n){if(!t.targets||!this._parent.loadMorphTargets)return Promise.resolve();const o=new Array,i=s.morphTargetManager;for(let s=0;s<i.numTargets;s++){const r=i.getTarget(s);o.push(this._loadMorphTargetVertexDataAsync(`${e}/targets/${s}`,n,t.targets[s],r))}return Promise.all(o).then((()=>{i.areUpdatesFrozen=!1}))}async _loadMorphTargetVertexDataAsync(e,t,s,n){const o=new Array,i=(n,i,r)=>{if(null==s[n])return;const a=t.getVertexBuffer(i);if(!a)return;const l=Te.Get(`${e}/${n}`,this._gltf.accessors,s[n]);o.push(this._loadFloatAccessorAsync(`/accessors/${l.index}`,l).then((e=>{r(a,e)})))};return i("POSITION",b.PositionKind,((e,t)=>{const s=new Float32Array(t.length);e.forEach(t.length,((e,n)=>{s[n]=t[n]+e})),n.setPositions(s)})),i("NORMAL",b.NormalKind,((e,t)=>{const s=new Float32Array(t.length);e.forEach(s.length,((e,n)=>{s[n]=t[n]+e})),n.setNormals(s)})),i("TANGENT",b.TangentKind,((e,t)=>{const s=new Float32Array(t.length/3*4);let o=0;e.forEach(t.length/3*4,((e,n)=>{(n+1)%4!=0&&(s[o]=t[o]+e,o++)})),n.setTangents(s)})),i("TEXCOORD_0",b.UVKind,((e,t)=>{const s=new Float32Array(t.length);e.forEach(t.length,((e,n)=>{s[n]=t[n]+e})),n.setUVs(s)})),i("TEXCOORD_1",b.UV2Kind,((e,t)=>{const s=new Float32Array(t.length);e.forEach(t.length,((e,n)=>{s[n]=t[n]+e})),n.setUV2s(s)})),i("COLOR_0",b.ColorKind,((t,s)=>{let o=null;const i=t.getSize();if(3===i){o=new Float32Array(s.length/3*4),t.forEach(s.length,((e,t)=>{const n=Math.floor(t/3),i=t%3;o[4*n+i]=s[3*n+i]+e}));for(let e=0;e<s.length/3;++e)o[4*e+3]=1}else{if(4!==i)throw new Error(`${e}: Invalid number of components (${i}) for COLOR_0 attribute`);o=new Float32Array(s.length),t.forEach(s.length,((e,t)=>{o[t]=s[t]+e}))}n.setColors(o)})),await Promise.all(o).then((()=>{}))}static _LoadTransform(e,t){if(null!=e.skin)return;let n=s.Zero(),o=F.Identity(),i=s.One();if(e.matrix){h.FromArray(e.matrix).decompose(i,o,n)}else e.translation&&(n=s.FromArray(e.translation)),e.rotation&&(o=F.FromArray(e.rotation)),e.scale&&(i=s.FromArray(e.scale));t.position=n,t.rotationQuaternion=o,t.scaling=i}_loadSkinAsync(e,t,s,n){if(!this._parent.loadSkins)return Promise.resolve();const o=this._extensionsLoadSkinAsync(e,t,s);if(o)return o;if(s._data)return n(s._data.babylonSkeleton),s._data.promise;const i=`skeleton${s.index}`;this._babylonScene._blockEntityCollection=!!this._assetContainer;const r=new Q(s.name||i,i,this._babylonScene);r._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,this._loadBones(e,s,r);const a=this._loadSkinInverseBindMatricesDataAsync(e,s).then((e=>{this._updateBoneMatrices(r,e)}));return s._data={babylonSkeleton:r,promise:a},n(r),a}_loadBones(e,t,s){if(null==t.skeleton||this._parent.alwaysComputeSkeletonRootNode){const s=this._findSkeletonRootNode(`${e}/joints`,t.joints);if(s)if(void 0===t.skeleton)t.skeleton=s.index;else{const n=(e,t)=>{for(;t.parent;t=t.parent)if(t.parent===e)return!0;return!1},o=Te.Get(`${e}/skeleton`,this._gltf.nodes,t.skeleton);o===s||n(o,s)||(w.Warn(`${e}/skeleton: Overriding with nearest common ancestor as skeleton node is not a common root`),t.skeleton=s.index)}else w.Warn(`${e}: Failed to find common root`)}const n={};for(const o of t.joints){const i=Te.Get(`${e}/joints/${o}`,this._gltf.nodes,o);this._loadBone(i,t,s,n)}}_findSkeletonRootNode(e,t){if(0===t.length)return null;const s={};for(const n of t){const t=[];let o=Te.Get(`${e}/${n}`,this._gltf.nodes,n);for(;-1!==o.index;)t.unshift(o),o=o.parent;s[n]=t}let n=null;for(let e=0;;++e){let o=s[t[0]];if(e>=o.length)return n;const i=o[e];for(let r=1;r<t.length;++r)if(o=s[t[r]],e>=o.length||i!==o[e])return n;n=i}}_loadBone(e,t,s,n){e._isJoint=!0;let o=n[e.index];if(o)return o;let i=null;e.index!==t.skeleton&&(e.parent&&-1!==e.parent.index?i=this._loadBone(e.parent,t,s,n):void 0!==t.skeleton&&w.Warn(`/skins/${t.index}/skeleton: Skeleton node is not a common root`));const r=t.joints.indexOf(e.index);return o=new J(e.name||`joint${e.index}`,s,i,this._getNodeMatrix(e),null,null,r),n[e.index]=o,this._postSceneLoadActions.push((()=>{o.linkTransformNode(e._babylonTransformNode)})),o}_loadSkinInverseBindMatricesDataAsync(e,t){if(null==t.inverseBindMatrices)return Promise.resolve(null);const s=Te.Get(`${e}/inverseBindMatrices`,this._gltf.accessors,t.inverseBindMatrices);return this._loadFloatAccessorAsync(`/accessors/${s.index}`,s)}_updateBoneMatrices(e,t){for(const s of e.bones){const e=h.Identity(),n=s._index;t&&-1!==n&&(h.FromArrayToRef(t,16*n,e),e.invertToRef(e));const o=s.getParent();o&&e.multiplyToRef(o.getAbsoluteInverseBindMatrix(),e),s.updateMatrix(e,!1,!1),s._updateAbsoluteBindMatrices(void 0,!1)}}_getNodeMatrix(e){return e.matrix?h.FromArray(e.matrix):h.Compose(e.scale?s.FromArray(e.scale):s.One(),e.rotation?F.FromArray(e.rotation):F.Identity(),e.translation?s.FromArray(e.translation):s.Zero())}loadCameraAsync(e,t,n=()=>{}){const o=this._extensionsLoadCameraAsync(e,t,n);if(o)return o;const i=new Array;this.logOpen(`${e} ${t.name||""}`),this._babylonScene._blockEntityCollection=!!this._assetContainer;const r=new ue(t.name||`camera${t.index}`,s.Zero(),this._babylonScene,!1);switch(r._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,t._babylonCamera=r,r.setTarget(new s(0,0,-1)),t.type){case"perspective":{const s=t.perspective;if(!s)throw new Error(`${e}: Camera perspective properties are missing`);r.fov=s.yfov,r.minZ=s.znear,r.maxZ=s.zfar||0;break}case"orthographic":if(!t.orthographic)throw new Error(`${e}: Camera orthographic properties are missing`);r.mode=B.ORTHOGRAPHIC_CAMERA,r.orthoLeft=-t.orthographic.xmag,r.orthoRight=t.orthographic.xmag,r.orthoBottom=-t.orthographic.ymag,r.orthoTop=t.orthographic.ymag,r.minZ=t.orthographic.znear,r.maxZ=t.orthographic.zfar;break;default:throw new Error(`${e}: Invalid camera type (${t.type})`)}return Ee.AddPointerMetadata(r,e),this._parent.onCameraLoadedObservable.notifyObservers(r),n(r),this.logClose(),Promise.all(i).then((()=>r))}_loadAnimationsAsync(){this._parent._startPerformanceCounter("Load animations");const e=this._gltf.animations;if(!e)return Promise.resolve();const t=new Array;for(let s=0;s<e.length;s++){const n=e[s];t.push(this.loadAnimationAsync(`/animations/${n.index}`,n).then((e=>{0===e.targetedAnimations.length&&e.dispose()})))}return Promise.all(t).then((()=>{this._parent._endPerformanceCounter("Load animations")}))}loadAnimationAsync(e,t){this._parent._startPerformanceCounter("Load animation");const s=this._extensionsLoadAnimationAsync(e,t);return s||Ce.value.then((({AnimationGroup:s})=>{this._babylonScene._blockEntityCollection=!!this._assetContainer;const n=new s(t.name||`animation${t.index}`,this._babylonScene);n._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,t._babylonAnimationGroup=n;const o=new Array;Te.Assign(t.channels),Te.Assign(t.samplers);for(const s of t.channels)o.push(this._loadAnimationChannelAsync(`${e}/channels/${s.index}`,e,t,s,((e,t)=>{e.animations=e.animations||[],e.animations.push(t),n.addTargetedAnimation(t,e)})));return this._parent._endPerformanceCounter("Load animation"),Promise.all(o).then((()=>(n.normalize(0),n)))}))}_loadAnimationChannelAsync(e,t,s,n,o){const i=this._extensionsLoadAnimationChannelAsync(e,t,s,n,o);if(i)return i;if(null==n.target.node)return Promise.resolve();const r=Te.Get(`${e}/target/node`,this._gltf.nodes,n.target.node),a=n.target.path,l="weights"===a;return l&&!r._numMorphTargets||!l&&!r._babylonTransformNode?Promise.resolve():this._parent.loadNodeAnimations||l||r._isJoint?Me.value.then((()=>{let i;switch(a){case"translation":i=te("/nodes/{}/translation")?.interpolation;break;case"rotation":i=te("/nodes/{}/rotation")?.interpolation;break;case"scale":i=te("/nodes/{}/scale")?.interpolation;break;case"weights":i=te("/nodes/{}/weights")?.interpolation;break;default:throw new Error(`${e}/target/path: Invalid value (${n.target.path})`)}if(!i)throw new Error(`${e}/target/path: Could not find interpolation properties for target path (${n.target.path})`);const l={object:r,info:i};return this._loadAnimationChannelFromTargetInfoAsync(e,t,s,n,l,o)})):Promise.resolve()}_loadAnimationChannelFromTargetInfoAsync(e,t,s,n,o,i){const r=this.parent.targetFps,a=1/r,l=Te.Get(`${e}/sampler`,s.samplers,n.sampler);return this._loadAnimationSamplerAsync(`${t}/samplers/${n.sampler}`,l).then((e=>{let t=0;const l=o.object,h=o.info;for(const o of h){const h=o.getStride(l),c=e.input,d=e.output,u=new Array(c.length);let _=0;switch(e.interpolation){case"STEP":for(let e=0;e<c.length;e++){const t=o.getValue(l,d,_,1);_+=h,u[e]={frame:c[e]*r,value:t,interpolation:1}}break;case"CUBICSPLINE":for(let e=0;e<c.length;e++){const t=o.getValue(l,d,_,a);_+=h;const s=o.getValue(l,d,_,1);_+=h;const n=o.getValue(l,d,_,a);_+=h,u[e]={frame:c[e]*r,inTangent:t,value:s,outTangent:n}}break;case"LINEAR":for(let e=0;e<c.length;e++){const t=o.getValue(l,d,_,1);_+=h,u[e]={frame:c[e]*r,value:t}}}if(_>0){const e=`${s.name||`animation${s.index}`}_channel${n.index}_${t}`,a=o.buildAnimations(l,e,r,u);for(const e of a)t++,i(e.babylonAnimatable,e.babylonAnimation)}}}))}_loadAnimationSamplerAsync(e,t){if(t._data)return t._data;const s=t.interpolation||"LINEAR";switch(s){case"STEP":case"LINEAR":case"CUBICSPLINE":break;default:throw new Error(`${e}/interpolation: Invalid value (${t.interpolation})`)}const n=Te.Get(`${e}/input`,this._gltf.accessors,t.input),o=Te.Get(`${e}/output`,this._gltf.accessors,t.output);return t._data=Promise.all([this._loadFloatAccessorAsync(`/accessors/${n.index}`,n),this._loadFloatAccessorAsync(`/accessors/${o.index}`,o)]).then((([e,t])=>({input:e,interpolation:s,output:t}))),t._data}loadBufferAsync(e,t,s,n){const o=this._extensionsLoadBufferAsync(e,t,s,n);if(o)return o;if(!t._data)if(t.uri)t._data=this.loadUriAsync(`${e}/uri`,t,t.uri);else{if(!this._bin)throw new Error(`${e}: Uri is missing or the binary glTF is missing its binary chunk`);t._data=this._bin.readAsync(0,t.byteLength)}return t._data.then((t=>{try{return new Uint8Array(t.buffer,t.byteOffset+s,n)}catch(t){throw new Error(`${e}: ${t.message}`)}}))}loadBufferViewAsync(e,t){const s=this._extensionsLoadBufferViewAsync(e,t);if(s)return s;if(t._data)return t._data;const n=Te.Get(`${e}/buffer`,this._gltf.buffers,t.buffer);return t._data=this.loadBufferAsync(`/buffers/${n.index}`,n,t.byteOffset||0,t.byteLength),t._data}_loadAccessorAsync(e,t,s){if(t._data)return t._data;const n=Ee._GetNumComponents(e,t.type),o=n*b.GetTypeByteLength(t.componentType),i=n*t.count;if(null==t.bufferView)t._data=Promise.resolve(new s(i));else{const r=Te.Get(`${e}/bufferView`,this._gltf.bufferViews,t.bufferView);t._data=this.loadBufferViewAsync(`/bufferViews/${r.index}`,r).then((a=>{if(5126!==t.componentType||t.normalized||r.byteStride&&r.byteStride!==o){const e=new s(i);return b.ForEach(a,t.byteOffset||0,r.byteStride||o,n,t.componentType,e.length,t.normalized||!1,((t,s)=>{e[s]=t})),e}return Ee._GetTypedArray(e,t.componentType,a,t.byteOffset,i)}))}if(t.sparse){const i=t.sparse;t._data=t._data.then((r=>{const a=r,l=Te.Get(`${e}/sparse/indices/bufferView`,this._gltf.bufferViews,i.indices.bufferView),h=Te.Get(`${e}/sparse/values/bufferView`,this._gltf.bufferViews,i.values.bufferView);return Promise.all([this.loadBufferViewAsync(`/bufferViews/${l.index}`,l),this.loadBufferViewAsync(`/bufferViews/${h.index}`,h)]).then((([r,l])=>{const h=Ee._GetTypedArray(`${e}/sparse/indices`,i.indices.componentType,r,i.indices.byteOffset,i.count),c=n*i.count;let d;if(5126!==t.componentType||t.normalized){const r=Ee._GetTypedArray(`${e}/sparse/values`,t.componentType,l,i.values.byteOffset,c);d=new s(c),b.ForEach(r,0,o,n,t.componentType,d.length,t.normalized||!1,((e,t)=>{d[t]=e}))}else d=Ee._GetTypedArray(`${e}/sparse/values`,t.componentType,l,i.values.byteOffset,c);let u=0;for(let e=0;e<h.length;e++){let t=h[e]*n;for(let e=0;e<n;e++)a[t++]=d[u++]}return a}))}))}return t._data}_loadFloatAccessorAsync(e,t){return this._loadAccessorAsync(e,t,Float32Array)}_loadIndicesAccessorAsync(e,t){if("SCALAR"!==t.type)throw new Error(`${e}/type: Invalid value ${t.type}`);if(5121!==t.componentType&&5123!==t.componentType&&5125!==t.componentType)throw new Error(`${e}/componentType: Invalid value ${t.componentType}`);if(t._data)return t._data;if(t.sparse){const s=Ee._GetTypedArrayConstructor(`${e}/componentType`,t.componentType);t._data=this._loadAccessorAsync(e,t,s)}else{const s=Te.Get(`${e}/bufferView`,this._gltf.bufferViews,t.bufferView);t._data=this.loadBufferViewAsync(`/bufferViews/${s.index}`,s).then((s=>Ee._GetTypedArray(e,t.componentType,s,t.byteOffset,t.count)))}return t._data}_loadVertexBufferViewAsync(e){if(e._babylonBuffer)return e._babylonBuffer;const t=this._babylonScene.getEngine();return e._babylonBuffer=this.loadBufferViewAsync(`/bufferViews/${e.index}`,e).then((e=>new G(t,e,!1))),e._babylonBuffer}_loadVertexAccessorAsync(e,t,s){if(t._babylonVertexBuffer?.[s])return t._babylonVertexBuffer[s];t._babylonVertexBuffer||(t._babylonVertexBuffer={});const n=this._babylonScene.getEngine();if(t.sparse||null==t.bufferView)t._babylonVertexBuffer[s]=this._loadFloatAccessorAsync(e,t).then((e=>new b(n,e,s,!1)));else{const o=Te.Get(`${e}/bufferView`,this._gltf.bufferViews,t.bufferView);t._babylonVertexBuffer[s]=this._loadVertexBufferViewAsync(o).then((i=>{const r=Ee._GetNumComponents(e,t.type);return new b(n,i,s,!1,void 0,o.byteStride,void 0,t.byteOffset,r,t.componentType,t.normalized,!0,void 0,!0)}))}return t._babylonVertexBuffer[s]}_loadMaterialMetallicRoughnessPropertiesAsync(e,t,s){if(!(s instanceof W))throw new Error(`${e}: Material type not supported`);const n=new Array;return t&&(t.baseColorFactor?(s.albedoColor=X.FromArray(t.baseColorFactor),s.alpha=t.baseColorFactor[3]):s.albedoColor=X.White(),s.metallic=null==t.metallicFactor?1:t.metallicFactor,s.roughness=null==t.roughnessFactor?1:t.roughnessFactor,t.baseColorTexture&&n.push(this.loadTextureInfoAsync(`${e}/baseColorTexture`,t.baseColorTexture,(e=>{e.name=`${s.name} (Base Color)`,s.albedoTexture=e}))),t.metallicRoughnessTexture&&(t.metallicRoughnessTexture.nonColorData=!0,n.push(this.loadTextureInfoAsync(`${e}/metallicRoughnessTexture`,t.metallicRoughnessTexture,(e=>{e.name=`${s.name} (Metallic Roughness)`,s.metallicTexture=e}))),s.useMetallnessFromMetallicTextureBlue=!0,s.useRoughnessFromMetallicTextureGreen=!0,s.useRoughnessFromMetallicTextureAlpha=!1)),Promise.all(n).then((()=>{}))}_loadMaterialAsync(e,t,s,n,o=()=>{}){const i=this._extensionsLoadMaterialAsync(e,t,s,n,o);if(i)return i;t._data=t._data||{};let r=t._data[n];if(!r){this.logOpen(`${e} ${t.name||""}`);const s=this.createMaterial(e,t,n);r={babylonMaterial:s,babylonMeshes:[],promise:this.loadMaterialPropertiesAsync(e,t,s)},t._data[n]=r,Ee.AddPointerMetadata(s,e),this._parent.onMaterialLoadedObservable.notifyObservers(s),this.logClose()}return s&&(r.babylonMeshes.push(s),s.onDisposeObservable.addOnce((()=>{const e=r.babylonMeshes.indexOf(s);-1!==e&&r.babylonMeshes.splice(e,1)}))),o(r.babylonMaterial),r.promise.then((()=>r.babylonMaterial))}_createDefaultMaterial(e,t){this._babylonScene._blockEntityCollection=!!this._assetContainer;const s=new W(e,this._babylonScene);return s._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,s.fillMode=t,s.enableSpecularAntiAliasing=!0,s.useRadianceOverAlpha=!this._parent.transparencyAsCoverage,s.useSpecularOverAlpha=!this._parent.transparencyAsCoverage,s.transparencyMode=W.PBRMATERIAL_OPAQUE,s.metallic=1,s.roughness=1,s}createMaterial(e,t,s){const n=this._extensionsCreateMaterial(e,t,s);if(n)return n;const o=t.name||`material${t.index}`;return this._createDefaultMaterial(o,s)}loadMaterialPropertiesAsync(e,t,s){const n=this._extensionsLoadMaterialPropertiesAsync(e,t,s);if(n)return n;const o=new Array;return o.push(this.loadMaterialBasePropertiesAsync(e,t,s)),t.pbrMetallicRoughness&&o.push(this._loadMaterialMetallicRoughnessPropertiesAsync(`${e}/pbrMetallicRoughness`,t.pbrMetallicRoughness,s)),this.loadMaterialAlphaProperties(e,t,s),Promise.all(o).then((()=>{}))}loadMaterialBasePropertiesAsync(e,t,s){if(!(s instanceof W))throw new Error(`${e}: Material type not supported`);const n=new Array;return s.emissiveColor=t.emissiveFactor?X.FromArray(t.emissiveFactor):new X(0,0,0),t.doubleSided&&(s.backFaceCulling=!1,s.twoSidedLighting=!0),t.normalTexture&&(t.normalTexture.nonColorData=!0,n.push(this.loadTextureInfoAsync(`${e}/normalTexture`,t.normalTexture,(e=>{e.name=`${s.name} (Normal)`,s.bumpTexture=e}))),s.invertNormalMapX=!this._babylonScene.useRightHandedSystem,s.invertNormalMapY=this._babylonScene.useRightHandedSystem,null!=t.normalTexture.scale&&s.bumpTexture&&(s.bumpTexture.level=t.normalTexture.scale),s.forceIrradianceInFragment=!0),t.occlusionTexture&&(t.occlusionTexture.nonColorData=!0,n.push(this.loadTextureInfoAsync(`${e}/occlusionTexture`,t.occlusionTexture,(e=>{e.name=`${s.name} (Occlusion)`,s.ambientTexture=e}))),s.useAmbientInGrayScale=!0,null!=t.occlusionTexture.strength&&(s.ambientTextureStrength=t.occlusionTexture.strength)),t.emissiveTexture&&n.push(this.loadTextureInfoAsync(`${e}/emissiveTexture`,t.emissiveTexture,(e=>{e.name=`${s.name} (Emissive)`,s.emissiveTexture=e}))),Promise.all(n).then((()=>{}))}loadMaterialAlphaProperties(e,t,s){if(!(s instanceof W))throw new Error(`${e}: Material type not supported`);switch(t.alphaMode||"OPAQUE"){case"OPAQUE":s.transparencyMode=W.PBRMATERIAL_OPAQUE,s.alpha=1;break;case"MASK":s.transparencyMode=W.PBRMATERIAL_ALPHATEST,s.alphaCutOff=null==t.alphaCutoff?.5:t.alphaCutoff,s.albedoTexture&&(s.albedoTexture.hasAlpha=!0);break;case"BLEND":s.transparencyMode=W.PBRMATERIAL_ALPHABLEND,s.albedoTexture&&(s.albedoTexture.hasAlpha=!0,s.useAlphaFromAlbedoTexture=!0);break;default:throw new Error(`${e}/alphaMode: Invalid value (${t.alphaMode})`)}}loadTextureInfoAsync(e,t,s=()=>{}){const n=this._extensionsLoadTextureInfoAsync(e,t,s);if(n)return n;if(this.logOpen(`${e}`),t.texCoord>=6)throw new Error(`${e}/texCoord: Invalid value (${t.texCoord})`);const o=Te.Get(`${e}/index`,this._gltf.textures,t.index);o._textureInfo=t;const i=this._loadTextureAsync(`/textures/${t.index}`,o,(n=>{n.coordinatesIndex=t.texCoord||0,Ee.AddPointerMetadata(n,e),this._parent.onTextureLoadedObservable.notifyObservers(n),s(n)}));return this.logClose(),i}_loadTextureAsync(e,t,s=()=>{}){const n=this._extensionsLoadTextureAsync(e,t,s);if(n)return n;this.logOpen(`${e} ${t.name||""}`);const o=null==t.sampler?Ee.DefaultSampler:Te.Get(`${e}/sampler`,this._gltf.samplers,t.sampler),i=Te.Get(`${e}/source`,this._gltf.images,t.source),r=this._createTextureAsync(e,o,i,s,void 0,!t._textureInfo.nonColorData);return this.logClose(),r}_createTextureAsync(e,t,s,n=()=>{},o,i){const r=this._loadSampler(`/samplers/${t.index}`,t),a=new Array,l=new Y;this._babylonScene._blockEntityCollection=!!this._assetContainer;const h={noMipmap:r.noMipMaps,invertY:!1,samplingMode:r.samplingMode,onLoad:()=>{this._disposed||l.resolve()},onError:(t,s)=>{this._disposed||l.reject(new Error(`${e}: ${s&&s.message?s.message:t||"Failed to load texture"}`))},mimeType:s.mimeType??Z(s.uri??""),loaderOptions:o,useSRGBBuffer:!!i&&this._parent.useSRGBBuffers},c=new v(null,this._babylonScene,h);return c._parentContainer=this._assetContainer,this._babylonScene._blockEntityCollection=!1,a.push(l.promise),a.push(this.loadImageAsync(`/images/${s.index}`,s).then((e=>{const t=s.uri||`${this._fileName}#image${s.index}`,n=`data:${this._uniqueRootUrl}${t}`;c.updateURL(n,e);const o=c.getInternalTexture();o&&(o.label=s.name)}))),c.wrapU=r.wrapU,c.wrapV=r.wrapV,n(c),this._parent.useGltfTextureNames&&(c.name=s.name||s.uri||`image${s.index}`),Promise.all(a).then((()=>c))}_loadSampler(e,t){return t._data||(t._data={noMipMaps:9728===t.minFilter||9729===t.minFilter,samplingMode:Ee._GetTextureSamplingMode(e,t),wrapU:Ee._GetTextureWrapMode(`${e}/wrapS`,t.wrapS),wrapV:Ee._GetTextureWrapMode(`${e}/wrapT`,t.wrapT)}),t._data}loadImageAsync(e,t){if(!t._data){if(this.logOpen(`${e} ${t.name||""}`),t.uri)t._data=this.loadUriAsync(`${e}/uri`,t,t.uri);else{const s=Te.Get(`${e}/bufferView`,this._gltf.bufferViews,t.bufferView);t._data=this.loadBufferViewAsync(`/bufferViews/${s.index}`,s)}this.logClose()}return t._data}loadUriAsync(e,t,s){const n=this._extensionsLoadUriAsync(e,t,s);if(n)return n;if(!Ee._ValidateUri(s))throw new Error(`${e}: '${s}' is invalid`);if(z(s)){const t=new Uint8Array(O(s));return this.log(`${e}: Decoded ${s.substring(0,64)}... (${t.length} bytes)`),Promise.resolve(t)}return this.log(`${e}: Loading ${s}`),this._parent.preprocessUrlAsync(this._rootUrl+s).then((t=>new Promise(((n,o)=>{this._parent._loadFile(this._babylonScene,t,(t=>{this._disposed||(this.log(`${e}: Loaded ${s} (${t.byteLength} bytes)`),n(new Uint8Array(t)))}),!0,(t=>{o(new K(`${e}: Failed to load '${s}'${t?": "+t.status+" "+t.statusText:""}`,t))}))}))))}static AddPointerMetadata(e,t){e.metadata=e.metadata||{};const s=e._internalMetadata=e._internalMetadata||{},n=s.gltf=s.gltf||{};(n.pointers=n.pointers||[]).push(t)}static _GetTextureWrapMode(e,t){switch(t=null==t?10497:t){case 33071:return v.CLAMP_ADDRESSMODE;case 33648:return v.MIRROR_ADDRESSMODE;case 10497:return v.WRAP_ADDRESSMODE;default:return w.Warn(`${e}: Invalid value (${t})`),v.WRAP_ADDRESSMODE}}static _GetTextureSamplingMode(e,t){const s=null==t.magFilter?9729:t.magFilter,n=null==t.minFilter?9987:t.minFilter;if(9729===s)switch(n){case 9728:return v.LINEAR_NEAREST;case 9729:return v.LINEAR_LINEAR;case 9984:return v.LINEAR_NEAREST_MIPNEAREST;case 9985:return v.LINEAR_LINEAR_MIPNEAREST;case 9986:return v.LINEAR_NEAREST_MIPLINEAR;case 9987:return v.LINEAR_LINEAR_MIPLINEAR;default:return w.Warn(`${e}/minFilter: Invalid value (${n})`),v.LINEAR_LINEAR_MIPLINEAR}else switch(9728!==s&&w.Warn(`${e}/magFilter: Invalid value (${s})`),n){case 9728:return v.NEAREST_NEAREST;case 9729:return v.NEAREST_LINEAR;case 9984:return v.NEAREST_NEAREST_MIPNEAREST;case 9985:return v.NEAREST_LINEAR_MIPNEAREST;case 9986:return v.NEAREST_NEAREST_MIPLINEAR;case 9987:return v.NEAREST_LINEAR_MIPLINEAR;default:return w.Warn(`${e}/minFilter: Invalid value (${n})`),v.NEAREST_NEAREST_MIPNEAREST}}static _GetTypedArrayConstructor(e,t){try{return j(t)}catch(t){throw new Error(`${e}: ${t.message}`)}}static _GetTypedArray(e,t,s,n,o){const i=s.buffer;n=s.byteOffset+(n||0);const r=Ee._GetTypedArrayConstructor(`${e}/componentType`,t),a=b.GetTypeByteLength(t);return n%a!==0?(w.Warn(`${e}: Copying buffer as byte offset (${n}) is not a multiple of component type byte length (${a})`),new r(i.slice(n,n+o*a),0)):new r(i,n,o)}static _GetNumComponents(e,t){switch(t){case"SCALAR":return 1;case"VEC2":return 2;case"VEC3":return 3;case"VEC4":case"MAT2":return 4;case"MAT3":return 9;case"MAT4":return 16}throw new Error(`${e}: Invalid type (${t})`)}static _ValidateUri(t){return e.IsBase64(t)||-1===t.indexOf("..")}static _GetDrawMode(e,t){switch(null==t&&(t=4),t){case 0:return L.PointListDrawMode;case 1:return L.LineListDrawMode;case 2:return L.LineLoopDrawMode;case 3:return L.LineStripDrawMode;case 4:return L.TriangleFillMode;case 5:return L.TriangleStripDrawMode;case 6:return L.TriangleFanDrawMode}throw new Error(`${e}: Invalid mesh primitive mode (${t})`)}_compileMaterialsAsync(){this._parent._startPerformanceCounter("Compile materials");const e=new Array;if(this._gltf.materials)for(const t of this._gltf.materials)if(t._data)for(const s in t._data){const n=t._data[s];for(const t of n.babylonMeshes){t.computeWorldMatrix(!0);const s=n.babylonMaterial;e.push(s.forceCompilationAsync(t)),e.push(s.forceCompilationAsync(t,{useInstances:!0})),this._parent.useClipPlane&&(e.push(s.forceCompilationAsync(t,{clipPlane:!0})),e.push(s.forceCompilationAsync(t,{clipPlane:!0,useInstances:!0})))}}return Promise.all(e).then((()=>{this._parent._endPerformanceCounter("Compile materials")}))}_compileShadowGeneratorsAsync(){this._parent._startPerformanceCounter("Compile shadow generators");const e=new Array,t=this._babylonScene.lights;for(const s of t){const t=s.getShadowGenerator();t&&e.push(t.forceCompilationAsync())}return Promise.all(e).then((()=>{this._parent._endPerformanceCounter("Compile shadow generators")}))}_forEachExtensions(e){for(const t of this._extensions)t.enabled&&e(t)}_applyExtensions(e,t,s){for(const n of this._extensions)if(n.enabled){const o=`${n.name}.${t}`,i=e;i._activeLoaderExtensionFunctions=i._activeLoaderExtensionFunctions||{};const r=i._activeLoaderExtensionFunctions;if(!r[o]){r[o]=!0;try{const e=s(n);if(e)return e}finally{delete r[o]}}}return null}_extensionsOnLoading(){this._forEachExtensions((e=>e.onLoading&&e.onLoading()))}_extensionsOnReady(){this._forEachExtensions((e=>e.onReady&&e.onReady()))}_extensionsLoadSceneAsync(e,t){return this._applyExtensions(t,"loadScene",(s=>s.loadSceneAsync&&s.loadSceneAsync(e,t)))}_extensionsLoadNodeAsync(e,t,s){return this._applyExtensions(t,"loadNode",(n=>n.loadNodeAsync&&n.loadNodeAsync(e,t,s)))}_extensionsLoadCameraAsync(e,t,s){return this._applyExtensions(t,"loadCamera",(n=>n.loadCameraAsync&&n.loadCameraAsync(e,t,s)))}_extensionsLoadVertexDataAsync(e,t,s){return this._applyExtensions(t,"loadVertexData",(n=>n._loadVertexDataAsync&&n._loadVertexDataAsync(e,t,s)))}_extensionsLoadMeshPrimitiveAsync(e,t,s,n,o,i){return this._applyExtensions(o,"loadMeshPrimitive",(r=>r._loadMeshPrimitiveAsync&&r._loadMeshPrimitiveAsync(e,t,s,n,o,i)))}_extensionsLoadMaterialAsync(e,t,s,n,o){return this._applyExtensions(t,"loadMaterial",(i=>i._loadMaterialAsync&&i._loadMaterialAsync(e,t,s,n,o)))}_extensionsCreateMaterial(e,t,s){return this._applyExtensions(t,"createMaterial",(n=>n.createMaterial&&n.createMaterial(e,t,s)))}_extensionsLoadMaterialPropertiesAsync(e,t,s){return this._applyExtensions(t,"loadMaterialProperties",(n=>n.loadMaterialPropertiesAsync&&n.loadMaterialPropertiesAsync(e,t,s)))}_extensionsLoadTextureInfoAsync(e,t,s){return this._applyExtensions(t,"loadTextureInfo",(n=>n.loadTextureInfoAsync&&n.loadTextureInfoAsync(e,t,s)))}_extensionsLoadTextureAsync(e,t,s){return this._applyExtensions(t,"loadTexture",(n=>n._loadTextureAsync&&n._loadTextureAsync(e,t,s)))}_extensionsLoadAnimationAsync(e,t){return this._applyExtensions(t,"loadAnimation",(s=>s.loadAnimationAsync&&s.loadAnimationAsync(e,t)))}_extensionsLoadAnimationChannelAsync(e,t,s,n,o){return this._applyExtensions(s,"loadAnimationChannel",(i=>i._loadAnimationChannelAsync&&i._loadAnimationChannelAsync(e,t,s,n,o)))}_extensionsLoadSkinAsync(e,t,s){return this._applyExtensions(s,"loadSkin",(n=>n._loadSkinAsync&&n._loadSkinAsync(e,t,s)))}_extensionsLoadUriAsync(e,t,s){return this._applyExtensions(t,"loadUri",(n=>n._loadUriAsync&&n._loadUriAsync(e,t,s)))}_extensionsLoadBufferViewAsync(e,t){return this._applyExtensions(t,"loadBufferView",(s=>s.loadBufferViewAsync&&s.loadBufferViewAsync(e,t)))}_extensionsLoadBufferAsync(e,t,s,n){return this._applyExtensions(t,"loadBuffer",(o=>o.loadBufferAsync&&o.loadBufferAsync(e,t,s,n)))}static LoadExtensionAsync(e,t,s,n){if(!t.extensions)return null;const o=t.extensions[s];return o?n(`${e}/extensions/${s}`,o):null}static LoadExtraAsync(e,t,s,n){if(!t.extras)return null;const o=t.extras[s];return o?n(`${e}/extras/${s}`,o):null}isExtensionUsed(e){return!!this._gltf.extensionsUsed&&-1!==this._gltf.extensionsUsed.indexOf(e)}logOpen(e){this._parent._logOpen(e)}logClose(){this._parent._logClose()}log(e){this._parent._log(e)}startPerformanceCounter(e){this._parent._startPerformanceCounter(e)}endPerformanceCounter(e){this._parent._endPerformanceCounter(e)}}Ee.DefaultSampler={index:-1},xe._CreateGLTF2Loader=e=>new Ee(e);export{Te as ArrayItem,xe as GLTFFileLoader,Ee as GLTFLoader,Oe as LoadBoundingInfoFromPositionAccessor};
//# sourceMappingURL=glTFLoader-DrZpsmpQ.esm.min.js.map