@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) • 27.1 kB
JavaScript
import{bh as e,y as s,a7 as t,bi as n,M as r,T as o,aI as i,aV as a,u as h,a as c,aL as u,aU as d,aY as f,bj as l}from"./index-BPURObVq.esm.min.js";class g extends e{constructor(e,s){super(e,s.getScene()),this._indexInSourceMeshInstanceArray=-1,this._distanceToCamera=0,s.addInstance(this),this._sourceMesh=s,this._unIndexed=s._unIndexed,this.position.copyFrom(s.position),this.rotation.copyFrom(s.rotation),this.scaling.copyFrom(s.scaling),s.rotationQuaternion&&(this.rotationQuaternion=s.rotationQuaternion.clone()),this.animations=s.animations.slice();for(const e of s.getAnimationRanges())null!=e&&this.createAnimationRange(e.name,e.from,e.to);if(this.infiniteDistance=s.infiniteDistance,this.setPivotMatrix(s.getPivotMatrix()),s.skeleton||s.morphTargetManager||!s.hasBoundingInfo)this.refreshBoundingInfo(!0,!0);else{const e=s.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&&s.Warn("Setting receiveShadows on an instanced mesh has no effect")}get material(){return this._sourceMesh.material}set material(e){this._sourceMesh?.material!==e&&s.Warn("Setting material on an instanced mesh has no effect")}get visibility(){return this._sourceMesh.visibility}set visibility(e){this._sourceMesh?.visibility!==e&&s.Warn("Setting visibility on an instanced mesh has no effect")}get skeleton(){return this._sourceMesh.skeleton}set skeleton(e){this._sourceMesh?.skeleton!==e&&s.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,s,t){return this._sourceMesh.getVerticesData(e,s,t)}copyVerticesData(e,s){this._sourceMesh.copyVerticesData(e,s)}getVertexBuffer(e,s){return this._sourceMesh.getVertexBuffer(e,s)}setVerticesData(e,s,t,n){return this.sourceMesh&&this.sourceMesh.setVerticesData(e,s,t,n),this.sourceMesh}updateVerticesData(e,s,t,n){return this.sourceMesh&&this.sourceMesh.updateVerticesData(e,s,t,n),this.sourceMesh}setIndices(e,s=null){return this.sourceMesh&&this.sourceMesh.setIndices(e,s),this.sourceMesh}isVerticesDataPresent(e){return this._sourceMesh.isVerticesDataPresent(e)}getIndices(){return this._sourceMesh.getIndices()}get _positions(){return this._sourceMesh._positions}refreshBoundingInfo(e=!1,s=!1){if(this.hasBoundingInfo&&this.getBoundingInfo().isLocked)return this;let n;n="object"==typeof e?e:{applySkeleton:e,applyMorph:s};const r=this._sourceMesh.geometry?this._sourceMesh.geometry.boundingBias:null;return this._refreshBoundingInfo(this._sourceMesh._getData(n,null,t.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!==n.BILLBOARDMODE_NONE&&this._currentLOD._masterMesh!==this){this._billboardWorldMatrix||(this._billboardWorldMatrix=new r);const e=this._currentLOD._masterMesh;return this._currentLOD._masterMesh=this,o.Vector3[7].copyFrom(this._currentLOD.position),this._currentLOD.position.set(0,0,0),this._billboardWorldMatrix.copyFrom(this._currentLOD.computeWorldMatrix(!0)),this._currentLOD.position.copyFrom(o.Vector3[7]),this._currentLOD._masterMesh=e,this._billboardWorldMatrix}return super.getWorldMatrix()}get isAnInstance(){return!0}getLOD(e){if(!e)return this;const s=this.sourceMesh.getLODLevels();if(s&&0!==s.length){const s=this.getBoundingInfo();this._currentLOD=this.sourceMesh.getLOD(e,s.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,s=null,t,n){const r=(n||this._sourceMesh).createInstance(e);if(i.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"],[]),s&&(r.parent=s),!t)for(let e=0;e<this.getScene().meshes.length;e++){const s=this.getScene().meshes[e];s.parent===this&&s.clone(s.name,r)}return r.computeWorldMatrix(!0),this.onClonedObservable.notifyObservers(r),r}dispose(e,s=!1){this._sourceMesh.removeInstance(this),super.dispose(e,s)}_serializeAsParent(e){super._serializeAsParent(e),e.parentId=this._sourceMesh.uniqueId,e.parentInstanceIndex=this._indexInSourceMeshInstanceArray}instantiateHierarchy(e=null,s,t){const n=this.clone("Clone of "+(this.name||this.id),e||this.parent,!0,s&&s.newSourcedMesh);n&&t&&t(this,n);for(const e of this.getChildTransformNodes(!0))e.instantiateHierarchy(n,s,t);return n}}let m=!1;function p(){m||(m=!0,a._instancedMeshFactory=(e,s)=>{const t=new g(e,s);if(s.instancedBuffers){t.instancedBuffers={};for(const e in s.instancedBuffers)t.instancedBuffers[e]=s.instancedBuffers[e]}return t},a.prototype.registerInstancedBuffer=function(e,s){if(this._userInstancedBuffersStorage?.vertexBuffers[e]?.dispose(),this._userInstancedBuffersStorage?.renderPasses)for(const s in this._userInstancedBuffersStorage.renderPasses){const t=this._userInstancedBuffersStorage.renderPasses[s];t[e]?.dispose(),delete t[e]}if(!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]=s,this._userInstancedBuffersStorage.sizes[e]=32*s,this._userInstancedBuffersStorage.data[e]=new Float32Array(this._userInstancedBuffersStorage.sizes[e]),this._userInstancedBuffersStorage.vertexBuffers[e]=this._instanceDataStorage.useMonoDataStorageRenderPass?new t(this.getEngine(),this._userInstancedBuffersStorage.data[e],e,!0,!1,s,!0):null;for(const s of this.instances)s.instancedBuffers[e]=null;this._invalidateInstanceVertexArrayObject(),this._markSubMeshesAsAttributesDirty()},a.prototype._processInstancedBuffers=function(e,s){const n=e?e.length:0,r=!this._instanceDataStorage.useMonoDataStorageRenderPass;let o;if(r){const e=this._instanceDataStorage.engine.currentRenderPassId;this._userInstancedBuffersStorage.renderPasses||(this._userInstancedBuffersStorage.renderPasses={}),this._userInstancedBuffersStorage.renderPasses[e]||(this._userInstancedBuffersStorage.renderPasses[e]={}),o=this._userInstancedBuffersStorage.renderPasses[e]}for(const i in this.instancedBuffers){let a=this._userInstancedBuffersStorage.sizes[i];const h=this._userInstancedBuffersStorage.strides[i],c=(n+1)*h;for(;a<c;)a*=2;this._userInstancedBuffersStorage.data[i].length!=a&&(this._userInstancedBuffersStorage.data[i]=new Float32Array(a),this._userInstancedBuffersStorage.sizes[i]=a,r?o[i]&&(o[i].dispose(),o[i]=null):this._userInstancedBuffersStorage.vertexBuffers[i]&&(this._userInstancedBuffersStorage.vertexBuffers[i].dispose(),this._userInstancedBuffersStorage.vertexBuffers[i]=null));const u=this._userInstancedBuffersStorage.data[i];let d=0;if(s){const e=this.instancedBuffers[i]??0;e.toArray?e.toArray(u,d):e.copyToArray?e.copyToArray(u,d):u[d]=e,d+=h}for(let s=0;s<n;s++){const t=e[s].instancedBuffers[i]??0;t.toArray?t.toArray(u,d):t.copyToArray?t.copyToArray(u,d):u[d]=t,d+=h}r?o[i]?o[i].updateDirectly(u,0):(o[i]=new t(this.getEngine(),this._userInstancedBuffersStorage.data[i],i,!0,!1,h,!0),this._invalidateInstanceVertexArrayObject()):this._userInstancedBuffersStorage.vertexBuffers[i]?this._userInstancedBuffersStorage.vertexBuffers[i].updateDirectly(u,0):(this._userInstancedBuffersStorage.vertexBuffers[i]=new t(this.getEngine(),this._userInstancedBuffersStorage.data[i],i,!0,!1,h,!0),this._invalidateInstanceVertexArrayObject())}},a.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={}}},a.prototype._disposeInstanceSpecificData=function(){for(const e in this._instanceDataStorage.renderPasses)this._instanceDataStorage.renderPasses[e].instancesBuffer?.dispose();for(this._instanceDataStorage.renderPasses={},this._instanceDataStorage.dataStorageRenderPass?.instancesBuffer?.dispose();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={}},h("BABYLON.InstancedMesh",g))}class _{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=[],this.spriteManagers=[]}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 s of this.skeletons)e=e.concat(s.bones);return e}}class M extends _{}class I{constructor(){this.rootNodes=[],this.skeletons=[],this.animationGroups=[]}dispose(){const e=this.rootNodes;for(const s of e)s.dispose();e.length=0;const s=this.skeletons;for(const e of s)e.dispose();s.length=0;const t=this.animationGroups;for(const e of t)e.dispose();t.length=0}}class y extends _{constructor(e){super(),this._wasAddedToScene=!1,(e=e||c.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();for(const e of this.spriteManagers)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 s of e){const e=s.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,s,t,n){if(t&&(!n||n(t))&&!s.has(t.uniqueId)){e.push(t),s.add(t.uniqueId);for(const r of t.getDescendants(!0))this._addNodeAndDescendantsToList(e,s,r,n)}}_isNodeInContainer(s){return s instanceof e&&-1!==this.meshes.indexOf(s)||(s instanceof n&&-1!==this.transformNodes.indexOf(s)||(s instanceof u&&-1!==this.lights.indexOf(s)||s instanceof d&&-1!==this.cameras.indexOf(s)))}_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,t){this._isValidHierarchy()||f.Warn("SceneSerializer.InstantiateModelsToScene: The Asset Container hierarchy is not valid.");const n={},r={},o=new I,i=[],h=[],c={doNotInstantiate:!0,...t},u=[],d=new Set;for(const e of this.transformNodes)null===e.parent&&this._addNodeAndDescendantsToList(u,d,e,c.predicate);for(const e of this.meshes)null===e.parent&&this._addNodeAndDescendantsToList(u,d,e,c.predicate);const l=this._topologicalSort(u),g=(t,i)=>{if(((s,t)=>{if(n[s.uniqueId]=t.uniqueId,r[t.uniqueId]=t,e&&(t.name=e(s.name)),t instanceof a){const e=t;if(e.morphTargetManager){const t=s.morphTargetManager;e.morphTargetManager=t.clone();for(let s=0;s<t.numTargets;s++){const o=t.getTarget(s),i=e.morphTargetManager.getTarget(s);n[o.uniqueId]=i.uniqueId,r[i.uniqueId]=i}}}})(t,i),t.parent){const e=n[t.parent.uniqueId],s=r[e];i.parent=s||t.parent}if(i.position&&t.position&&i.position.copyFrom(t.position),i.rotationQuaternion&&t.rotationQuaternion&&i.rotationQuaternion.copyFrom(t.rotationQuaternion),i.rotation&&t.rotation&&i.rotation.copyFrom(t.rotation),i.scaling&&t.scaling&&i.scaling.copyFrom(t.scaling),i.material){const o=i;if(o.material)if(s){const s=t.material;if(-1===h.indexOf(s)){let t=s.clone(e?e(s.name):"Clone of "+s.name);if(h.push(s),n[s.uniqueId]=t.uniqueId,r[t.uniqueId]=t,"MultiMaterial"===s.getClassName()){const o=s;for(const s of o.subMaterials)s&&(t=s.clone(e?e(s.name):"Clone of "+s.name),h.push(s),n[s.uniqueId]=t.uniqueId,r[t.uniqueId]=t);o.subMaterials=o.subMaterials.map(e=>e&&r[n[e.uniqueId]])}}"InstancedMesh"!==o.getClassName()&&(o.material=r[n[s.uniqueId]])}else"MultiMaterial"===o.material.getClassName()?-1===this.scene.multiMaterials.indexOf(o.material)&&this.scene.addMultiMaterial(o.material):-1===this.scene.materials.indexOf(o.material)&&this.scene.addMaterial(o.material)}null===i.parent&&o.rootNodes.push(i)};for(const e of l)if("InstancedMesh"===e.getClassName()){const s=e,t=s.sourceMesh,o=n[t.uniqueId];g(s,("number"==typeof o?r[o]:t).createInstance(s.name))}else{let s=!0;"TransformNode"===e.getClassName()||"Node"===e.getClassName()||e.skeleton||!e.getTotalVertices||0===e.getTotalVertices()?s=!1:c.doNotInstantiate&&(s="function"==typeof c.doNotInstantiate?!c.doNotInstantiate(e):!c.doNotInstantiate);const t=s?e.createInstance(`instance of ${e.name}`):e.clone(`Clone of ${e.name}`,null,!0);if(!t)throw new Error(`Could not clone or instantiate node on Asset Container ${e.name}`);g(e,t)}for(const s of this.skeletons){if(c.predicate&&!c.predicate(s))continue;const t=s.clone(e?e(s.name):"Clone of "+s.name);for(const e of this.meshes)if(e.skeleton===s&&!e.isAnInstance){const s=r[n[e.uniqueId]];if(!s||s.isAnInstance)continue;if(s.skeleton=t,-1!==i.indexOf(t))continue;i.push(t);for(const e of t.bones)e._linkedTransformNode&&(e._linkedTransformNode=r[n[e._linkedTransformNode.uniqueId]])}o.skeletons.push(t)}for(const s of this.animationGroups){if(c.predicate&&!c.predicate(s))continue;const t=s.clone(e?e(s.name):"Clone of "+s.name,e=>r[n[e.uniqueId]]||e);o.animationGroups.push(t)}return o}addAllToScene(){if(!this._wasAddedToScene){this._isValidHierarchy()||f.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 s=[];for(const t of this.cameras)e&&!e(t)||(this.scene.addCamera(t),s.push(t));for(const t of this.lights)e&&!e(t)||(this.scene.addLight(t),s.push(t));for(const t of this.meshes)e&&!e(t)||(this.scene.addMesh(t),s.push(t));for(const s of this.skeletons)e&&!e(s)||this.scene.addSkeleton(s);for(const s of this.animations)e&&!e(s)||this.scene.addAnimation(s);for(const s of this.animationGroups)e&&!e(s)||this.scene.addAnimationGroup(s);for(const s of this.multiMaterials)e&&!e(s)||this.scene.addMultiMaterial(s);for(const s of this.materials)e&&!e(s)||this.scene.addMaterial(s);for(const s of this.morphTargetManagers)e&&!e(s)||this.scene.addMorphTargetManager(s);for(const s of this.geometries)e&&!e(s)||this.scene.addGeometry(s);for(const t of this.transformNodes)e&&!e(t)||(this.scene.addTransformNode(t),s.push(t));for(const s of this.actionManagers)e&&!e(s)||this.scene.addActionManager(s);for(const s of this.textures)e&&!e(s)||this.scene.addTexture(s);for(const s of this.reflectionProbes)e&&!e(s)||this.scene.addReflectionProbe(s);for(const s of this.spriteManagers)e&&!e(s)||(this.scene.spriteManagers||(this.scene.spriteManagers=[]),this.scene.spriteManagers.push(s));if(s.length){const e=new Set(this.scene.meshes);for(const s of this.scene.lights)e.add(s);for(const s of this.scene.cameras)e.add(s);for(const s of this.scene.transformNodes)e.add(s);for(const s of this.skeletons)for(const t of s.bones)e.add(t);for(const t of s)t.parent&&!e.has(t.parent)&&(t.setParent?t.setParent(null):t.parent=null)}}removeAllFromScene(){this._isValidHierarchy()||f.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 s of this.cameras)e&&!e(s)||this.scene.removeCamera(s);for(const s of this.lights)e&&!e(s)||this.scene.removeLight(s);for(const s of this.meshes)e&&!e(s)||this.scene.removeMesh(s,!0);for(const s of this.skeletons)e&&!e(s)||this.scene.removeSkeleton(s);for(const s of this.animations)e&&!e(s)||this.scene.removeAnimation(s);for(const s of this.animationGroups)e&&!e(s)||this.scene.removeAnimationGroup(s);for(const s of this.multiMaterials)e&&!e(s)||this.scene.removeMultiMaterial(s);for(const s of this.materials)e&&!e(s)||this.scene.removeMaterial(s);for(const s of this.morphTargetManagers)e&&!e(s)||this.scene.removeMorphTargetManager(s);for(const s of this.geometries)e&&!e(s)||this.scene.removeGeometry(s);for(const s of this.transformNodes)e&&!e(s)||this.scene.removeTransformNode(s);for(const s of this.actionManagers)e&&!e(s)||this.scene.removeActionManager(s);for(const s of this.textures)e&&!e(s)||this.scene.removeTexture(s);for(const s of this.reflectionProbes)e&&!e(s)||this.scene.removeReflectionProbe(s);for(const s of this.spriteManagers)if((!e||e(s))&&this.scene.spriteManagers){const e=this.scene.spriteManagers.indexOf(s);-1!==e&&this.scene.spriteManagers.splice(e,1)}}dispose(){const e=this.cameras.slice(0);for(const s of e)s.dispose();this.cameras.length=0;const s=this.lights.slice(0);for(const e of s)e.dispose();this.lights.length=0;const t=this.meshes.slice(0);for(const e of t)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;const l=this.spriteManagers.slice(0);for(const e of l)e.dispose();this.spriteManagers.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,s,t){if(e&&s)for(const n of e){let e=!0;if(t)for(const s of t)if(n===s){e=!1;break}e&&(s.push(n),n._parentContainer=this)}}moveAllFromScene(e){this._wasAddedToScene=!1,void 0===e&&(e=new M);for(const s in this)Object.prototype.hasOwnProperty.call(this,s)&&(this[s]=this[s]||("_environmentTexture"===s?null:[]),this._moveAssets(this.scene[s],this[s],e[s]));this.environmentTexture=this.scene.environmentTexture,this.removeAllFromScene()}createRootMesh(){const e=new a("assetContainerRootMesh",this.scene);for(const s of this.meshes)s.parent||e.addChild(s);return this.meshes.unshift(e),e}mergeAnimationsTo(e=c.LastCreatedScene,t,n=null){if(!e)return s.Error("No scene available to merge animations to"),[];const r=n||(s=>{let t;const n=s.animations.length?s.animations[0].targetProperty:"",r=s.name.split(".").join("").split("_primitive")[0];switch(n){case"position":case"rotationQuaternion":t=e.getTransformNodeByName(s.name)||e.getTransformNodeByName(r);break;case"influence":t=e.getMorphTargetByName(s.name)||e.getMorphTargetByName(r);break;default:t=e.getNodeByName(s.name)||e.getNodeByName(r)}return t}),o=this.getNodes();for(const e of o){const s=r(e);if(null!==s){for(const t of e.animations){const e=s.animations.filter(e=>e.targetProperty===t.targetProperty);for(const t of e){const e=s.animations.indexOf(t,0);e>-1&&s.animations.splice(e,1)}}s.animations=s.animations.concat(e.animations)}}const i=[],a=this.animationGroups.slice();for(const e of a){i.push(e.clone(e.name,r));for(const s of e.animatables)s.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(s){if(!s)return;const t=[],r=new Set;for(t.push(s);t.length>0;){const s=t.pop();if(s instanceof a?(s.geometry&&-1===this.geometries.indexOf(s.geometry)&&this.geometries.push(s.geometry),this.meshes.push(s)):s instanceof g?this.meshes.push(s):s instanceof n?this.transformNodes.push(s):s instanceof u?this.lights.push(s):s instanceof d&&this.cameras.push(s),s instanceof e){if(s.material&&-1===this.materials.indexOf(s.material)){this.materials.push(s.material);for(const e of s.material.getActiveTextures())-1===this.textures.indexOf(e)&&this.textures.push(e)}s.skeleton&&-1===this.skeletons.indexOf(s.skeleton)&&this.skeletons.push(s.skeleton),s.morphTargetManager&&-1===this.morphTargetManagers.indexOf(s.morphTargetManager)&&this.morphTargetManagers.push(s.morphTargetManager)}for(const e of s.getChildren())r.has(e)||t.push(e);r.add(s)}this.populateRootNodes()}_getByTags(e,s,t){if(void 0===s)return e;const n=[];for(const r in e){const o=e[r];l&&l.MatchesQuery(o,s)&&(!t||t(o))&&n.push(o)}return n}getMeshesByTags(e,s){return this._getByTags(this.meshes,e,s)}getCamerasByTags(e,s){return this._getByTags(this.cameras,e,s)}getLightsByTags(e,s){return this._getByTags(this.lights,e,s)}getMaterialsByTags(e,s){return this._getByTags(this.materials,e,s).concat(this._getByTags(this.multiMaterials,e,s))}getTransformNodesByTags(e,s){return this._getByTags(this.transformNodes,e,s)}}export{y as A,g as I,p as R};
//# sourceMappingURL=assetContainer-CAncviZo.esm.min.js.map