UNPKG

@babylonjs/viewer

Version:

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

3 lines (2 loc) 25.4 kB
import{ap as e,b as t,L as s,m as n,br as r,M as o,aS as i,bs as a,g as h,R as c,H as u,a8 as d,a2 as f,bt as l}from"./index-Bw2N6w1y.esm.min.js";h._instancedMeshFactory=(e,t)=>{const s=new g(e,t);if(t.instancedBuffers){s.instancedBuffers={};for(const e in t.instancedBuffers)s.instancedBuffers[e]=t.instancedBuffers[e]}return s};class g extends e{constructor(e,t){super(e,t.getScene()),this._indexInSourceMeshInstanceArray=-1,this._distanceToCamera=0,t.addInstance(this),this._sourceMesh=t,this._unIndexed=t._unIndexed,this.position.copyFrom(t.position),this.rotation.copyFrom(t.rotation),this.scaling.copyFrom(t.scaling),t.rotationQuaternion&&(this.rotationQuaternion=t.rotationQuaternion.clone()),this.animations=t.animations.slice();for(const e of t.getAnimationRanges())null!=e&&this.createAnimationRange(e.name,e.from,e.to);if(this.infiniteDistance=t.infiniteDistance,this.setPivotMatrix(t.getPivotMatrix()),t.skeleton||t.morphTargetManager||!t.hasBoundingInfo)this.refreshBoundingInfo(!0,!0);else{const e=t.getBoundingInfo();this.buildBoundingInfo(e.minimum,e.maximum)}this._syncSubMeshes()}getClassName(){return"InstancedMesh"}get lightSources(){return this._sourceMesh._lightSources}_resyncLightSources(){}_resyncLightSource(){}_removeLightSource(){}get receiveShadows(){return this._sourceMesh.receiveShadows}set receiveShadows(e){this._sourceMesh?.receiveShadows!==e&&t.Warn("Setting receiveShadows on an instanced mesh has no effect")}get material(){return this._sourceMesh.material}set material(e){this._sourceMesh?.material!==e&&t.Warn("Setting material on an instanced mesh has no effect")}get visibility(){return this._sourceMesh.visibility}set visibility(e){this._sourceMesh?.visibility!==e&&t.Warn("Setting visibility on an instanced mesh has no effect")}get skeleton(){return this._sourceMesh.skeleton}set skeleton(e){this._sourceMesh?.skeleton!==e&&t.Warn("Setting skeleton on an instanced mesh has no effect")}get renderingGroupId(){return this._sourceMesh.renderingGroupId}set renderingGroupId(e){this._sourceMesh&&e!==this._sourceMesh.renderingGroupId&&s.Warn("Note - setting renderingGroupId of an instanced mesh has no effect on the scene")}getTotalVertices(){return this._sourceMesh?this._sourceMesh.getTotalVertices():0}getTotalIndices(){return this._sourceMesh.getTotalIndices()}get sourceMesh(){return this._sourceMesh}get geometry(){return this._sourceMesh._geometry}createInstance(e){return this._sourceMesh.createInstance(e)}isReady(e=!1){return this._sourceMesh.isReady(e,!0)}getVerticesData(e,t,s){return this._sourceMesh.getVerticesData(e,t,s)}copyVerticesData(e,t){this._sourceMesh.copyVerticesData(e,t)}setVerticesData(e,t,s,n){return this.sourceMesh&&this.sourceMesh.setVerticesData(e,t,s,n),this.sourceMesh}updateVerticesData(e,t,s,n){return this.sourceMesh&&this.sourceMesh.updateVerticesData(e,t,s,n),this.sourceMesh}setIndices(e,t=null){return this.sourceMesh&&this.sourceMesh.setIndices(e,t),this.sourceMesh}isVerticesDataPresent(e){return this._sourceMesh.isVerticesDataPresent(e)}getIndices(){return this._sourceMesh.getIndices()}get _positions(){return this._sourceMesh._positions}refreshBoundingInfo(e=!1,t=!1){if(this.hasBoundingInfo&&this.getBoundingInfo().isLocked)return this;let s;s="object"==typeof e?e:{applySkeleton:e,applyMorph:t};const r=this._sourceMesh.geometry?this._sourceMesh.geometry.boundingBias:null;return this._refreshBoundingInfo(this._sourceMesh._getData(s,null,n.PositionKind),r),this}_preActivate(){return this._currentLOD&&this._currentLOD._preActivate(),this}_activate(e,t){if(super._activate(e,t),this._sourceMesh.subMeshes||s.Warn("Instances should only be created for meshes with geometry."),this._currentLOD){if(this._currentLOD._getWorldMatrixDeterminant()>=0!=this._getWorldMatrixDeterminant()>=0)return this._internalAbstractMeshDataInfo._actAsRegularMesh=!0,!0;if(this._internalAbstractMeshDataInfo._actAsRegularMesh=!1,this._currentLOD._registerInstanceForRenderId(this,e),t){if(!this._currentLOD._internalAbstractMeshDataInfo._isActiveIntermediate)return this._currentLOD._internalAbstractMeshDataInfo._onlyForInstancesIntermediate=!0,!0}else if(!this._currentLOD._internalAbstractMeshDataInfo._isActive)return this._currentLOD._internalAbstractMeshDataInfo._onlyForInstances=!0,!0}return!1}_postActivate(){this._sourceMesh.edgesShareWithInstances&&this._sourceMesh._edgesRenderer&&this._sourceMesh._edgesRenderer.isEnabled&&this._sourceMesh._renderingGroup?(this._sourceMesh._renderingGroup._edgesRenderers.pushNoDuplicate(this._sourceMesh._edgesRenderer),this._sourceMesh._edgesRenderer.customInstances.push(this.getWorldMatrix())):this._edgesRenderer&&this._edgesRenderer.isEnabled&&this._sourceMesh._renderingGroup&&this._sourceMesh._renderingGroup._edgesRenderers.push(this._edgesRenderer)}getWorldMatrix(){if(this._currentLOD&&this._currentLOD!==this._sourceMesh&&this._currentLOD.billboardMode!==r.BILLBOARDMODE_NONE&&this._currentLOD._masterMesh!==this){this._billboardWorldMatrix||(this._billboardWorldMatrix=new o);const e=this._currentLOD._masterMesh;return this._currentLOD._masterMesh=this,i.Vector3[7].copyFrom(this._currentLOD.position),this._currentLOD.position.set(0,0,0),this._billboardWorldMatrix.copyFrom(this._currentLOD.computeWorldMatrix(!0)),this._currentLOD.position.copyFrom(i.Vector3[7]),this._currentLOD._masterMesh=e,this._billboardWorldMatrix}return super.getWorldMatrix()}get isAnInstance(){return!0}getLOD(e){if(!e)return this;const t=this.sourceMesh.getLODLevels();if(t&&0!==t.length){const t=this.getBoundingInfo();this._currentLOD=this.sourceMesh.getLOD(e,t.boundingSphere)}else this._currentLOD=this.sourceMesh;return this._currentLOD}_preActivateForIntermediateRendering(e){return this.sourceMesh._preActivateForIntermediateRendering(e)}_syncSubMeshes(){if(this.releaseSubMeshes(),this._sourceMesh.subMeshes)for(let e=0;e<this._sourceMesh.subMeshes.length;e++)this._sourceMesh.subMeshes[e].clone(this,this._sourceMesh);return this}_generatePointsArray(){return this._sourceMesh._generatePointsArray()}_updateBoundingInfo(){return this.hasBoundingInfo?this.getBoundingInfo().update(this.worldMatrixFromCache):this.buildBoundingInfo(this.absolutePosition,this.absolutePosition,this.worldMatrixFromCache),this._updateSubMeshesBoundingInfo(this.worldMatrixFromCache),this}clone(e,t=null,s,n){const r=(n||this._sourceMesh).createInstance(e);if(a.DeepCopy(this,r,["name","subMeshes","uniqueId","parent","lightSources","receiveShadows","material","visibility","skeleton","sourceMesh","isAnInstance","facetNb","isFacetDataEnabled","isBlocked","useBones","hasInstances","collider","edgesRenderer","forward","up","right","absolutePosition","absoluteScaling","absoluteRotationQuaternion","isWorldMatrixFrozen","nonUniformScaling","behaviors","worldMatrixFromCache","hasThinInstances","hasBoundingInfo","geometry"],[]),this.refreshBoundingInfo(),t&&(r.parent=t),!s)for(let e=0;e<this.getScene().meshes.length;e++){const t=this.getScene().meshes[e];t.parent===this&&t.clone(t.name,r)}return r.computeWorldMatrix(!0),this.onClonedObservable.notifyObservers(r),r}dispose(e,t=!1){this._sourceMesh.removeInstance(this),super.dispose(e,t)}_serializeAsParent(e){super._serializeAsParent(e),e.parentId=this._sourceMesh.uniqueId,e.parentInstanceIndex=this._indexInSourceMeshInstanceArray}instantiateHierarchy(e=null,t,s){const n=this.clone("Clone of "+(this.name||this.id),e||this.parent,!0,t&&t.newSourcedMesh);n&&s&&s(this,n);for(const e of this.getChildTransformNodes(!0))e.instantiateHierarchy(n,t,s);return n}}h.prototype.registerInstancedBuffer=function(e,t){if(this._userInstancedBuffersStorage?.vertexBuffers[e]?.dispose(),!this.instancedBuffers){this.instancedBuffers={};for(const e of this.instances)e.instancedBuffers={}}this._userInstancedBuffersStorage||(this._userInstancedBuffersStorage={data:{},vertexBuffers:{},strides:{},sizes:{},vertexArrayObjects:this.getEngine().getCaps().vertexArrayObject?{}:void 0}),this.instancedBuffers[e]=null,this._userInstancedBuffersStorage.strides[e]=t,this._userInstancedBuffersStorage.sizes[e]=32*t,this._userInstancedBuffersStorage.data[e]=new Float32Array(this._userInstancedBuffersStorage.sizes[e]),this._userInstancedBuffersStorage.vertexBuffers[e]=new n(this.getEngine(),this._userInstancedBuffersStorage.data[e],e,!0,!1,t,!0);for(const t of this.instances)t.instancedBuffers[e]=null;this._invalidateInstanceVertexArrayObject(),this._markSubMeshesAsAttributesDirty()},h.prototype._processInstancedBuffers=function(e,t){const s=e?e.length:0;for(const r in this.instancedBuffers){let o=this._userInstancedBuffersStorage.sizes[r];const i=this._userInstancedBuffersStorage.strides[r],a=(s+1)*i;for(;o<a;)o*=2;this._userInstancedBuffersStorage.data[r].length!=o&&(this._userInstancedBuffersStorage.data[r]=new Float32Array(o),this._userInstancedBuffersStorage.sizes[r]=o,this._userInstancedBuffersStorage.vertexBuffers[r]&&(this._userInstancedBuffersStorage.vertexBuffers[r].dispose(),this._userInstancedBuffersStorage.vertexBuffers[r]=null));const h=this._userInstancedBuffersStorage.data[r];let c=0;if(t){const e=this.instancedBuffers[r];e.toArray?e.toArray(h,c):e.copyToArray?e.copyToArray(h,c):h[c]=e,c+=i}for(let t=0;t<s;t++){const s=e[t].instancedBuffers[r];s.toArray?s.toArray(h,c):s.copyToArray?s.copyToArray(h,c):h[c]=s,c+=i}this._userInstancedBuffersStorage.vertexBuffers[r]?this._userInstancedBuffersStorage.vertexBuffers[r].updateDirectly(h,0):(this._userInstancedBuffersStorage.vertexBuffers[r]=new n(this.getEngine(),this._userInstancedBuffersStorage.data[r],r,!0,!1,i,!0),this._invalidateInstanceVertexArrayObject())}},h.prototype._invalidateInstanceVertexArrayObject=function(){if(this._userInstancedBuffersStorage&&void 0!==this._userInstancedBuffersStorage.vertexArrayObjects){for(const e in this._userInstancedBuffersStorage.vertexArrayObjects)this.getEngine().releaseVertexArrayObject(this._userInstancedBuffersStorage.vertexArrayObjects[e]);this._userInstancedBuffersStorage.vertexArrayObjects={}}},h.prototype._disposeInstanceSpecificData=function(){for(this._instanceDataStorage.instancesBuffer&&(this._instanceDataStorage.instancesBuffer.dispose(),this._instanceDataStorage.instancesBuffer=null);this.instances.length;)this.instances[0].dispose();for(const e in this.instancedBuffers)this._userInstancedBuffersStorage.vertexBuffers[e]&&this._userInstancedBuffersStorage.vertexBuffers[e].dispose();this._invalidateInstanceVertexArrayObject(),this.instancedBuffers={}},c("BABYLON.InstancedMesh",g);class m{constructor(){this.rootNodes=[],this.cameras=[],this.lights=[],this.meshes=[],this.skeletons=[],this.particleSystems=[],this.animations=[],this.animationGroups=[],this.multiMaterials=[],this.materials=[],this.morphTargetManagers=[],this.geometries=[],this.transformNodes=[],this.actionManagers=[],this.textures=[],this._environmentTexture=null,this.postProcesses=[],this.sounds=null,this.effectLayers=[],this.layers=[],this.reflectionProbes=[]}get environmentTexture(){return this._environmentTexture}set environmentTexture(e){this._environmentTexture=e}getNodes(){let e=[];e=e.concat(this.meshes),e=e.concat(this.lights),e=e.concat(this.cameras),e=e.concat(this.transformNodes);for(const t of this.skeletons)e=e.concat(t.bones);return e}}class p extends m{}class _{constructor(){this.rootNodes=[],this.skeletons=[],this.animationGroups=[]}dispose(){const e=this.rootNodes;for(const t of e)t.dispose();e.length=0;const t=this.skeletons;for(const e of t)e.dispose();t.length=0;const s=this.animationGroups;for(const e of s)e.dispose();s.length=0}}class M extends m{constructor(e){super(),this._wasAddedToScene=!1,(e=e||u.LastCreatedScene)&&(this.scene=e,this.proceduralTextures=[],e.onDisposeObservable.add((()=>{this._wasAddedToScene||this.dispose()})),this._onContextRestoredObserver=e.getEngine().onContextRestoredObservable.add((()=>{for(const e of this.geometries)e._rebuild();for(const e of this.meshes)e._rebuild();for(const e of this.particleSystems)e.rebuild();for(const e of this.textures)e._rebuild()})))}_topologicalSort(e){const t=new Map;for(const s of e)t.set(s.uniqueId,s);const n={dependsOn:new Map,dependedBy:new Map};for(const t of e){const e=t.uniqueId;n.dependsOn.set(e,new Set),n.dependedBy.set(e,new Set)}for(const s of e){const e=s.uniqueId,r=n.dependsOn.get(e);if(s instanceof g){const o=s.sourceMesh;t.has(o.uniqueId)&&(r.add(o.uniqueId),n.dependedBy.get(o.uniqueId).add(e))}const o=n.dependedBy.get(e);for(const r of s.getDescendants()){const s=r.uniqueId;if(t.has(s)){o.add(s);n.dependsOn.get(s).add(e)}}}const r=[],o=[];for(const s of e){const e=s.uniqueId;0===n.dependsOn.get(e).size&&(o.push(s),t.delete(e))}const i=o;for(;i.length>0;){const e=i.shift();r.push(e);const s=n.dependedBy.get(e.uniqueId);for(const r of Array.from(s.values())){const s=n.dependsOn.get(r);s.delete(e.uniqueId),0===s.size&&t.get(r)&&(i.push(t.get(r)),t.delete(r))}}return t.size>0&&(s.Error("SceneSerializer._topologicalSort: There were unvisited nodes:"),t.forEach((e=>{s.Error(e.name)}))),r}_addNodeAndDescendantsToList(e,t,s,n){if(s&&(!n||n(s))&&!t.has(s.uniqueId)){e.push(s),t.add(s.uniqueId);for(const r of s.getDescendants(!0))this._addNodeAndDescendantsToList(e,t,r,n)}}_isNodeInContainer(t){return t instanceof e&&-1!==this.meshes.indexOf(t)||(t instanceof r&&-1!==this.transformNodes.indexOf(t)||(t instanceof d&&-1!==this.lights.indexOf(t)||t instanceof f&&-1!==this.cameras.indexOf(t)))}_isValidHierarchy(){for(const e of this.meshes)if(e.parent&&!this._isNodeInContainer(e.parent))return s.Warn(`Node ${e.name} has a parent that is not in the container.`),!1;for(const e of this.transformNodes)if(e.parent&&!this._isNodeInContainer(e.parent))return s.Warn(`Node ${e.name} has a parent that is not in the container.`),!1;for(const e of this.lights)if(e.parent&&!this._isNodeInContainer(e.parent))return s.Warn(`Node ${e.name} has a parent that is not in the container.`),!1;for(const e of this.cameras)if(e.parent&&!this._isNodeInContainer(e.parent))return s.Warn(`Node ${e.name} has a parent that is not in the container.`),!1;return!0}instantiateModelsToScene(e,s=!1,n){this._isValidHierarchy()||t.Warn("SceneSerializer.InstantiateModelsToScene: The Asset Container hierarchy is not valid.");const r={},o={},i=new _,a=[],c=[],u={doNotInstantiate:!0,...n},d=[],f=new Set;for(const e of this.transformNodes)null===e.parent&&this._addNodeAndDescendantsToList(d,f,e,u.predicate);for(const e of this.meshes)null===e.parent&&this._addNodeAndDescendantsToList(d,f,e,u.predicate);const l=this._topologicalSort(d),g=(t,n)=>{if(((t,s)=>{if(r[t.uniqueId]=s.uniqueId,o[s.uniqueId]=s,e&&(s.name=e(t.name)),s instanceof h){const e=s;if(e.morphTargetManager){const s=t.morphTargetManager;e.morphTargetManager=s.clone();for(let t=0;t<s.numTargets;t++){const n=s.getTarget(t),i=e.morphTargetManager.getTarget(t);r[n.uniqueId]=i.uniqueId,o[i.uniqueId]=i}}}})(t,n),t.parent){const e=r[t.parent.uniqueId],s=o[e];n.parent=s||t.parent}if(n.position&&t.position&&n.position.copyFrom(t.position),n.rotationQuaternion&&t.rotationQuaternion&&n.rotationQuaternion.copyFrom(t.rotationQuaternion),n.rotation&&t.rotation&&n.rotation.copyFrom(t.rotation),n.scaling&&t.scaling&&n.scaling.copyFrom(t.scaling),n.material){const i=n;if(i.material)if(s){const s=t.material;if(-1===c.indexOf(s)){let t=s.clone(e?e(s.name):"Clone of "+s.name);if(c.push(s),r[s.uniqueId]=t.uniqueId,o[t.uniqueId]=t,"MultiMaterial"===s.getClassName()){const n=s;for(const s of n.subMaterials)s&&(t=s.clone(e?e(s.name):"Clone of "+s.name),c.push(s),r[s.uniqueId]=t.uniqueId,o[t.uniqueId]=t);n.subMaterials=n.subMaterials.map((e=>e&&o[r[e.uniqueId]]))}}"InstancedMesh"!==i.getClassName()&&(i.material=o[r[s.uniqueId]])}else"MultiMaterial"===i.material.getClassName()?-1===this.scene.multiMaterials.indexOf(i.material)&&this.scene.addMultiMaterial(i.material):-1===this.scene.materials.indexOf(i.material)&&this.scene.addMaterial(i.material)}null===n.parent&&i.rootNodes.push(n)};for(const e of l)if("InstancedMesh"===e.getClassName()){const t=e,s=t.sourceMesh,n=r[s.uniqueId];g(t,("number"==typeof n?o[n]:s).createInstance(t.name))}else{let t=!0;"TransformNode"===e.getClassName()||"Node"===e.getClassName()||e.skeleton||!e.getTotalVertices||0===e.getTotalVertices()?t=!1:u.doNotInstantiate&&(t="function"==typeof u.doNotInstantiate?!u.doNotInstantiate(e):!u.doNotInstantiate);const s=t?e.createInstance(`instance of ${e.name}`):e.clone(`Clone of ${e.name}`,null,!0);if(!s)throw new Error(`Could not clone or instantiate node on Asset Container ${e.name}`);g(e,s)}for(const t of this.skeletons){if(u.predicate&&!u.predicate(t))continue;const s=t.clone(e?e(t.name):"Clone of "+t.name);for(const e of this.meshes)if(e.skeleton===t&&!e.isAnInstance){const t=o[r[e.uniqueId]];if(!t||t.isAnInstance)continue;if(t.skeleton=s,-1!==a.indexOf(s))continue;a.push(s);for(const e of s.bones)e._linkedTransformNode&&(e._linkedTransformNode=o[r[e._linkedTransformNode.uniqueId]])}i.skeletons.push(s)}for(const t of this.animationGroups){if(u.predicate&&!u.predicate(t))continue;const s=t.clone(e?e(t.name):"Clone of "+t.name,(e=>o[r[e.uniqueId]]||e));i.animationGroups.push(s)}return i}addAllToScene(){if(!this._wasAddedToScene){this._isValidHierarchy()||t.Warn("SceneSerializer.addAllToScene: The Asset Container hierarchy is not valid."),this._wasAddedToScene=!0,this.addToScene(null),this.environmentTexture&&(this.scene.environmentTexture=this.environmentTexture);for(const e of this.scene._serializableComponents)e.addFromContainer(this);this.scene.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver),this._onContextRestoredObserver=null}}addToScene(e=null){const t=[];for(const s of this.cameras)e&&!e(s)||(this.scene.addCamera(s),t.push(s));for(const s of this.lights)e&&!e(s)||(this.scene.addLight(s),t.push(s));for(const s of this.meshes)e&&!e(s)||(this.scene.addMesh(s),t.push(s));for(const t of this.skeletons)e&&!e(t)||this.scene.addSkeleton(t);for(const t of this.animations)e&&!e(t)||this.scene.addAnimation(t);for(const t of this.animationGroups)e&&!e(t)||this.scene.addAnimationGroup(t);for(const t of this.multiMaterials)e&&!e(t)||this.scene.addMultiMaterial(t);for(const t of this.materials)e&&!e(t)||this.scene.addMaterial(t);for(const t of this.morphTargetManagers)e&&!e(t)||this.scene.addMorphTargetManager(t);for(const t of this.geometries)e&&!e(t)||this.scene.addGeometry(t);for(const s of this.transformNodes)e&&!e(s)||(this.scene.addTransformNode(s),t.push(s));for(const t of this.actionManagers)e&&!e(t)||this.scene.addActionManager(t);for(const t of this.textures)e&&!e(t)||this.scene.addTexture(t);for(const t of this.reflectionProbes)e&&!e(t)||this.scene.addReflectionProbe(t);for(const e of t)e.parent&&-1===this.scene.getNodes().indexOf(e.parent)&&(e.setParent?e.setParent(null):e.parent=null)}removeAllFromScene(){this._isValidHierarchy()||t.Warn("SceneSerializer.removeAllFromScene: The Asset Container hierarchy is not valid."),this._wasAddedToScene=!1,this.removeFromScene(null),this.environmentTexture===this.scene.environmentTexture&&(this.scene.environmentTexture=null);for(const e of this.scene._serializableComponents)e.removeFromContainer(this)}removeFromScene(e=null){for(const t of this.cameras)e&&!e(t)||this.scene.removeCamera(t);for(const t of this.lights)e&&!e(t)||this.scene.removeLight(t);for(const t of this.meshes)e&&!e(t)||this.scene.removeMesh(t,!0);for(const t of this.skeletons)e&&!e(t)||this.scene.removeSkeleton(t);for(const t of this.animations)e&&!e(t)||this.scene.removeAnimation(t);for(const t of this.animationGroups)e&&!e(t)||this.scene.removeAnimationGroup(t);for(const t of this.multiMaterials)e&&!e(t)||this.scene.removeMultiMaterial(t);for(const t of this.materials)e&&!e(t)||this.scene.removeMaterial(t);for(const t of this.morphTargetManagers)e&&!e(t)||this.scene.removeMorphTargetManager(t);for(const t of this.geometries)e&&!e(t)||this.scene.removeGeometry(t);for(const t of this.transformNodes)e&&!e(t)||this.scene.removeTransformNode(t);for(const t of this.actionManagers)e&&!e(t)||this.scene.removeActionManager(t);for(const t of this.textures)e&&!e(t)||this.scene.removeTexture(t);for(const t of this.reflectionProbes)e&&!e(t)||this.scene.removeReflectionProbe(t)}dispose(){const e=this.cameras.slice(0);for(const t of e)t.dispose();this.cameras.length=0;const t=this.lights.slice(0);for(const e of t)e.dispose();this.lights.length=0;const s=this.meshes.slice(0);for(const e of s)e.dispose();this.meshes.length=0;const n=this.skeletons.slice(0);for(const e of n)e.dispose();this.skeletons.length=0;const r=this.animationGroups.slice(0);for(const e of r)e.dispose();this.animationGroups.length=0;const o=this.multiMaterials.slice(0);for(const e of o)e.dispose();this.multiMaterials.length=0;const i=this.materials.slice(0);for(const e of i)e.dispose();this.materials.length=0;const a=this.geometries.slice(0);for(const e of a)e.dispose();this.geometries.length=0;const h=this.transformNodes.slice(0);for(const e of h)e.dispose();this.transformNodes.length=0;const c=this.actionManagers.slice(0);for(const e of c)e.dispose();this.actionManagers.length=0;const u=this.textures.slice(0);for(const e of u)e.dispose();this.textures.length=0;const d=this.reflectionProbes.slice(0);for(const e of d)e.dispose();this.reflectionProbes.length=0;const f=this.morphTargetManagers.slice(0);for(const e of f)e.dispose();this.morphTargetManagers.length=0,this.environmentTexture&&(this.environmentTexture.dispose(),this.environmentTexture=null);for(const e of this.scene._serializableComponents)e.removeFromContainer(this,!0);this._onContextRestoredObserver&&(this.scene.getEngine().onContextRestoredObservable.remove(this._onContextRestoredObserver),this._onContextRestoredObserver=null)}_moveAssets(e,t,s){if(e&&t)for(const n of e){let e=!0;if(s)for(const t of s)if(n===t){e=!1;break}e&&(t.push(n),n._parentContainer=this)}}moveAllFromScene(e){this._wasAddedToScene=!1,void 0===e&&(e=new p);for(const t in this)Object.prototype.hasOwnProperty.call(this,t)&&(this[t]=this[t]||("_environmentTexture"===t?null:[]),this._moveAssets(this.scene[t],this[t],e[t]));this.environmentTexture=this.scene.environmentTexture,this.removeAllFromScene()}createRootMesh(){const e=new h("assetContainerRootMesh",this.scene);for(const t of this.meshes)t.parent||e.addChild(t);return this.meshes.unshift(e),e}mergeAnimationsTo(e=u.LastCreatedScene,t,n=null){if(!e)return s.Error("No scene available to merge animations to"),[];const r=n||(t=>{let s=null;const n=t.animations.length?t.animations[0].targetProperty:"",r=t.name.split(".").join("").split("_primitive")[0];switch(n){case"position":case"rotationQuaternion":s=e.getTransformNodeByName(t.name)||e.getTransformNodeByName(r);break;case"influence":s=e.getMorphTargetByName(t.name)||e.getMorphTargetByName(r);break;default:s=e.getNodeByName(t.name)||e.getNodeByName(r)}return s}),o=this.getNodes();for(const e of o){const t=r(e);if(null!==t){for(const s of e.animations){const e=t.animations.filter((e=>e.targetProperty===s.targetProperty));for(const s of e){const e=t.animations.indexOf(s,0);e>-1&&t.animations.splice(e,1)}}t.animations=t.animations.concat(e.animations)}}const i=[],a=this.animationGroups.slice();for(const e of a){i.push(e.clone(e.name,r));for(const t of e.animatables)t.stop()}for(const s of t){const t=r(s.target);t&&(e.beginAnimation(t,s.fromFrame,s.toFrame,s.loopAnimation,s.speedRatio,s.onAnimationEnd?s.onAnimationEnd:void 0,void 0,!0,void 0,s.onAnimationLoop?s.onAnimationLoop:void 0),e.stopAnimation(s.target))}return i}populateRootNodes(){this.rootNodes.length=0;for(const e of this.meshes)e.parent||-1!==this.rootNodes.indexOf(e)||this.rootNodes.push(e);for(const e of this.transformNodes)e.parent||-1!==this.rootNodes.indexOf(e)||this.rootNodes.push(e);for(const e of this.lights)e.parent||-1!==this.rootNodes.indexOf(e)||this.rootNodes.push(e);for(const e of this.cameras)e.parent||-1!==this.rootNodes.indexOf(e)||this.rootNodes.push(e)}addAllAssetsToContainer(t){if(!t)return;const s=[],n=new Set;for(s.push(t);s.length>0;){const t=s.pop();if(t instanceof h?(t.geometry&&-1===this.geometries.indexOf(t.geometry)&&this.geometries.push(t.geometry),this.meshes.push(t)):t instanceof g?this.meshes.push(t):t instanceof r?this.transformNodes.push(t):t instanceof d?this.lights.push(t):t instanceof f&&this.cameras.push(t),t instanceof e){if(t.material&&-1===this.materials.indexOf(t.material)){this.materials.push(t.material);for(const e of t.material.getActiveTextures())-1===this.textures.indexOf(e)&&this.textures.push(e)}t.skeleton&&-1===this.skeletons.indexOf(t.skeleton)&&this.skeletons.push(t.skeleton),t.morphTargetManager&&-1===this.morphTargetManagers.indexOf(t.morphTargetManager)&&this.morphTargetManagers.push(t.morphTargetManager)}for(const e of t.getChildren())n.has(e)||s.push(e);n.add(t)}this.populateRootNodes()}_getByTags(e,t,s){if(void 0===t)return e;const n=[];for(const r in e){const o=e[r];l&&l.MatchesQuery(o,t)&&(!s||s(o))&&n.push(o)}return n}getMeshesByTags(e,t){return this._getByTags(this.meshes,e,t)}getCamerasByTags(e,t){return this._getByTags(this.cameras,e,t)}getLightsByTags(e,t){return this._getByTags(this.lights,e,t)}getMaterialsByTags(e,t){return this._getByTags(this.materials,e,t).concat(this._getByTags(this.multiMaterials,e,t))}getTransformNodesByTags(e,t){return this._getByTags(this.transformNodes,e,t)}}export{M as A}; //# sourceMappingURL=assetContainer-21j7tcC8.esm.min.js.map