-
Notifications
You must be signed in to change notification settings - Fork 0
/
87a06baf-5d3ac30d48950f0f9b7a.js
2 lines (2 loc) · 63.9 KB
/
87a06baf-5d3ac30d48950f0f9b7a.js
1
2
"use strict";(self.webpackChunkcode_cave=self.webpackChunkcode_cave||[]).push([[568],{7575:function(e,t,s){s.d(t,{Kj:function(){return F},gW:function(){return A}});var n=s(8139),i=s(8658),r=s(2827),a=s(4104),o=s(140),h=s(4515),l=s(147),c=s(5412),d=s(2922),u=s(6387),f=s(2186),g=s(2341),_=s(4106),m=s(5068),I=s(4735),M=s(2067),p=s(8058),v=s(5458),y=s(8137),D=s(658),b=s(646),S=s(9069),x=s(4559),B=s(1298);class A{}class P{constructor(){this.visibleInstances={},this.batchCache=new w,this.batchCacheReplacementModeInFrozenMode=new w,this.instancesBufferSize=2048}}class w{constructor(){this.mustReturn=!1,this.visibleInstances=new Array,this.renderSelf=new Array,this.hardwareInstancedRendering=new Array}}class O{constructor(){this.instancesCount=0,this.matrixBuffer=null,this.previousMatrixBuffer=null,this.matrixBufferSize=512,this.matrixData=null,this.boundingVectors=[],this.worldMatrices=null}}class C{constructor(){this._areNormalsFrozen=!1,this._source=null,this.meshMap=null,this._preActivateId=-1,this._LODLevels=new Array,this._useLODScreenCoverage=!1,this._effectiveMaterial=null,this._forcedInstanceCount=0,this._overrideRenderingFillMode=null}}class F extends m.x{static _GetDefaultSideOrientation(e){return e||F.FRONTSIDE}get useLODScreenCoverage(){return this._internalMeshDataInfo._useLODScreenCoverage}set useLODScreenCoverage(e){this._internalMeshDataInfo._useLODScreenCoverage=e,this._sortLODLevels()}get computeBonesUsingShaders(){return this._internalAbstractMeshDataInfo._computeBonesUsingShaders}set computeBonesUsingShaders(e){this._internalAbstractMeshDataInfo._computeBonesUsingShaders!==e&&(e&&this._internalMeshDataInfo._sourcePositions&&(this.setVerticesData(f.o.PositionKind,this._internalMeshDataInfo._sourcePositions,!0),this._internalMeshDataInfo._sourceNormals&&this.setVerticesData(f.o.NormalKind,this._internalMeshDataInfo._sourceNormals,!0),this._internalMeshDataInfo._sourcePositions=null,this._internalMeshDataInfo._sourceNormals=null),this._internalAbstractMeshDataInfo._computeBonesUsingShaders=e,this._markSubMeshesAsAttributesDirty())}get onBeforeRenderObservable(){return this._internalMeshDataInfo._onBeforeRenderObservable||(this._internalMeshDataInfo._onBeforeRenderObservable=new n.y$),this._internalMeshDataInfo._onBeforeRenderObservable}get onBeforeBindObservable(){return this._internalMeshDataInfo._onBeforeBindObservable||(this._internalMeshDataInfo._onBeforeBindObservable=new n.y$),this._internalMeshDataInfo._onBeforeBindObservable}get onAfterRenderObservable(){return this._internalMeshDataInfo._onAfterRenderObservable||(this._internalMeshDataInfo._onAfterRenderObservable=new n.y$),this._internalMeshDataInfo._onAfterRenderObservable}get onBetweenPassObservable(){return this._internalMeshDataInfo._onBetweenPassObservable||(this._internalMeshDataInfo._onBetweenPassObservable=new n.y$),this._internalMeshDataInfo._onBetweenPassObservable}get onBeforeDrawObservable(){return this._internalMeshDataInfo._onBeforeDrawObservable||(this._internalMeshDataInfo._onBeforeDrawObservable=new n.y$),this._internalMeshDataInfo._onBeforeDrawObservable}set onBeforeDraw(e){this._onBeforeDrawObserver&&this.onBeforeDrawObservable.remove(this._onBeforeDrawObserver),this._onBeforeDrawObserver=this.onBeforeDrawObservable.add(e)}get hasInstances(){return this.instances.length>0}get hasThinInstances(){var e;return(null!==(e=this._thinInstanceDataStorage.instancesCount)&&void 0!==e?e:0)>0}get forcedInstanceCount(){return this._internalMeshDataInfo._forcedInstanceCount}set forcedInstanceCount(e){this._internalMeshDataInfo._forcedInstanceCount=e}get overrideRenderingFillMode(){return this._internalMeshDataInfo._overrideRenderingFillMode}set overrideRenderingFillMode(e){this._internalMeshDataInfo._overrideRenderingFillMode=e}get source(){return this._internalMeshDataInfo._source}get cloneMeshMap(){return this._internalMeshDataInfo.meshMap}get isUnIndexed(){return this._unIndexed}set isUnIndexed(e){this._unIndexed!==e&&(this._unIndexed=e,this._markSubMeshesAsAttributesDirty())}get worldMatrixInstancedBuffer(){return this._instanceDataStorage.instancesData}get previousWorldMatrixInstancedBuffer(){return this._instanceDataStorage.instancesPreviousData}get manualUpdateOfWorldMatrixInstancedBuffer(){return this._instanceDataStorage.manualUpdate}set manualUpdateOfWorldMatrixInstancedBuffer(e){this._instanceDataStorage.manualUpdate=e}get manualUpdateOfPreviousWorldMatrixInstancedBuffer(){return this._instanceDataStorage.previousManualUpdate}set manualUpdateOfPreviousWorldMatrixInstancedBuffer(e){this._instanceDataStorage.previousManualUpdate=e}get forceWorldMatrixInstancedBufferUpdate(){return this._instanceDataStorage.forceMatrixUpdates}set forceWorldMatrixInstancedBufferUpdate(e){this._instanceDataStorage.forceMatrixUpdates=e}constructor(e,t=null,s=null,i=null,o,h=!0){if(super(e,t),this._internalMeshDataInfo=new C,this.delayLoadState=0,this.instances=new Array,this._creationDataStorage=null,this._geometry=null,this._instanceDataStorage=new P,this._thinInstanceDataStorage=new O,this._shouldGenerateFlatShading=!1,this._originalBuilderSideOrientation=F.DEFAULTSIDE,this.overrideMaterialSideOrientation=null,this.ignoreCameraMaxZ=!1,t=this.getScene(),this._onBeforeDraw=(e,t,s)=>{e&&s&&(this._uniformBuffer?this.transferToEffect(t):s.bindOnlyWorldMatrix(t))},i){if(i._geometry&&i._geometry.applyToMesh(this),r.j.DeepCopy(i,this,["name","material","skeleton","instances","parent","uniqueId","source","metadata","morphTargetManager","hasInstances","worldMatrixInstancedBuffer","previousWorldMatrixInstancedBuffer","hasLODLevels","geometry","isBlocked","areNormalsFrozen","facetNb","isFacetDataEnabled","lightSources","useBones","isAnInstance","collider","edgesRenderer","forward","up","right","absolutePosition","absoluteScaling","absoluteRotationQuaternion","isWorldMatrixFrozen","nonUniformScaling","behaviors","worldMatrixFromCache","hasThinInstances","cloneMeshMap","hasBoundingInfo"],["_poseMatrix"]),this._internalMeshDataInfo._source=i,t.useClonedMeshMap&&(i._internalMeshDataInfo.meshMap||(i._internalMeshDataInfo.meshMap={}),i._internalMeshDataInfo.meshMap[this.uniqueId]=this),this._originalBuilderSideOrientation=i._originalBuilderSideOrientation,this._creationDataStorage=i._creationDataStorage,i._ranges){const e=i._ranges;for(const t in e)Object.prototype.hasOwnProperty.call(e,t)&&e[t]&&this.createAnimationRange(t,e[t].from,e[t].to)}if(i.metadata&&i.metadata.clone?this.metadata=i.metadata.clone():this.metadata=i.metadata,this._internalMetadata=i._internalMetadata,a.$&&a.$.HasTags(i)&&a.$.AddTagsTo(this,a.$.GetTags(i,!0)),this.setEnabled(i.isEnabled(!1)),this.parent=i.parent,this.setPivotMatrix(i.getPivotMatrix()),this.id=e+"."+i.id,this.material=i.material,!o){const t=i.getDescendants(!0);for(let s=0;s<t.length;s++){const n=t[s];n.clone&&n.clone(e+"."+n.name,this)}}if(i.morphTargetManager&&(this.morphTargetManager=i.morphTargetManager),t.getPhysicsEngine){const e=t.getPhysicsEngine();if(h&&e)if(1===e.getPluginVersion()){const t=e.getImpostorForPhysicsObject(i);t&&(this.physicsImpostor=t.clone(this))}else 2===e.getPluginVersion()&&i.physicsBody&&i.physicsBody.clone(this)}for(let e=0;e<t.particleSystems.length;e++){const s=t.particleSystems[e];s.emitter===i&&s.clone(s.name,this)}this.skeleton=i.skeleton,this.refreshBoundingInfo(!0,!0),this.computeWorldMatrix(!0)}null!==s&&(this.parent=s),this._instanceDataStorage.hardwareInstancedRendering=this.getEngine().getCaps().instancedArrays,this._internalMeshDataInfo._onMeshReadyObserverAdded=e=>{e.unregisterOnNextCall=!0,this.isReady(!0)?this.onMeshReadyObservable.notifyObservers(this):this._internalMeshDataInfo._checkReadinessObserver||(this._internalMeshDataInfo._checkReadinessObserver=this._scene.onBeforeRenderObservable.add((()=>{this.isReady(!0)&&(this._scene.onBeforeRenderObservable.remove(this._internalMeshDataInfo._checkReadinessObserver),this._internalMeshDataInfo._checkReadinessObserver=null,this.onMeshReadyObservable.notifyObservers(this))})))},this.onMeshReadyObservable=new n.y$(this._internalMeshDataInfo._onMeshReadyObserverAdded),i&&i.onClonedObservable.notifyObservers(this)}instantiateHierarchy(e=null,t,s){const n=0===this.getTotalVertices()||t&&t.doNotInstantiate&&(!0===t.doNotInstantiate||t.doNotInstantiate(this))?this.clone("Clone of "+(this.name||this.id),e||this.parent,!0):this.createInstance("instance of "+(this.name||this.id));n.parent=e||this.parent,n.position=this.position.clone(),n.scaling=this.scaling.clone(),this.rotationQuaternion?n.rotationQuaternion=this.rotationQuaternion.clone():n.rotation=this.rotation.clone(),s&&s(this,n);for(const i of this.getChildTransformNodes(!0))"InstancedMesh"===i.getClassName()&&"Mesh"===n.getClassName()&&i.sourceMesh===this?i.instantiateHierarchy(n,{doNotInstantiate:t&&t.doNotInstantiate||!1,newSourcedMesh:n},s):i.instantiateHierarchy(n,t,s);return n}getClassName(){return"Mesh"}get _isMesh(){return!0}toString(e){let t=super.toString(e);if(t+=", n vertices: "+this.getTotalVertices(),t+=", parent: "+(this._waitingParentId?this._waitingParentId:this.parent?this.parent.name:"NONE"),this.animations)for(let s=0;s<this.animations.length;s++)t+=", animation[0]: "+this.animations[s].toString(e);if(e)if(this._geometry){const e=this.getIndices(),s=this.getVerticesData(f.o.PositionKind);s&&e&&(t+=", flat shading: "+(s.length/3===e.length?"YES":"NO"))}else t+=", flat shading: UNKNOWN";return t}_unBindEffect(){super._unBindEffect();for(const e of this.instances)e._unBindEffect()}get hasLODLevels(){return this._internalMeshDataInfo._LODLevels.length>0}getLODLevels(){return this._internalMeshDataInfo._LODLevels}_sortLODLevels(){const e=this._internalMeshDataInfo._useLODScreenCoverage?-1:1;this._internalMeshDataInfo._LODLevels.sort(((t,s)=>t.distanceOrScreenCoverage<s.distanceOrScreenCoverage?e:t.distanceOrScreenCoverage>s.distanceOrScreenCoverage?-e:0))}addLODLevel(e,t){if(t&&t._masterMesh)return D.Y.Warn("You cannot use a mesh as LOD level twice"),this;const s=new B.g(e,t);return this._internalMeshDataInfo._LODLevels.push(s),t&&(t._masterMesh=this),this._sortLODLevels(),this}getLODLevelAtDistance(e){const t=this._internalMeshDataInfo;for(let s=0;s<t._LODLevels.length;s++){const n=t._LODLevels[s];if(n.distanceOrScreenCoverage===e)return n.mesh}return null}removeLODLevel(e){const t=this._internalMeshDataInfo;for(let s=0;s<t._LODLevels.length;s++)t._LODLevels[s].mesh===e&&(t._LODLevels.splice(s,1),e&&(e._masterMesh=null));return this._sortLODLevels(),this}getLOD(e,t){const s=this._internalMeshDataInfo;if(!s._LODLevels||0===s._LODLevels.length)return this;const n=t||this.getBoundingInfo().boundingSphere,i=e.mode===h.V.ORTHOGRAPHIC_CAMERA?e.minZ:n.centerWorld.subtract(e.globalPosition).length();let r=i,a=1;if(s._useLODScreenCoverage){const t=e.screenArea;let s=n.radiusWorld*e.minZ/i;s=s*s*Math.PI,r=s/t,a=-1}if(a*s._LODLevels[s._LODLevels.length-1].distanceOrScreenCoverage>a*r)return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this),this;for(let o=0;o<s._LODLevels.length;o++){const e=s._LODLevels[o];if(a*e.distanceOrScreenCoverage<a*r){if(e.mesh){if(4===e.mesh.delayLoadState)return e.mesh._checkDelayState(),this;if(2===e.mesh.delayLoadState)return this;e.mesh._preActivate(),e.mesh._updateSubMeshesBoundingInfo(this.worldMatrixFromCache)}return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,e.mesh),e.mesh}}return this.onLODLevelSelection&&this.onLODLevelSelection(r,this,this),this}get geometry(){return this._geometry}getTotalVertices(){return null===this._geometry||void 0===this._geometry?0:this._geometry.getTotalVertices()}getVerticesData(e,t,s,n){var i,r;if(!this._geometry)return null;let a=n||null===(r=null===(i=this._userInstancedBuffersStorage)||void 0===i?void 0:i.vertexBuffers[e])||void 0===r?void 0:r.getFloatData(this.instances.length+1,s||t&&1!==this._geometry.meshes.length);return a||(a=this._geometry.getVerticesData(e,t,s)),a}getVertexBuffer(e,t){var s,n;return this._geometry?null!==(n=t||null===(s=this._userInstancedBuffersStorage)||void 0===s?void 0:s.vertexBuffers[e])&&void 0!==n?n:this._geometry.getVertexBuffer(e):null}isVerticesDataPresent(e,t){var s;return this._geometry?!t&&void 0!==(null===(s=this._userInstancedBuffersStorage)||void 0===s?void 0:s.vertexBuffers[e])||this._geometry.isVerticesDataPresent(e):!!this._delayInfo&&-1!==this._delayInfo.indexOf(e)}isVertexBufferUpdatable(e,t){var s;if(!this._geometry)return!!this._delayInfo&&-1!==this._delayInfo.indexOf(e);if(!t){const t=null===(s=this._userInstancedBuffersStorage)||void 0===s?void 0:s.vertexBuffers[e];if(t)return t.isUpdatable()}return this._geometry.isVertexBufferUpdatable(e)}getVerticesDataKinds(e){if(!this._geometry){const e=new Array;return this._delayInfo&&this._delayInfo.forEach((function(t){e.push(t)})),e}const t=this._geometry.getVerticesDataKinds();if(!e&&this._userInstancedBuffersStorage)for(const s in this._userInstancedBuffersStorage.vertexBuffers)-1===t.indexOf(s)&&t.push(s);return t}getTotalIndices(){return this._geometry?this._geometry.getTotalIndices():0}getIndices(e,t){return this._geometry?this._geometry.getIndices(e,t):[]}get isBlocked(){return null!==this._masterMesh&&void 0!==this._masterMesh}isReady(e=!1,t=!1){var s,n,i,r,a,o,h;if(2===this.delayLoadState)return!1;if(!super.isReady(e))return!1;if(!this.subMeshes||0===this.subMeshes.length)return!0;if(!e)return!0;const l=this.getEngine(),c=this.getScene(),d=t||l.getCaps().instancedArrays&&(this.instances.length>0||this.hasThinInstances);this.computeWorldMatrix();const u=this.material||c.defaultMaterial;if(u)if(u._storeEffectOnSubMeshes)for(const g of this.subMeshes){const e=g.getMaterial();if(e)if(e._storeEffectOnSubMeshes){if(!e.isReadyForSubMesh(this,g,d))return!1}else if(!e.isReady(this,d))return!1}else if(!u.isReady(this,d))return!1;const f=l.currentRenderPassId;for(const g of this.lightSources){const e=g.getShadowGenerators();if(!e)continue;const t=e.values();for(let c=t.next();!0!==c.done;c=t.next()){const e=c.value;if(e&&(!(null===(s=e.getShadowMap())||void 0===s?void 0:s.renderList)||(null===(n=e.getShadowMap())||void 0===n?void 0:n.renderList)&&-1!==(null===(r=null===(i=e.getShadowMap())||void 0===i?void 0:i.renderList)||void 0===r?void 0:r.indexOf(this)))){const t=null!==(a=e.getShadowMap().renderPassIds)&&void 0!==a?a:[l.currentRenderPassId];for(let s=0;s<t.length;++s){l.currentRenderPassId=t[s];for(const t of this.subMeshes)if(!e.isReady(t,d,null!==(h=null===(o=t.getMaterial())||void 0===o?void 0:o.needAlphaBlendingForMesh(this))&&void 0!==h&&h))return l.currentRenderPassId=f,!1}l.currentRenderPassId=f}}}for(const g of this._internalMeshDataInfo._LODLevels)if(g.mesh&&!g.mesh.isReady(d))return!1;return!0}get areNormalsFrozen(){return this._internalMeshDataInfo._areNormalsFrozen}freezeNormals(){return this._internalMeshDataInfo._areNormalsFrozen=!0,this}unfreezeNormals(){return this._internalMeshDataInfo._areNormalsFrozen=!1,this}set overridenInstanceCount(e){this._instanceDataStorage.overridenInstanceCount=e}_preActivate(){const e=this._internalMeshDataInfo,t=this.getScene().getRenderId();return e._preActivateId===t||(e._preActivateId=t,this._instanceDataStorage.visibleInstances=null),this}_preActivateForIntermediateRendering(e){return this._instanceDataStorage.visibleInstances&&(this._instanceDataStorage.visibleInstances.intermediateDefaultRenderId=e),this}_registerInstanceForRenderId(e,t){return this._instanceDataStorage.visibleInstances||(this._instanceDataStorage.visibleInstances={defaultRenderId:t,selfDefaultRenderId:this._renderId}),this._instanceDataStorage.visibleInstances[t]||(void 0!==this._instanceDataStorage.previousRenderId&&this._instanceDataStorage.isFrozen&&(this._instanceDataStorage.visibleInstances[this._instanceDataStorage.previousRenderId]=null),this._instanceDataStorage.previousRenderId=t,this._instanceDataStorage.visibleInstances[t]=new Array),this._instanceDataStorage.visibleInstances[t].push(e),this}_afterComputeWorldMatrix(){super._afterComputeWorldMatrix(),this.hasThinInstances&&(this.doNotSyncBoundingInfo||this.thinInstanceRefreshBoundingInfo(!1))}_postActivate(){this.edgesShareWithInstances&&this.edgesRenderer&&this.edgesRenderer.isEnabled&&this._renderingGroup&&(this._renderingGroup._edgesRenderers.pushNoDuplicate(this.edgesRenderer),this.edgesRenderer.customInstances.push(this.getWorldMatrix()))}refreshBoundingInfo(e=!1,t=!1){if(this.hasBoundingInfo&&this.getBoundingInfo().isLocked)return this;const s=this.geometry?this.geometry.boundingBias:null;return this._refreshBoundingInfo(this._getPositionData(e,t),s),this}_createGlobalSubMesh(e){const t=this.getTotalVertices();if(!t||!this.getIndices())return null;if(this.subMeshes&&this.subMeshes.length>0){const s=this.getIndices();if(!s)return null;const n=s.length;let i=!1;if(e)i=!0;else for(const e of this.subMeshes){if(e.indexStart+e.indexCount>n){i=!0;break}if(e.verticesStart+e.verticesCount>t){i=!0;break}}if(!i)return this.subMeshes[0]}return this.releaseSubMeshes(),new I.P(0,0,t,0,this.getTotalIndices(),this)}subdivide(e){if(e<1)return;const t=this.getTotalIndices();let s=t/e|0,n=0;for(;s%3!=0;)s++;this.releaseSubMeshes();for(let i=0;i<e&&!(n>=t);i++)I.P.CreateFromIndices(0,n,i===e-1?t-n:s,this,void 0,!1),n+=s;this.refreshBoundingInfo(),this.synchronizeInstances()}setVerticesData(e,t,s=!1,n){if(this._geometry)this._geometry.setVerticesData(e,t,s,n);else{const n=new g.x;n.set(t,e);const i=this.getScene();new _.Z(_.Z.RandomId(),i,n,s,this)}return this}removeVerticesData(e){this._geometry&&this._geometry.removeVerticesData(e)}markVerticesDataAsUpdatable(e,t=!0){const s=this.getVertexBuffer(e);s&&s.isUpdatable()!==t&&this.setVerticesData(e,this.getVerticesData(e),t)}setVerticesBuffer(e,t=!0){return this._geometry||(this._geometry=_.Z.CreateGeometryForMesh(this)),this._geometry.setVerticesBuffer(e,null,t),this}updateVerticesData(e,t,s,n){return this._geometry?(n?(this.makeGeometryUnique(),this.updateVerticesData(e,t,s,!1)):this._geometry.updateVerticesData(e,t,s),this):this}updateMeshPositions(e,t=!0){const s=this.getVerticesData(f.o.PositionKind);if(!s)return this;if(e(s),this.updateVerticesData(f.o.PositionKind,s,!1,!1),t){const e=this.getIndices(),t=this.getVerticesData(f.o.NormalKind);if(!t)return this;g.x.ComputeNormals(s,e,t),this.updateVerticesData(f.o.NormalKind,t,!1,!1)}return this}makeGeometryUnique(){if(!this._geometry)return this;if(1===this._geometry.meshes.length)return this;const e=this._geometry,t=this._geometry.copy(_.Z.RandomId());return e.releaseForMesh(this,!0),t.applyToMesh(this),this}setIndices(e,t=null,s=!1){if(this._geometry)this._geometry.setIndices(e,t,s);else{const t=new g.x;t.indices=e;const n=this.getScene();new _.Z(_.Z.RandomId(),n,t,s,this)}return this}updateIndices(e,t,s=!1){return this._geometry?(this._geometry.updateIndices(e,t,s),this):this}toLeftHanded(){return this._geometry?(this._geometry.toLeftHanded(),this):this}_bind(e,t,s,n=!0){if(!this._geometry)return this;const i=this.getScene().getEngine();let r;if(this.morphTargetManager&&this.morphTargetManager.isUsingTextureForTargets&&this.morphTargetManager._bind(t),this._unIndexed)r=null;else switch(this._getRenderingFillMode(s)){case M.F.PointFillMode:r=null;break;case M.F.WireFrameFillMode:r=e._getLinesIndexBuffer(this.getIndices(),i);break;default:case M.F.TriangleFillMode:r=this._geometry.getIndexBuffer()}return n&&this._userInstancedBuffersStorage&&!this.hasThinInstances?this._geometry._bind(t,r,this._userInstancedBuffersStorage.vertexBuffers,this._userInstancedBuffersStorage.vertexArrayObjects):this._geometry._bind(t,r),this}_draw(e,t,s){if(!this._geometry||!this._geometry.getVertexBuffers()||!this._unIndexed&&!this._geometry.getIndexBuffer())return this;this._internalMeshDataInfo._onBeforeDrawObservable&&this._internalMeshDataInfo._onBeforeDrawObservable.notifyObservers(this);const n=this.getScene().getEngine();return this._unIndexed||t==M.F.PointFillMode?n.drawArraysType(t,e.verticesStart,e.verticesCount,this.forcedInstanceCount||s):t==M.F.WireFrameFillMode?n.drawElementsType(t,0,e._linesIndexCount,this.forcedInstanceCount||s):n.drawElementsType(t,e.indexStart,e.indexCount,this.forcedInstanceCount||s),this}registerBeforeRender(e){return this.onBeforeRenderObservable.add(e),this}unregisterBeforeRender(e){return this.onBeforeRenderObservable.removeCallback(e),this}registerAfterRender(e){return this.onAfterRenderObservable.add(e),this}unregisterAfterRender(e){return this.onAfterRenderObservable.removeCallback(e),this}_getInstancesRenderList(e,t=!1){if(this._instanceDataStorage.isFrozen){if(t)return this._instanceDataStorage.batchCacheReplacementModeInFrozenMode.hardwareInstancedRendering[e]=!1,this._instanceDataStorage.batchCacheReplacementModeInFrozenMode.renderSelf[e]=!0,this._instanceDataStorage.batchCacheReplacementModeInFrozenMode;if(this._instanceDataStorage.previousBatch)return this._instanceDataStorage.previousBatch}const s=this.getScene(),n=s._isInIntermediateRendering(),i=n?this._internalAbstractMeshDataInfo._onlyForInstancesIntermediate:this._internalAbstractMeshDataInfo._onlyForInstances,r=this._instanceDataStorage.batchCache;if(r.mustReturn=!1,r.renderSelf[e]=t||!i&&this.isEnabled()&&this.isVisible,r.visibleInstances[e]=null,this._instanceDataStorage.visibleInstances&&!t){const t=this._instanceDataStorage.visibleInstances,i=s.getRenderId(),a=n?t.intermediateDefaultRenderId:t.defaultRenderId;r.visibleInstances[e]=t[i],!r.visibleInstances[e]&&a&&(r.visibleInstances[e]=t[a])}return r.hardwareInstancedRendering[e]=!t&&this._instanceDataStorage.hardwareInstancedRendering&&null!==r.visibleInstances[e]&&void 0!==r.visibleInstances[e],this._instanceDataStorage.previousBatch=r,r}_renderWithInstances(e,t,s,n,i){var r;const a=s.visibleInstances[e._id],o=a?a.length:0,h=this._instanceDataStorage,l=h.instancesBufferSize;let d=h.instancesBuffer,u=h.instancesPreviousBuffer;const g=16*(o+1)*4;for(;h.instancesBufferSize<g;)h.instancesBufferSize*=2;h.instancesData&&l==h.instancesBufferSize||(h.instancesData=new Float32Array(h.instancesBufferSize/4)),(this._scene.needsPreviousWorldMatrices&&!h.instancesPreviousData||l!=h.instancesBufferSize)&&(h.instancesPreviousData=new Float32Array(h.instancesBufferSize/4));let _=0,m=0;const I=s.renderSelf[e._id],M=!d||l!==h.instancesBufferSize||this._scene.needsPreviousWorldMatrices&&!h.instancesPreviousBuffer;if(this._instanceDataStorage.manualUpdate||h.isFrozen&&!M)m=(I?1:0)+o;else{const t=this.getWorldMatrix();if(I&&(this._scene.needsPreviousWorldMatrices&&(h.masterMeshPreviousWorldMatrix?(h.masterMeshPreviousWorldMatrix.copyToArray(h.instancesPreviousData,_),h.masterMeshPreviousWorldMatrix.copyFrom(t)):(h.masterMeshPreviousWorldMatrix=t.clone(),h.masterMeshPreviousWorldMatrix.copyToArray(h.instancesPreviousData,_))),t.copyToArray(h.instancesData,_),_+=16,m++),a){if(F.INSTANCEDMESH_SORT_TRANSPARENT&&this._scene.activeCamera&&(null===(r=e.getMaterial())||void 0===r?void 0:r.needAlphaBlendingForMesh(e.getRenderingMesh()))){const e=this._scene.activeCamera.globalPosition;for(let t=0;t<a.length;t++){const s=a[t];s._distanceToCamera=c.P.Distance(s.getBoundingInfo().boundingSphere.centerWorld,e)}a.sort(((e,t)=>e._distanceToCamera>t._distanceToCamera?-1:e._distanceToCamera<t._distanceToCamera?1:0))}for(let e=0;e<a.length;e++){const t=a[e],s=t.getWorldMatrix();s.copyToArray(h.instancesData,_),this._scene.needsPreviousWorldMatrices&&(t._previousWorldMatrix?(t._previousWorldMatrix.copyToArray(h.instancesPreviousData,_),t._previousWorldMatrix.copyFrom(s)):(t._previousWorldMatrix=s.clone(),t._previousWorldMatrix.copyToArray(h.instancesPreviousData,_))),_+=16,m++}}}return M?(d&&d.dispose(),u&&u.dispose(),d=new f.l(i,h.instancesData,!0,16,!1,!0),h.instancesBuffer=d,this._userInstancedBuffersStorage||(this._userInstancedBuffersStorage={data:{},vertexBuffers:{},strides:{},sizes:{},vertexArrayObjects:this.getEngine().getCaps().vertexArrayObject?{}:void 0}),this._userInstancedBuffersStorage.vertexBuffers.world0=d.createVertexBuffer("world0",0,4),this._userInstancedBuffersStorage.vertexBuffers.world1=d.createVertexBuffer("world1",4,4),this._userInstancedBuffersStorage.vertexBuffers.world2=d.createVertexBuffer("world2",8,4),this._userInstancedBuffersStorage.vertexBuffers.world3=d.createVertexBuffer("world3",12,4),this._scene.needsPreviousWorldMatrices&&(u=new f.l(i,h.instancesPreviousData,!0,16,!1,!0),h.instancesPreviousBuffer=u,this._userInstancedBuffersStorage.vertexBuffers.previousWorld0=u.createVertexBuffer("previousWorld0",0,4),this._userInstancedBuffersStorage.vertexBuffers.previousWorld1=u.createVertexBuffer("previousWorld1",4,4),this._userInstancedBuffersStorage.vertexBuffers.previousWorld2=u.createVertexBuffer("previousWorld2",8,4),this._userInstancedBuffersStorage.vertexBuffers.previousWorld3=u.createVertexBuffer("previousWorld3",12,4)),this._invalidateInstanceVertexArrayObject()):this._instanceDataStorage.isFrozen&&!this._instanceDataStorage.forceMatrixUpdates||(d.updateDirectly(h.instancesData,0,m),!this._scene.needsPreviousWorldMatrices||this._instanceDataStorage.manualUpdate&&!this._instanceDataStorage.previousManualUpdate||u.updateDirectly(h.instancesPreviousData,0,m)),this._processInstancedBuffers(a,I),this.getScene()._activeIndices.addCount(e.indexCount*m,!1),i._currentDrawContext&&(i._currentDrawContext.useInstancing=!0),this._bind(e,n,t),this._draw(e,t,m),!this._scene.needsPreviousWorldMatrices||M||!this._instanceDataStorage.manualUpdate||this._instanceDataStorage.isFrozen&&!this._instanceDataStorage.forceMatrixUpdates||this._instanceDataStorage.previousManualUpdate||u.updateDirectly(h.instancesData,0,m),i.unbindInstanceAttributes(),this}_renderWithThinInstances(e,t,s,n){var i,r;const a=null!==(r=null===(i=this._thinInstanceDataStorage)||void 0===i?void 0:i.instancesCount)&&void 0!==r?r:0;this.getScene()._activeIndices.addCount(e.indexCount*a,!1),n._currentDrawContext&&(n._currentDrawContext.useInstancing=!0),this._bind(e,s,t),this._draw(e,t,a),this._scene.needsPreviousWorldMatrices&&!this._thinInstanceDataStorage.previousMatrixData&&this._thinInstanceDataStorage.matrixData&&(this._thinInstanceDataStorage.previousMatrixBuffer?this._thinInstanceDataStorage.previousMatrixBuffer.updateDirectly(this._thinInstanceDataStorage.matrixData,0,a):this._thinInstanceDataStorage.previousMatrixBuffer=this._thinInstanceCreateMatrixBuffer("previousWorld",this._thinInstanceDataStorage.matrixData,!1)),n.unbindInstanceAttributes()}_processInstancedBuffers(e,t){}_processRendering(e,t,s,n,i,r,a,o){const h=this.getScene(),l=h.getEngine();if(n=this._getRenderingFillMode(n),r&&t.getRenderingMesh().hasThinInstances)return this._renderWithThinInstances(t,n,s,l),this;if(r)this._renderWithInstances(t,n,i,s,l);else{l._currentDrawContext&&(l._currentDrawContext.useInstancing=!1);let s=0;i.renderSelf[t._id]&&(a&&a(!1,e.getWorldMatrix(),o),s++,this._draw(t,n,this._instanceDataStorage.overridenInstanceCount));const r=i.visibleInstances[t._id];if(r){const e=r.length;s+=e;for(let s=0;s<e;s++){const e=r[s].getWorldMatrix();a&&a(!0,e,o),this._draw(t,n)}}h._activeIndices.addCount(t.indexCount*s,!1)}return this}_rebuild(e=!1){if(this._instanceDataStorage.instancesBuffer&&(e&&this._instanceDataStorage.instancesBuffer.dispose(),this._instanceDataStorage.instancesBuffer=null),this._userInstancedBuffersStorage){for(const t in this._userInstancedBuffersStorage.vertexBuffers){const s=this._userInstancedBuffersStorage.vertexBuffers[t];s&&(e&&s.dispose(),this._userInstancedBuffersStorage.vertexBuffers[t]=null)}this._userInstancedBuffersStorage.vertexArrayObjects&&(this._userInstancedBuffersStorage.vertexArrayObjects={})}this._internalMeshDataInfo._effectiveMaterial=null,super._rebuild(e)}_freeze(){if(this.subMeshes){for(let e=0;e<this.subMeshes.length;e++)this._getInstancesRenderList(e);this._internalMeshDataInfo._effectiveMaterial=null,this._instanceDataStorage.isFrozen=!0}}_unFreeze(){this._instanceDataStorage.isFrozen=!1,this._instanceDataStorage.previousBatch=null}render(e,t,s){var n,i,r;const a=this.getScene();if(this._internalAbstractMeshDataInfo._isActiveIntermediate?this._internalAbstractMeshDataInfo._isActiveIntermediate=!1:this._internalAbstractMeshDataInfo._isActive=!1,this._checkOcclusionQuery()&&!this._occlusionDataStorage.forceRenderingWhenOccluded)return this;const o=this._getInstancesRenderList(e._id,!!s);if(o.mustReturn)return this;if(!this._geometry||!this._geometry.getVertexBuffers()||!this._unIndexed&&!this._geometry.getIndexBuffer())return this;const h=a.getEngine();let c=0,d=null;this.ignoreCameraMaxZ&&a.activeCamera&&!a._isInIntermediateRendering()&&(c=a.activeCamera.maxZ,d=a.activeCamera,a.activeCamera.maxZ=0,a.updateTransformMatrix(!0)),this._internalMeshDataInfo._onBeforeRenderObservable&&this._internalMeshDataInfo._onBeforeRenderObservable.notifyObservers(this);const u=e.getRenderingMesh(),f=o.hardwareInstancedRendering[e._id]||u.hasThinInstances||!!this._userInstancedBuffersStorage&&!e.getMesh()._internalAbstractMeshDataInfo._actAsRegularMesh,g=this._instanceDataStorage,_=e.getMaterial();if(!_)return d&&(d.maxZ=c,a.updateTransformMatrix(!0)),this;if(g.isFrozen&&this._internalMeshDataInfo._effectiveMaterial&&this._internalMeshDataInfo._effectiveMaterial===_){if(_._storeEffectOnSubMeshes&&!(null===(n=e.effect)||void 0===n?void 0:n._wasPreviouslyReady)||!_._storeEffectOnSubMeshes&&!(null===(i=_.getEffect())||void 0===i?void 0:i._wasPreviouslyReady))return d&&(d.maxZ=c,a.updateTransformMatrix(!0)),this}else{if(_._storeEffectOnSubMeshes){if(!_.isReadyForSubMesh(this,e,f))return d&&(d.maxZ=c,a.updateTransformMatrix(!0)),this}else if(!_.isReady(this,f))return d&&(d.maxZ=c,a.updateTransformMatrix(!0)),this;this._internalMeshDataInfo._effectiveMaterial=_}let m;t&&h.setAlphaMode(this._internalMeshDataInfo._effectiveMaterial.alphaMode),m=this._internalMeshDataInfo._effectiveMaterial._storeEffectOnSubMeshes?e._drawWrapper:this._internalMeshDataInfo._effectiveMaterial._getDrawWrapper();const I=null!==(r=null==m?void 0:m.effect)&&void 0!==r?r:null;for(const l of a._beforeRenderingMeshStage)l.action(this,e,o,I);if(!m||!I)return d&&(d.maxZ=c,a.updateTransformMatrix(!0)),this;const p=s||this;let v;if(g.isFrozen||!this._internalMeshDataInfo._effectiveMaterial.backFaceCulling&&null===this.overrideMaterialSideOrientation)v=g.sideOrientation;else{const e=p._getWorldMatrixDeterminant();v=this.overrideMaterialSideOrientation,null==v&&(v=this._internalMeshDataInfo._effectiveMaterial.sideOrientation),e<0&&(v=v===M.F.ClockWiseSideOrientation?M.F.CounterClockWiseSideOrientation:M.F.ClockWiseSideOrientation),g.sideOrientation=v}const y=this._internalMeshDataInfo._effectiveMaterial._preBind(m,v);this._internalMeshDataInfo._effectiveMaterial.forceDepthWrite&&h.setDepthWrite(!0);const D=this._internalMeshDataInfo._effectiveMaterial,b=D.fillMode;this._internalMeshDataInfo._onBeforeBindObservable&&this._internalMeshDataInfo._onBeforeBindObservable.notifyObservers(this),f||this._bind(e,I,b,!1);const S=p.getWorldMatrix();D._storeEffectOnSubMeshes?D.bindForSubMesh(S,this,e):D.bind(S,this),!D.backFaceCulling&&D.separateCullingPass&&(h.setState(!0,D.zOffset,!1,!y,D.cullBackFaces,D.stencil,D.zOffsetUnits),this._processRendering(this,e,I,b,o,f,this._onBeforeDraw,this._internalMeshDataInfo._effectiveMaterial),h.setState(!0,D.zOffset,!1,y,D.cullBackFaces,D.stencil,D.zOffsetUnits),this._internalMeshDataInfo._onBetweenPassObservable&&this._internalMeshDataInfo._onBetweenPassObservable.notifyObservers(e)),this._processRendering(this,e,I,b,o,f,this._onBeforeDraw,this._internalMeshDataInfo._effectiveMaterial),this._internalMeshDataInfo._effectiveMaterial.unbind();for(const l of a._afterRenderingMeshStage)l.action(this,e,o,I);return this._internalMeshDataInfo._onAfterRenderObservable&&this._internalMeshDataInfo._onAfterRenderObservable.notifyObservers(this),d&&(d.maxZ=c,a.updateTransformMatrix(!0)),a.performancePriority!==l.a.Aggressive||g.isFrozen||this._freeze(),this}cleanMatrixWeights(){this.isVerticesDataPresent(f.o.MatricesWeightsKind)&&(this.isVerticesDataPresent(f.o.MatricesWeightsExtraKind)?this._normalizeSkinWeightsAndExtra():this._normalizeSkinFourWeights())}_normalizeSkinFourWeights(){const e=this.getVerticesData(f.o.MatricesWeightsKind),t=e.length;for(let s=0;s<t;s+=4){const t=e[s]+e[s+1]+e[s+2]+e[s+3];if(0===t)e[s]=1;else{const n=1/t;e[s]*=n,e[s+1]*=n,e[s+2]*=n,e[s+3]*=n}}this.setVerticesData(f.o.MatricesWeightsKind,e)}_normalizeSkinWeightsAndExtra(){const e=this.getVerticesData(f.o.MatricesWeightsExtraKind),t=this.getVerticesData(f.o.MatricesWeightsKind),s=t.length;for(let n=0;n<s;n+=4){let s=t[n]+t[n+1]+t[n+2]+t[n+3];if(s+=e[n]+e[n+1]+e[n+2]+e[n+3],0===s)t[n]=1;else{const i=1/s;t[n]*=i,t[n+1]*=i,t[n+2]*=i,t[n+3]*=i,e[n]*=i,e[n+1]*=i,e[n+2]*=i,e[n+3]*=i}}this.setVerticesData(f.o.MatricesWeightsKind,t),this.setVerticesData(f.o.MatricesWeightsKind,e)}validateSkinning(){const e=this.getVerticesData(f.o.MatricesWeightsExtraKind),t=this.getVerticesData(f.o.MatricesWeightsKind);if(null===t||null==this.skeleton)return{skinned:!1,valid:!0,report:"not skinned"};const s=t.length;let n=0,i=0,r=0,a=0;const o=null===e?4:8,h=new Array;for(let f=0;f<=o;f++)h[f]=0;for(let f=0;f<s;f+=4){let s=t[f],l=s,c=0===l?0:1;for(let i=1;i<o;i++){const r=i<4?t[f+i]:e[f+i-4];r>s&&n++,0!==r&&c++,l+=r,s=r}if(h[c]++,c>r&&(r=c),0===l)i++;else{const s=1/l;let n=0;for(let i=0;i<o;i++)n+=i<4?Math.abs(t[f+i]-t[f+i]*s):Math.abs(e[f+i-4]-e[f+i-4]*s);n>.001&&a++}}const l=this.skeleton.bones.length,c=this.getVerticesData(f.o.MatricesIndicesKind),d=this.getVerticesData(f.o.MatricesIndicesExtraKind);let u=0;for(let f=0;f<s;f+=4)for(let e=0;e<o;e++){const t=e<4?c[f+e]:d[f+e-4];(t>=l||t<0)&&u++}return{skinned:!0,valid:0===i&&0===a&&0===u,report:"Number of Weights = "+s/4+"\nMaximum influences = "+r+"\nMissing Weights = "+i+"\nNot Sorted = "+n+"\nNot Normalized = "+a+"\nWeightCounts = ["+h+"]\nNumber of bones = "+l+"\nBad Bone Indices = "+u}}_checkDelayState(){const e=this.getScene();return this._geometry?this._geometry.load(e):4===this.delayLoadState&&(this.delayLoadState=2,this._queueLoad(e)),this}_queueLoad(e){e.addPendingData(this);const t=-1!==this.delayLoadingFile.indexOf(".babylonbinarymeshdata");return i.w1.LoadFile(this.delayLoadingFile,(t=>{t instanceof ArrayBuffer?this._delayLoadingFunction(t,this):this._delayLoadingFunction(JSON.parse(t),this),this.instances.forEach((e=>{e.refreshBoundingInfo(),e._syncSubMeshes()})),this.delayLoadState=1,e.removePendingData(this)}),(()=>{}),e.offlineProvider,t),this}isInFrustum(e){return 2!==this.delayLoadState&&(!!super.isInFrustum(e)&&(this._checkDelayState(),!0))}setMaterialById(e){const t=this.getScene().materials;let s;for(s=t.length-1;s>-1;s--)if(t[s].id===e)return this.material=t[s],this;const n=this.getScene().multiMaterials;for(s=n.length-1;s>-1;s--)if(n[s].id===e)return this.material=n[s],this;return this}getAnimatables(){const e=new Array;return this.material&&e.push(this.material),this.skeleton&&e.push(this.skeleton),e}bakeTransformIntoVertices(e){if(!this.isVerticesDataPresent(f.o.PositionKind))return this;const t=this.subMeshes.splice(0);this._resetPointsArrayCache();let s=this.getVerticesData(f.o.PositionKind);const n=c.P.Zero();let i;for(i=0;i<s.length;i+=3)c.P.TransformCoordinatesFromFloatsToRef(s[i],s[i+1],s[i+2],e,n).toArray(s,i);if(this.setVerticesData(f.o.PositionKind,s,this.getVertexBuffer(f.o.PositionKind).isUpdatable()),this.isVerticesDataPresent(f.o.NormalKind)){for(s=this.getVerticesData(f.o.NormalKind),i=0;i<s.length;i+=3)c.P.TransformNormalFromFloatsToRef(s[i],s[i+1],s[i+2],e,n).normalize().toArray(s,i);this.setVerticesData(f.o.NormalKind,s,this.getVertexBuffer(f.o.NormalKind).isUpdatable())}return e.determinant()<0&&this.flipFaces(),this.releaseSubMeshes(),this.subMeshes=t,this}bakeCurrentTransformIntoVertices(e=!0){return this.bakeTransformIntoVertices(this.computeWorldMatrix(!0)),this.resetLocalMatrix(e),this}get _positions(){return this._internalAbstractMeshDataInfo._positions?this._internalAbstractMeshDataInfo._positions:this._geometry?this._geometry._positions:null}_resetPointsArrayCache(){return this._geometry&&this._geometry._resetPointsArrayCache(),this}_generatePointsArray(){return!!this._geometry&&this._geometry._generatePointsArray()}clone(e="",t=null,s,n=!0){return new F(e,this.getScene(),t,this,s,n)}dispose(e,t=!1){this.morphTargetManager=null,this._geometry&&this._geometry.releaseForMesh(this,!0);const s=this._internalMeshDataInfo;if(s._onBeforeDrawObservable&&s._onBeforeDrawObservable.clear(),s._onBeforeBindObservable&&s._onBeforeBindObservable.clear(),s._onBeforeRenderObservable&&s._onBeforeRenderObservable.clear(),s._onAfterRenderObservable&&s._onAfterRenderObservable.clear(),s._onBetweenPassObservable&&s._onBetweenPassObservable.clear(),this._scene.useClonedMeshMap){if(s.meshMap)for(const e in s.meshMap){const t=s.meshMap[e];t&&(t._internalMeshDataInfo._source=null,s.meshMap[e]=void 0)}s._source&&s._source._internalMeshDataInfo.meshMap&&(s._source._internalMeshDataInfo.meshMap[this.uniqueId]=void 0)}else{const e=this.getScene().meshes;for(const t of e){const e=t;e._internalMeshDataInfo&&e._internalMeshDataInfo._source&&e._internalMeshDataInfo._source===this&&(e._internalMeshDataInfo._source=null)}}s._source=null,this._instanceDataStorage.visibleInstances={},this._disposeInstanceSpecificData(),this._disposeThinInstanceSpecificData(),this._internalMeshDataInfo._checkReadinessObserver&&this._scene.onBeforeRenderObservable.remove(this._internalMeshDataInfo._checkReadinessObserver),super.dispose(e,t)}_disposeInstanceSpecificData(){}_disposeThinInstanceSpecificData(){}_invalidateInstanceVertexArrayObject(){}applyDisplacementMap(e,t,s,n,r,a,o=!1){const h=this.getScene();return i.w1.LoadImage(e,(e=>{const i=e.width,h=e.height,l=this.getEngine().createCanvas(i,h).getContext("2d");l.drawImage(e,0,0);const c=l.getImageData(0,0,i,h).data;this.applyDisplacementMapFromBuffer(c,i,h,t,s,r,a,o),n&&n(this)}),(()=>{}),h.offlineProvider),this}applyDisplacementMapFromBuffer(e,t,s,n,i,r,a,o=!1){if(!this.isVerticesDataPresent(f.o.PositionKind)||!this.isVerticesDataPresent(f.o.NormalKind)||!this.isVerticesDataPresent(f.o.UVKind))return D.Y.Warn("Cannot call applyDisplacementMap: Given mesh is not complete. Position, Normal or UV are missing"),this;const h=this.getVerticesData(f.o.PositionKind,!0,!0),l=this.getVerticesData(f.o.NormalKind),d=this.getVerticesData(f.o.UVKind);let u=c.P.Zero();const _=c.P.Zero(),m=c.FM.Zero();r=r||c.FM.Zero(),a=a||new c.FM(1,1);for(let f=0;f<h.length;f+=3){c.P.FromArrayToRef(h,f,u),c.P.FromArrayToRef(l,f,_),c.FM.FromArrayToRef(d,f/3*2,m);const o=4*((Math.abs(m.x*a.x+r.x%1)*(t-1)%t|0)+(Math.abs(m.y*a.y+r.y%1)*(s-1)%s|0)*t),g=.3*(e[o]/255)+.59*(e[o+1]/255)+.11*(e[o+2]/255);_.normalize(),_.scaleInPlace(n+(i-n)*g),u=u.add(_),u.toArray(h,f)}return g.x.ComputeNormals(h,this.getIndices(),l),o?(this.setVerticesData(f.o.PositionKind,h),this.setVerticesData(f.o.NormalKind,l),this.setVerticesData(f.o.UVKind,d)):(this.updateVerticesData(f.o.PositionKind,h),this.updateVerticesData(f.o.NormalKind,l)),this}_getFlattenedNormals(e,t){const s=new Float32Array(3*e.length);let n=0;const i=this.overrideMaterialSideOrientation===(this._scene.useRightHandedSystem?1:0);for(let r=0;r<e.length;r+=3){const a=c.P.FromArray(t,3*e[r]),o=c.P.FromArray(t,3*e[r+1]),h=c.P.FromArray(t,3*e[r+2]),l=a.subtract(o),d=h.subtract(o),u=c.P.Normalize(c.P.Cross(l,d));i&&u.scaleInPlace(-1);for(let e=0;e<3;e++)s[n++]=u.x,s[n++]=u.y,s[n++]=u.z}return s}_convertToUnIndexedMesh(e=!1){const t=this.getVerticesDataKinds(),s=this.getIndices(),n={},i=(e,t)=>{const n=new Float32Array(s.length*t);let i=0;for(let r=0;r<s.length;r++)for(let a=0;a<t;a++)n[i++]=e[s[r]*t+a];return n},r=this.geometry?this.subMeshes.slice(0):[];for(const a of t)n[a]=this.getVerticesData(a);for(const a of t){const t=this.getVertexBuffer(a),r=t.getStrideSize();if(e&&a===f.o.NormalKind){const e=this._getFlattenedNormals(s,n[f.o.PositionKind]);this.setVerticesData(f.o.NormalKind,e,t.isUpdatable(),r)}else this.setVerticesData(a,i(n[a],r),t.isUpdatable(),r)}if(this.morphTargetManager){for(let t=0;t<this.morphTargetManager.numTargets;t++){const n=this.morphTargetManager.getTarget(t),r=n.getPositions();n.setPositions(i(r,3));const a=n.getNormals();a&&n.setNormals(e?this._getFlattenedNormals(s,r):i(a,3));const o=n.getTangents();o&&n.setTangents(i(o,3));const h=n.getUVs();h&&n.setUVs(i(h,2))}this.morphTargetManager.synchronize()}for(let a=0;a<s.length;a++)s[a]=a;this.setIndices(s),this._unIndexed=!0,this.releaseSubMeshes();for(const a of r)I.P.AddToMesh(a.materialIndex,a.indexStart,a.indexCount,a.indexStart,a.indexCount,this);return this.synchronizeInstances(),this}convertToFlatShadedMesh(){return this._convertToUnIndexedMesh(!0)}convertToUnIndexedMesh(){return this._convertToUnIndexedMesh()}flipFaces(e=!1){const t=g.x.ExtractFromMesh(this);let s;if(e&&this.isVerticesDataPresent(f.o.NormalKind)&&t.normals)for(s=0;s<t.normals.length;s++)t.normals[s]*=-1;if(t.indices){let e;for(s=0;s<t.indices.length;s+=3)e=t.indices[s+1],t.indices[s+1]=t.indices[s+2],t.indices[s+2]=e}return t.applyToMesh(this,this.isVertexBufferUpdatable(f.o.PositionKind)),this}increaseVertices(e=1){const t=g.x.ExtractFromMesh(this),s=t.indices&&!Array.isArray(t.indices)&&Array.from?Array.from(t.indices):t.indices,n=t.positions&&!Array.isArray(t.positions)&&Array.from?Array.from(t.positions):t.positions,i=t.uvs&&!Array.isArray(t.uvs)&&Array.from?Array.from(t.uvs):t.uvs,r=t.normals&&!Array.isArray(t.normals)&&Array.from?Array.from(t.normals):t.normals;if(s&&n){t.indices=s,t.positions=n,i&&(t.uvs=i),r&&(t.normals=r);const a=e+1,o=new Array;for(let e=0;e<a+1;e++)o[e]=new Array;let h,l;const d=new c.P(0,0,0),u=new c.P(0,0,0),g=new c.FM(0,0),_=new Array,m=new Array,I=new Array;let M,p,v,y=n.length;i&&(p=i.length),r&&(v=r.length);for(let e=0;e<s.length;e+=3){m[0]=s[e],m[1]=s[e+1],m[2]=s[e+2];for(let e=0;e<3;e++)if(h=m[e],l=m[(e+1)%3],void 0===I[h]&&void 0===I[l]?(I[h]=new Array,I[l]=new Array):(void 0===I[h]&&(I[h]=new Array),void 0===I[l]&&(I[l]=new Array)),void 0===I[h][l]&&void 0===I[l][h]){I[h][l]=[],d.x=(n[3*l]-n[3*h])/a,d.y=(n[3*l+1]-n[3*h+1])/a,d.z=(n[3*l+2]-n[3*h+2])/a,r&&(u.x=(r[3*l]-r[3*h])/a,u.y=(r[3*l+1]-r[3*h+1])/a,u.z=(r[3*l+2]-r[3*h+2])/a),i&&(g.x=(i[2*l]-i[2*h])/a,g.y=(i[2*l+1]-i[2*h+1])/a),I[h][l].push(h);for(let e=1;e<a;e++)I[h][l].push(n.length/3),n[y++]=n[3*h]+e*d.x,n[y++]=n[3*h+1]+e*d.y,n[y++]=n[3*h+2]+e*d.z,r&&(r[v++]=r[3*h]+e*u.x,r[v++]=r[3*h+1]+e*u.y,r[v++]=r[3*h+2]+e*u.z),i&&(i[p++]=i[2*h]+e*g.x,i[p++]=i[2*h+1]+e*g.y);I[h][l].push(l),I[l][h]=new Array,M=I[h][l].length;for(let e=0;e<M;e++)I[l][h][e]=I[h][l][M-1-e]}o[0][0]=s[e],o[1][0]=I[s[e]][s[e+1]][1],o[1][1]=I[s[e]][s[e+2]][1];for(let t=2;t<a;t++){o[t][0]=I[s[e]][s[e+1]][t],o[t][t]=I[s[e]][s[e+2]][t],d.x=(n[3*o[t][t]]-n[3*o[t][0]])/t,d.y=(n[3*o[t][t]+1]-n[3*o[t][0]+1])/t,d.z=(n[3*o[t][t]+2]-n[3*o[t][0]+2])/t,r&&(u.x=(r[3*o[t][t]]-r[3*o[t][0]])/t,u.y=(r[3*o[t][t]+1]-r[3*o[t][0]+1])/t,u.z=(r[3*o[t][t]+2]-r[3*o[t][0]+2])/t),i&&(g.x=(i[2*o[t][t]]-i[2*o[t][0]])/t,g.y=(i[2*o[t][t]+1]-i[2*o[t][0]+1])/t);for(let e=1;e<t;e++)o[t][e]=n.length/3,n[y++]=n[3*o[t][0]]+e*d.x,n[y++]=n[3*o[t][0]+1]+e*d.y,n[y++]=n[3*o[t][0]+2]+e*d.z,r&&(r[v++]=r[3*o[t][0]]+e*u.x,r[v++]=r[3*o[t][0]+1]+e*u.y,r[v++]=r[3*o[t][0]+2]+e*u.z),i&&(i[p++]=i[2*o[t][0]]+e*g.x,i[p++]=i[2*o[t][0]+1]+e*g.y)}o[a]=I[s[e+1]][s[e+2]],_.push(o[0][0],o[1][0],o[1][1]);for(let e=1;e<a;e++){let t;for(t=0;t<e;t++)_.push(o[e][t],o[e+1][t],o[e+1][t+1]),_.push(o[e][t],o[e+1][t+1],o[e][t+1]);_.push(o[e][t],o[e+1][t],o[e+1][t+1])}}t.indices=_,t.applyToMesh(this,this.isVertexBufferUpdatable(f.o.PositionKind))}else D.Y.Warn("Couldn't increase number of vertices : VertexData must contain at least indices and positions")}forceSharedVertices(){const e=g.x.ExtractFromMesh(this),t=e.uvs,s=e.indices,n=e.positions,i=e.colors,r=e.matricesIndices,a=e.matricesWeights,o=e.matricesIndicesExtra,h=e.matricesWeightsExtra;if(void 0===s||void 0===n||null===s||null===n)D.Y.Warn("VertexData contains empty entries");else{const l=new Array,c=new Array,d=new Array,u=new Array,_=new Array,m=new Array,I=new Array,M=new Array;let p=new Array,v=0;const y={};let D,b;for(let e=0;e<s.length;e+=3){b=[s[e],s[e+1],s[e+2]],p=new Array;for(let e=0;e<3;e++){p[e]="";for(let t=0;t<3;t++)Math.abs(n[3*b[e]+t])<1e-8&&(n[3*b[e]+t]=0),p[e]+=n[3*b[e]+t]+"|"}if(p[0]!=p[1]&&p[0]!=p[2]&&p[1]!=p[2])for(let e=0;e<3;e++){if(D=y[p[e]],void 0===D){y[p[e]]=v,D=v++;for(let t=0;t<3;t++)l.push(n[3*b[e]+t]);if(null!=i)for(let t=0;t<4;t++)u.push(i[4*b[e]+t]);if(null!=t)for(let s=0;s<2;s++)d.push(t[2*b[e]+s]);if(null!=r)for(let t=0;t<4;t++)_.push(r[4*b[e]+t]);if(null!=a)for(let t=0;t<4;t++)m.push(a[4*b[e]+t]);if(null!=o)for(let t=0;t<4;t++)I.push(o[4*b[e]+t]);if(null!=h)for(let t=0;t<4;t++)M.push(h[4*b[e]+t])}c.push(D)}}const S=new Array;g.x.ComputeNormals(l,c,S),e.positions=l,e.indices=c,e.normals=S,null!=t&&(e.uvs=d),null!=i&&(e.colors=u),null!=r&&(e.matricesIndices=_),null!=a&&(e.matricesWeights=m),null!=o&&(e.matricesIndicesExtra=I),null!=a&&(e.matricesWeightsExtra=M),e.applyToMesh(this,this.isVertexBufferUpdatable(f.o.PositionKind))}}static _instancedMeshFactory(e,t){throw(0,S.S)("InstancedMesh")}static _PhysicsImpostorParser(e,t,s){throw(0,S.S)("PhysicsImpostor")}createInstance(e){return F._instancedMeshFactory(e,this)}synchronizeInstances(){for(let e=0;e<this.instances.length;e++){this.instances[e]._syncSubMeshes()}return this}optimizeIndices(e){const t=this.getIndices(),s=this.getVerticesData(f.o.PositionKind);if(!s||!t)return this;const n=new Array;for(let i=0;i<s.length;i+=3)n.push(c.P.FromArray(s,i));const r=new Array;return i.$g.SyncAsyncForLoop(n.length,40,(e=>{const t=n.length-1-e,s=n[t];for(let i=0;i<t;++i){const e=n[i];if(s.equals(e)){r[t]=i;break}}}),(()=>{for(let e=0;e<t.length;++e)t[e]=r[t[e]]||t[e];const s=this.subMeshes.slice(0);this.setIndices(t),this.subMeshes=s,e&&e(this)})),this}serialize(e={}){e.name=this.name,e.id=this.id,e.uniqueId=this.uniqueId,e.type=this.getClassName(),a.$&&a.$.HasTags(this)&&(e.tags=a.$.GetTags(this)),e.position=this.position.asArray(),this.rotationQuaternion?e.rotationQuaternion=this.rotationQuaternion.asArray():this.rotation&&(e.rotation=this.rotation.asArray()),e.scaling=this.scaling.asArray(),this._postMultiplyPivotMatrix?e.pivotMatrix=this.getPivotMatrix().asArray():e.localMatrix=this.getPivotMatrix().asArray(),e.isEnabled=this.isEnabled(!1),e.isVisible=this.isVisible,e.infiniteDistance=this.infiniteDistance,e.pickable=this.isPickable,e.receiveShadows=this.receiveShadows,e.billboardMode=this.billboardMode,e.visibility=this.visibility,e.checkCollisions=this.checkCollisions,e.isBlocker=this.isBlocker,e.overrideMaterialSideOrientation=this.overrideMaterialSideOrientation,this.parent&&this.parent._serializeAsParent(e),e.isUnIndexed=this.isUnIndexed;const t=this._geometry;if(t&&this.subMeshes){e.geometryUniqueId=t.uniqueId,e.geometryId=t.id,e.subMeshes=[];for(let t=0;t<this.subMeshes.length;t++){const s=this.subMeshes[t];e.subMeshes.push({materialIndex:s.materialIndex,verticesStart:s.verticesStart,verticesCount:s.verticesCount,indexStart:s.indexStart,indexCount:s.indexCount})}}if(this.material?this.material.doNotSerialize||(e.materialUniqueId=this.material.uniqueId,e.materialId=this.material.id):(this.material=null,e.materialUniqueId=this._scene.defaultMaterial.uniqueId,e.materialId=this._scene.defaultMaterial.id),this.morphTargetManager&&(e.morphTargetManagerId=this.morphTargetManager.uniqueId),this.skeleton&&(e.skeletonId=this.skeleton.id,e.numBoneInfluencers=this.numBoneInfluencers),this.getScene()._getComponent(x.l.NAME_PHYSICSENGINE)){const t=this.getPhysicsImpostor();t&&(e.physicsMass=t.getParam("mass"),e.physicsFriction=t.getParam("friction"),e.physicsRestitution=t.getParam("mass"),e.physicsImpostor=t.type)}this.metadata&&(e.metadata=this.metadata),e.instances=[];for(let s=0;s<this.instances.length;s++){const t=this.instances[s];if(t.doNotSerialize)continue;const n={name:t.name,id:t.id,isEnabled:t.isEnabled(!1),isVisible:t.isVisible,isPickable:t.isPickable,checkCollisions:t.checkCollisions,position:t.position.asArray(),scaling:t.scaling.asArray()};if(t.parent&&t.parent._serializeAsParent(n),t.rotationQuaternion?n.rotationQuaternion=t.rotationQuaternion.asArray():t.rotation&&(n.rotation=t.rotation.asArray()),this.getScene()._getComponent(x.l.NAME_PHYSICSENGINE)){const e=t.getPhysicsImpostor();e&&(n.physicsMass=e.getParam("mass"),n.physicsFriction=e.getParam("friction"),n.physicsRestitution=e.getParam("mass"),n.physicsImpostor=e.type)}t.metadata&&(n.metadata=t.metadata),t.actionManager&&(n.actions=t.actionManager.serialize(t.name)),e.instances.push(n),y.p4.AppendSerializedAnimations(t,n),n.ranges=t.serializeAnimationRanges()}if(this._thinInstanceDataStorage.instancesCount&&this._thinInstanceDataStorage.matrixData&&(e.thinInstances={instancesCount:this._thinInstanceDataStorage.instancesCount,matrixData:Array.from(this._thinInstanceDataStorage.matrixData),matrixBufferSize:this._thinInstanceDataStorage.matrixBufferSize,enablePicking:this.thinInstanceEnablePicking},this._userThinInstanceBuffersStorage)){const t={data:{},sizes:{},strides:{}};for(const e in this._userThinInstanceBuffersStorage.data)t.data[e]=Array.from(this._userThinInstanceBuffersStorage.data[e]),t.sizes[e]=this._userThinInstanceBuffersStorage.sizes[e],t.strides[e]=this._userThinInstanceBuffersStorage.strides[e];e.thinInstances.userThinInstance=t}return y.p4.AppendSerializedAnimations(this,e),e.ranges=this.serializeAnimationRanges(),e.layerMask=this.layerMask,e.alphaIndex=this.alphaIndex,e.hasVertexAlpha=this.hasVertexAlpha,e.overlayAlpha=this.overlayAlpha,e.overlayColor=this.overlayColor.asArray(),e.renderOverlay=this.renderOverlay,e.applyFog=this.applyFog,this.actionManager&&(e.actions=this.actionManager.serialize(this.name)),e}_syncGeometryWithMorphTargetManager(){if(!this.geometry)return;this._markSubMeshesAsAttributesDirty();const e=this._internalAbstractMeshDataInfo._morphTargetManager;if(e&&e.vertexCount){if(e.vertexCount!==this.getTotalVertices())return D.Y.Error("Mesh is incompatible with morph targets. Targets and mesh must all have the same vertices count."),void(this.morphTargetManager=null);if(e.isUsingTextureForTargets)return;for(let t=0;t<e.numInfluencers;t++){const s=e.getActiveTarget(t),n=s.getPositions();if(!n)return void D.Y.Error("Invalid morph target. Target must have positions.");this.geometry.setVerticesData(f.o.PositionKind+t,n,!1,3);const i=s.getNormals();i&&this.geometry.setVerticesData(f.o.NormalKind+t,i,!1,3);const r=s.getTangents();r&&this.geometry.setVerticesData(f.o.TangentKind+t,r,!1,3);const a=s.getUVs();a&&this.geometry.setVerticesData(f.o.UVKind+"_"+t,a,!1,2)}}else{let e=0;for(;this.geometry.isVerticesDataPresent(f.o.PositionKind+e);)this.geometry.removeVerticesData(f.o.PositionKind+e),this.geometry.isVerticesDataPresent(f.o.NormalKind+e)&&this.geometry.removeVerticesData(f.o.NormalKind+e),this.geometry.isVerticesDataPresent(f.o.TangentKind+e)&&this.geometry.removeVerticesData(f.o.TangentKind+e),this.geometry.isVerticesDataPresent(f.o.UVKind+e)&&this.geometry.removeVerticesData(f.o.UVKind+"_"+e),e++}}static Parse(e,t,s){let n;if(n=e.type&&"LinesMesh"===e.type?F._LinesMeshParser(e,t):e.type&&"GroundMesh"===e.type?F._GroundMeshParser(e,t):e.type&&"GoldbergMesh"===e.type?F._GoldbergMeshParser(e,t):e.type&&"GreasedLineMesh"===e.type?F._GreasedLineMeshParser(e,t):new F(e.name,t),n.id=e.id,n._waitingParsedUniqueId=e.uniqueId,a.$&&a.$.AddTagsTo(n,e.tags),n.position=c.P.FromArray(e.position),void 0!==e.metadata&&(n.metadata=e.metadata),e.rotationQuaternion?n.rotationQuaternion=c._f.FromArray(e.rotationQuaternion):e.rotation&&(n.rotation=c.P.FromArray(e.rotation)),n.scaling=c.P.FromArray(e.scaling),e.localMatrix?n.setPreTransformMatrix(c.y3.FromArray(e.localMatrix)):e.pivotMatrix&&n.setPivotMatrix(c.y3.FromArray(e.pivotMatrix)),n.setEnabled(e.isEnabled),n.isVisible=e.isVisible,n.infiniteDistance=e.infiniteDistance,n.showBoundingBox=e.showBoundingBox,n.showSubMeshesBoundingBox=e.showSubMeshesBoundingBox,void 0!==e.applyFog&&(n.applyFog=e.applyFog),void 0!==e.pickable&&(n.isPickable=e.pickable),void 0!==e.alphaIndex&&(n.alphaIndex=e.alphaIndex),n.receiveShadows=e.receiveShadows,void 0!==e.billboardMode&&(n.billboardMode=e.billboardMode),void 0!==e.visibility&&(n.visibility=e.visibility),n.checkCollisions=e.checkCollisions,n.overrideMaterialSideOrientation=e.overrideMaterialSideOrientation,void 0!==e.isBlocker&&(n.isBlocker=e.isBlocker),n._shouldGenerateFlatShading=e.useFlatShading,e.freezeWorldMatrix&&(n._waitingData.freezeWorldMatrix=e.freezeWorldMatrix),void 0!==e.parentId&&(n._waitingParentId=e.parentId),void 0!==e.parentInstanceIndex&&(n._waitingParentInstanceIndex=e.parentInstanceIndex),void 0!==e.actions&&(n._waitingData.actions=e.actions),void 0!==e.overlayAlpha&&(n.overlayAlpha=e.overlayAlpha),void 0!==e.overlayColor&&(n.overlayColor=d.Wo.FromArray(e.overlayColor)),void 0!==e.renderOverlay&&(n.renderOverlay=e.renderOverlay),n.isUnIndexed=!!e.isUnIndexed,n.hasVertexAlpha=e.hasVertexAlpha,e.delayLoadingFile?(n.delayLoadState=4,n.delayLoadingFile=s+e.delayLoadingFile,n.buildBoundingInfo(c.P.FromArray(e.boundingBoxMinimum),c.P.FromArray(e.boundingBoxMaximum)),e._binaryInfo&&(n._binaryInfo=e._binaryInfo),n._delayInfo=[],e.hasUVs&&n._delayInfo.push(f.o.UVKind),e.hasUVs2&&n._delayInfo.push(f.o.UV2Kind),e.hasUVs3&&n._delayInfo.push(f.o.UV3Kind),e.hasUVs4&&n._delayInfo.push(f.o.UV4Kind),e.hasUVs5&&n._delayInfo.push(f.o.UV5Kind),e.hasUVs6&&n._delayInfo.push(f.o.UV6Kind),e.hasColors&&n._delayInfo.push(f.o.ColorKind),e.hasMatricesIndices&&n._delayInfo.push(f.o.MatricesIndicesKind),e.hasMatricesWeights&&n._delayInfo.push(f.o.MatricesWeightsKind),n._delayLoadingFunction=_.Z._ImportGeometry,v.Z.ForceFullSceneLoadingForIncremental&&n._checkDelayState()):_.Z._ImportGeometry(e,n),e.materialUniqueId?n._waitingMaterialId=e.materialUniqueId:e.materialId&&(n._waitingMaterialId=e.materialId),e.morphTargetManagerId>-1&&(n.morphTargetManager=t.getMorphTargetManagerById(e.morphTargetManagerId)),void 0!==e.skeletonId&&null!==e.skeletonId&&(n.skeleton=t.getLastSkeletonById(e.skeletonId),e.numBoneInfluencers&&(n.numBoneInfluencers=e.numBoneInfluencers)),e.animations){for(let t=0;t<e.animations.length;t++){const s=e.animations[t],i=(0,b.q)("BABYLON.Animation");i&&n.animations.push(i.Parse(s))}u.N.ParseAnimationRanges(n,e,t)}if(e.autoAnimate&&t.beginAnimation(n,e.autoAnimateFrom,e.autoAnimateTo,e.autoAnimateLoop,e.autoAnimateSpeed||1),e.layerMask&&!isNaN(e.layerMask)?n.layerMask=Math.abs(parseInt(e.layerMask)):n.layerMask=268435455,e.physicsImpostor&&F._PhysicsImpostorParser(t,n,e),e.lodMeshIds&&(n._waitingData.lods={ids:e.lodMeshIds,distances:e.lodDistances?e.lodDistances:null,coverages:e.lodCoverages?e.lodCoverages:null}),e.instances)for(let i=0;i<e.instances.length;i++){const s=e.instances[i],r=n.createInstance(s.name);if(s.id&&(r.id=s.id),a.$&&(s.tags?a.$.AddTagsTo(r,s.tags):a.$.AddTagsTo(r,e.tags)),r.position=c.P.FromArray(s.position),void 0!==s.metadata&&(r.metadata=s.metadata),void 0!==s.parentId&&(r._waitingParentId=s.parentId),void 0!==s.parentInstanceIndex&&(r._waitingParentInstanceIndex=s.parentInstanceIndex),void 0!==s.isEnabled&&null!==s.isEnabled&&r.setEnabled(s.isEnabled),void 0!==s.isVisible&&null!==s.isVisible&&(r.isVisible=s.isVisible),void 0!==s.isPickable&&null!==s.isPickable&&(r.isPickable=s.isPickable),s.rotationQuaternion?r.rotationQuaternion=c._f.FromArray(s.rotationQuaternion):s.rotation&&(r.rotation=c.P.FromArray(s.rotation)),r.scaling=c.P.FromArray(s.scaling),null!=s.checkCollisions&&null!=s.checkCollisions&&(r.checkCollisions=s.checkCollisions),null!=s.pickable&&null!=s.pickable&&(r.isPickable=s.pickable),null!=s.showBoundingBox&&null!=s.showBoundingBox&&(r.showBoundingBox=s.showBoundingBox),null!=s.showSubMeshesBoundingBox&&null!=s.showSubMeshesBoundingBox&&(r.showSubMeshesBoundingBox=s.showSubMeshesBoundingBox),null!=s.alphaIndex&&null!=s.showSubMeshesBoundingBox&&(r.alphaIndex=s.alphaIndex),s.physicsImpostor&&F._PhysicsImpostorParser(t,r,s),void 0!==s.actions&&(r._waitingData.actions=s.actions),s.animations){for(let e=0;e<s.animations.length;e++){const t=s.animations[e],n=(0,b.q)("BABYLON.Animation");n&&r.animations.push(n.Parse(t))}u.N.ParseAnimationRanges(r,s,t),s.autoAnimate&&t.beginAnimation(r,s.autoAnimateFrom,s.autoAnimateTo,s.autoAnimateLoop,s.autoAnimateSpeed||1)}}if(e.thinInstances){const t=e.thinInstances;if(n.thinInstanceEnablePicking=!!t.enablePicking,t.matrixData?(n.thinInstanceSetBuffer("matrix",new Float32Array(t.matrixData),16,!1),n._thinInstanceDataStorage.matrixBufferSize=t.matrixBufferSize,n._thinInstanceDataStorage.instancesCount=t.instancesCount):n._thinInstanceDataStorage.matrixBufferSize=t.matrixBufferSize,e.thinInstances.userThinInstance){const t=e.thinInstances.userThinInstance;for(const e in t.data)n.thinInstanceSetBuffer(e,new Float32Array(t.data[e]),t.strides[e],!1),n._userThinInstanceBuffersStorage.sizes[e]=t.sizes[e]}}return n}setPositionsForCPUSkinning(){const e=this._internalMeshDataInfo;if(!e._sourcePositions){const t=this.getVerticesData(f.o.PositionKind);if(!t)return e._sourcePositions;e._sourcePositions=new Float32Array(t),this.isVertexBufferUpdatable(f.o.PositionKind)||this.setVerticesData(f.o.PositionKind,t,!0)}return e._sourcePositions}setNormalsForCPUSkinning(){const e=this._internalMeshDataInfo;if(!e._sourceNormals){const t=this.getVerticesData(f.o.NormalKind);if(!t)return e._sourceNormals;e._sourceNormals=new Float32Array(t),this.isVertexBufferUpdatable(f.o.NormalKind)||this.setVerticesData(f.o.NormalKind,t,!0)}return e._sourceNormals}applySkeleton(e){if(!this.geometry)return this;if(this.geometry._softwareSkinningFrameId==this.getScene().getFrameId())return this;if(this.geometry._softwareSkinningFrameId=this.getScene().getFrameId(),!this.isVerticesDataPresent(f.o.PositionKind))return this;if(!this.isVerticesDataPresent(f.o.MatricesIndicesKind))return this;if(!this.isVerticesDataPresent(f.o.MatricesWeightsKind))return this;const t=this.isVerticesDataPresent(f.o.NormalKind),s=this._internalMeshDataInfo;if(!s._sourcePositions){const e=this.subMeshes.slice();this.setPositionsForCPUSkinning(),this.subMeshes=e}t&&!s._sourceNormals&&this.setNormalsForCPUSkinning();let n=this.getVerticesData(f.o.PositionKind);if(!n)return this;n instanceof Float32Array||(n=new Float32Array(n));let i=this.getVerticesData(f.o.NormalKind);if(t){if(!i)return this;i instanceof Float32Array||(i=new Float32Array(i))}const r=this.getVerticesData(f.o.MatricesIndicesKind),a=this.getVerticesData(f.o.MatricesWeightsKind);if(!a||!r)return this;const o=this.numBoneInfluencers>4,h=o?this.getVerticesData(f.o.MatricesIndicesExtraKind):null,l=o?this.getVerticesData(f.o.MatricesWeightsExtraKind):null,d=e.getTransformMatrices(this),u=c.P.Zero(),g=new c.y3,_=new c.y3;let m,I=0;for(let f=0;f<n.length;f+=3,I+=4){let e;for(m=0;m<4;m++)e=a[I+m],e>0&&(c.y3.FromFloat32ArrayToRefScaled(d,Math.floor(16*r[I+m]),e,_),g.addToSelf(_));if(o)for(m=0;m<4;m++)e=l[I+m],e>0&&(c.y3.FromFloat32ArrayToRefScaled(d,Math.floor(16*h[I+m]),e,_),g.addToSelf(_));c.P.TransformCoordinatesFromFloatsToRef(s._sourcePositions[f],s._sourcePositions[f+1],s._sourcePositions[f+2],g,u),u.toArray(n,f),t&&(c.P.TransformNormalFromFloatsToRef(s._sourceNormals[f],s._sourceNormals[f+1],s._sourceNormals[f+2],g,u),u.toArray(i,f)),g.reset()}return this.updateVerticesData(f.o.PositionKind,n),t&&this.updateVerticesData(f.o.NormalKind,i),this}static MinMax(e){let t=null,s=null;return e.forEach((function(e){const n=e.getBoundingInfo().boundingBox;t&&s?(t.minimizeInPlace(n.minimumWorld),s.maximizeInPlace(n.maximumWorld)):(t=n.minimumWorld,s=n.maximumWorld)})),t&&s?{min:t,max:s}:{min:c.P.Zero(),max:c.P.Zero()}}static Center(e){const t=e instanceof Array?F.MinMax(e):e;return c.P.Center(t.min,t.max)}static MergeMeshes(e,t=!0,s,n,i,r){return(0,o.s3)(F._MergeMeshesCoroutine(e,t,s,n,i,r,!1))}static MergeMeshesAsync(e,t=!0,s,n,i,r){return(0,o.sM)(F._MergeMeshesCoroutine(e,t,s,n,i,r,!0),(0,o.KO)())}static*_MergeMeshesCoroutine(e,t=!0,s,n,i,r,a){if(0===(e=e.filter(Boolean)).length)return null;let o;if(!s){let t=0;for(o=0;o<e.length;o++)if(t+=e[o].getTotalVertices(),t>=65536)return D.Y.Warn("Cannot merge meshes because resulting mesh will have more than 65536 vertices. Please use allow32BitsIndices = true to use 32 bits indices"),null}r&&(i=!1);const h=new Array,l=new Array,c=new Array,d=e[0].overrideMaterialSideOrientation;for(o=0;o<e.length;o++){const t=e[o];if(t.isAnInstance)return D.Y.Warn("Cannot merge instance meshes."),null;if(d!==t.overrideMaterialSideOrientation)return D.Y.Warn("Cannot merge meshes with different overrideMaterialSideOrientation values."),null;if(i&&c.push(t.getTotalIndices()),r)if(t.material){const e=t.material;if(e instanceof p.G){for(let t=0;t<e.subMaterials.length;t++)h.indexOf(e.subMaterials[t])<0&&h.push(e.subMaterials[t]);for(let s=0;s<t.subMeshes.length;s++)l.push(h.indexOf(e.subMaterials[t.subMeshes[s].materialIndex])),c.push(t.subMeshes[s].indexCount)}else{h.indexOf(e)<0&&h.push(e);for(let s=0;s<t.subMeshes.length;s++)l.push(h.indexOf(e)),c.push(t.subMeshes[s].indexCount)}}else for(let e=0;e<t.subMeshes.length;e++)l.push(0),c.push(t.subMeshes[e].indexCount)}const u=e[0],f=e=>{const t=e.computeWorldMatrix(!0);return{vertexData:g.x.ExtractFromMesh(e,!1,!1),transform:t}},{vertexData:_,transform:m}=f(u);a&&(yield);const M=new Array(e.length-1);for(let g=1;g<e.length;g++)M[g-1]=f(e[g]),a&&(yield);const v=_._mergeCoroutine(m,M,s,a,!t);let y=v.next();for(;!y.done;)a&&(yield),y=v.next();const b=y.value;n||(n=new F(u.name+"_merged",u.getScene()));const S=b._applyToCoroutine(n,void 0,a);let x=S.next();for(;!x.done;)a&&(yield),x=S.next();if(n.checkCollisions=u.checkCollisions,n.overrideMaterialSideOrientation=u.overrideMaterialSideOrientation,t)for(o=0;o<e.length;o++)e[o].dispose();if(i||r){n.releaseSubMeshes(),o=0;let e=0;for(;o<c.length;)I.P.CreateFromIndices(0,e,c[o],n,void 0,!1),e+=c[o],o++;for(const t of n.subMeshes)t.refreshBoundingInfo();n.computeWorldMatrix(!0)}if(r){const e=new p.G(u.name+"_merged",u.getScene());e.subMaterials=h;for(let t=0;t<n.subMeshes.length;t++)n.subMeshes[t].materialIndex=l[t];n.material=e}else n.material=u.material;return n}addInstance(e){e._indexInSourceMeshInstanceArray=this.instances.length,this.instances.push(e)}removeInstance(e){const t=e._indexInSourceMeshInstanceArray;if(-1!=t){if(t!==this.instances.length-1){const e=this.instances[this.instances.length-1];this.instances[t]=e,e._indexInSourceMeshInstanceArray=t}e._indexInSourceMeshInstanceArray=-1,this.instances.pop()}}_shouldConvertRHS(){return this.overrideMaterialSideOrientation===M.F.CounterClockWiseSideOrientation}_getRenderingFillMode(e){var t;const s=this.getScene();return s.forcePointsCloud?M.F.PointFillMode:s.forceWireframe?M.F.WireFrameFillMode:null!==(t=this.overrideRenderingFillMode)&&void 0!==t?t:e}}F.FRONTSIDE=g.x.FRONTSIDE,F.BACKSIDE=g.x.BACKSIDE,F.DOUBLESIDE=g.x.DOUBLESIDE,F.DEFAULTSIDE=g.x.DEFAULTSIDE,F.NO_CAP=0,F.CAP_START=1,F.CAP_END=2,F.CAP_ALL=3,F.NO_FLIP=0,F.FLIP_TILE=1,F.ROTATE_TILE=2,F.FLIP_ROW=3,F.ROTATE_ROW=4,F.FLIP_N_ROTATE_TILE=5,F.FLIP_N_ROTATE_ROW=6,F.CENTER=0,F.LEFT=1,F.RIGHT=2,F.TOP=3,F.BOTTOM=4,F.INSTANCEDMESH_SORT_TRANSPARENT=!1,F._GroundMeshParser=(e,t)=>{throw(0,S.S)("GroundMesh")},F._GoldbergMeshParser=(e,t)=>{throw(0,S.S)("GoldbergMesh")},F._LinesMeshParser=(e,t)=>{throw(0,S.S)("LinesMesh")},F._GreasedLineMeshParser=(e,t)=>{throw(0,S.S)("GreasedLineMesh")},(0,b.H)("BABYLON.Mesh",F),F.prototype.setMaterialByID=function(e){return this.setMaterialById(e)},F.CreateDisc=F.CreateDisc||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateBox=F.CreateBox||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateSphere=F.CreateSphere||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateCylinder=F.CreateCylinder||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateTorusKnot=F.CreateTorusKnot||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateTorus=F.CreateTorus||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreatePlane=F.CreatePlane||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateGround=F.CreateGround||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateTiledGround=F.CreateTiledGround||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateGroundFromHeightMap=F.CreateGroundFromHeightMap||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateTube=F.CreateTube||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreatePolyhedron=F.CreatePolyhedron||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateIcoSphere=F.CreateIcoSphere||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateDecal=F.CreateDecal||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.CreateCapsule=F.CreateCapsule||(()=>{throw new Error("Import MeshBuilder to populate this function")}),F.ExtendToGoldberg=F.ExtendToGoldberg||(()=>{throw new Error("Import MeshBuilder to populate this function")})}}]);
//# sourceMappingURL=87a06baf-5d3ac30d48950f0f9b7a.js.map