u-space 0.0.31 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -13,4 +13,4 @@
13
13
  border-radius: 4px;
14
14
  pointer-events: auto;
15
15
  white-space: nowrap;
16
- `,t.labelStyle)for(const h of Object.keys(t.labelStyle)){const d=t.labelStyle[h];d!==void 0&&(r.style[h]=d)}let a=null;const c=t.labelOffset||{x:0,y:2,z:0};if(t.showLeaderLine!==!1){const{lineColor:h=16777215}=t,d=new o.BufferGeometry().setFromPoints([new o.Vector3(0,0,0),new o.Vector3(c.x,c.y,c.z)]),u=new o.LineBasicMaterial({color:h});a=new o.Line(d,u),s.add(a)}if(this._createCSSObject){const h=this._createCSSObject(r);h.position.set(c.x,c.y,c.z),s.add(h)}this.scene.add(s);const l={id:e,options:t,group:s,labelElement:r,line:a};return this.annotations.set(e,l),l}addText(e,t,s={}){const n=`annotation_${this._idCounter++}`;return this.add(n,{position:t,content:e,...s})}updateContent(e,t){const s=this.annotations.get(e);s&&(s.labelElement.innerHTML=t,s.options.content=t)}updatePosition(e,t){const s=this.annotations.get(e);s&&(s.group.position.set(t.x,t.y,t.z),s.options.position=t)}show(e){const t=this.annotations.get(e);t&&(t.group.visible=!0)}hide(e){const t=this.annotations.get(e);t&&(t.group.visible=!1)}get(e){return this.annotations.get(e)}remove(e){const t=this.annotations.get(e);if(t){const s=[...t.group.children];for(const n of s)t.group.remove(n),n.geometry?.dispose(),n.material?.dispose();this.scene.remove(t.group),this.annotations.delete(e)}}removeAll(){const e=Array.from(this.annotations.keys());for(const t of e)this.remove(t)}showAll(){for(const e of this.annotations.values())e.group.visible=!0}hideAll(){for(const e of this.annotations.values())e.group.visible=!1}keys(){return Array.from(this.annotations.keys())}get size(){return this.annotations.size}dispose(){this.removeAll()}}const Te=new o.Matrix4,vs=1e-6,Is=1e-6,De="uSpaceInstanceOriginalMaterialState",ye=0,ae=1,ft=2;function Cs(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Bs(i,e){const t=i.elements,s=e.elements;for(let n=0;n<16;n++)if(Math.abs(t[n]-s[n])>vs)return!1;return!0}function mt(i){const e=i.material;return Array.isArray(e)?e:[e]}function gt(i){const e=i.userData,t=e[De];if(t)return t;const s={transparent:i.transparent,opacity:i.opacity};return e[De]=s,s}function Os(i,e){i.traverse(t=>{const s=t;s.isMesh&&mt(s).forEach(n=>{if(!n)return;const r=n,a=gt(r),c=a.opacity*e;r.transparent=a.transparent||c<1,r.opacity=c,r.needsUpdate=!0})})}function As(i){i.traverse(e=>{const t=e;t.isMesh&&mt(t).forEach(s=>{if(!s)return;const n=s,r=gt(n);n.transparent=r.transparent,n.opacity=r.opacity,n.needsUpdate=!0})})}class _s extends q{isInstanceObject=!0;type="InstanceObject";instanceId="";instanceKind="";instanceName="";geometry=new o.BufferGeometry;boundingBox=null;boundingSphere=null;#s={color:null,colorMode:ye,opacity:1};#a=null;#t=null;#e=null;#r=null;#n=new Set;#o=new o.Matrix4;#c=!1;#l=!0;#d=!1;#u;constructor(e={}){super(),this.#u=e.boundsName??"InstanceBounds"}setInstanceIdentity(e){let t=!1;if(e.id!==void 0){const s=e.id??"";this.instanceId!==s&&(this.instanceId=s,t=!0)}if(e.kind!==void 0){const s=e.kind??"";this.instanceKind!==s&&(this.instanceKind=s,t=!0)}if(e.name!==void 0){const s=e.name??"";this.instanceName!==s&&(this.instanceName=s,t=!0)}return t&&this.markInstanceRenderDirty(),this}setInstanceBounds(e){if(e.isEmpty())return this;this.#t&&this.remove(this.#t);const t=new o.BufferGeometry;t.boundingBox=e.clone();const s=new o.Object3D;return s.name=this.#u,s.visible=!1,s.geometry=t,s.raycast=()=>{},this.#t=s,this.add(s),this.#h(),this.markInstanceRenderDirty(),this}setInstanceRenderObject(e){return this.#e&&this.#e!==e&&this.#e.parent===this&&this.remove(this.#e),this.#e=e,e&&e.parent!==this&&this.add(e),this.#f(),this.#h(),this.markInstanceRenderDirty(),this}getInstanceRenderObject(){return this.#e}setInstanceMaterializer(e){return this.#r=e,this}hasInstanceMaterializer(e){return this.#r===e}clearInstanceMaterializer(e){return(e===void 0||this.#r===e)&&(this.#r=null),this}materialize(){return this.#r?.()??this.#e??null}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new o.Box3),this.getInstanceBoundingBox(this.boundingBox,!1)}computeBoundingSphere(){if(this.boundingSphere===null&&(this.boundingSphere=new o.Sphere),this.boundingBox===null&&this.computeBoundingBox(),!this.boundingBox||this.boundingBox.isEmpty()){this.boundingSphere.makeEmpty();return}this.boundingBox.getBoundingSphere(this.boundingSphere)}getInstanceBoundingBox(e=new o.Box3,t=!1){const s=this.#t?.geometry?.boundingBox;return s?(e.copy(s),t&&(this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)),e):this.#e?(e.setFromObject(this.#e),t||(this.updateWorldMatrix(!0,!1),Te.copy(this.matrixWorld).invert(),e.applyMatrix4(Te)),e):e.makeEmpty()}setInstanceVisible(e){return this.visible===e?this:(this.visible=e,this.markInstanceRenderDirty(),this)}setInstanceColor(e){return this.#s.color=new o.Color(e),this.#s.colorMode=ae,this.#f(),this.markInstanceRenderDirty(),this}resetInstanceColor(){return this.#s.color===null?this:(this.#s.color=null,this.#s.colorMode=ye,this.#f(),this.markInstanceRenderDirty(),this)}setInstanceOpacity(e){const t=Math.max(0,Math.min(1,e));return Math.abs(this.#s.opacity-t)<=Is?this:(this.#s.opacity=t,this.#f(),this.markInstanceRenderDirty(),this)}getInstanceColor(e=new o.Color){const t=this.#p();return t.color?e.copy(t.color):e.setRGB(1,1,1)}hasInstanceColor(){return this.#p().color!==null}getInstanceOpacity(){return this.#p().opacity}setInstanceHighlight(e,t,s=!1){return this.#a={color:new o.Color(e),colorMode:s?ae:ft,opacity:Math.max(0,Math.min(1,t))},this.#f(),this.markInstanceRenderDirty(),this}clearInstanceHighlight(){return this.#a===null?this:(this.#a=null,this.#f(),this.markInstanceRenderDirty(),this)}getInstanceColorMode(){return this.#p().colorMode}onInstanceRenderDirty(e){return this.#n.add(e),()=>this.#n.delete(e)}markInstanceRenderDirty(){return this.#n.forEach(e=>e()),this}updateMatrixWorld(e){super.updateMatrixWorld(e),this.#i()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.#i()}#i(){const e=Cs(this);(!this.#c||!Bs(this.matrixWorld,this.#o)||!this.#d||e!==this.#l)&&(this.#c=!0,this.#d=!0,this.#o.copy(this.matrixWorld),this.#l=e,this.markInstanceRenderDirty())}#h(){this.boundingBox=null,this.boundingSphere=null}#p(){return this.#a??this.#s}#f(){if(!this.#e)return;const e=this.#p();if(e.color){As(this.#e),H.highlightColor(this.#e,{color:e.color,opacity:e.opacity,overwrite:e.colorMode===ae,multiplyOpacity:!0});return}H.removeHighlightColor(this.#e),Os(this.#e,e.opacity)}}function Ls(i){return i.isInstanceObject===!0}const Ts=new Set(["MeshBasicMaterial","MeshLambertMaterial","MeshPhongMaterial","MeshStandardMaterial","MeshPhysicalMaterial"]),Ne=new WeakMap;let Ds=1;const Re=new o.Matrix4,Z=new o.Matrix4,Pe=new o.Matrix4;function Ns(i,e,t=1e-6){const s=i.elements,n=e.elements;for(let r=0;r<16;r++)if(Math.abs(s[r]-n[r])>t)return!1;return!0}function yt(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Rs(i){const e=i.source.data;if(!e||typeof e!="object"&&typeof e!="function")return`texture:${i.uuid}`;let t=Ne.get(e);return t===void 0&&(t=Ds++,Ne.set(e,t)),`source:${t}`}function Ps(i){return JSON.stringify([Rs(i),i.mapping,i.channel,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.anisotropy,i.format,i.internalFormat,i.type,i.offset.toArray(),i.repeat.toArray(),i.center.toArray(),i.rotation,i.matrixAutoUpdate,i.matrix.toArray(),i.generateMipmaps,i.premultiplyAlpha,i.flipY,i.unpackAlignment,i.colorSpace,"compareFunction"in i?i.compareFunction:null])}function be(i){if(Array.isArray(i))return i.map(be);if(!i||typeof i!="object")return i;const e=i;return Object.fromEntries(Object.keys(e).sort().map(t=>[t,be(e[t])]))}function we(i,e){if(Array.isArray(i))return i.map(s=>we(s,e));if(!i||typeof i!="object")return typeof i=="string"?e.get(i)??i:i;const t=i;return Object.fromEntries(Object.keys(t).filter(s=>s!=="metadata"&&s!=="uuid"&&s!=="name").sort().map(s=>[s,we(t[s],e)]))}function ks(i){if(!Ts.has(i.type)||i.transparent||i.opacity<.999||i.visible===!1)return null;const e=i;if(Object.keys(e).some(r=>r.endsWith("Node")&&e[r]!=null)||Object.hasOwn(i,"onBeforeCompile"))return null;const t=new Map;Object.values(e).forEach(r=>{r instanceof o.Texture&&t.set(r.uuid,Ps(r))});const s={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n=i.toJSON(s);return JSON.stringify(be(we(n,t)))}function js(i){if(Object.keys(i.morphAttributes).length>0||i.drawRange.start!==0||i.drawRange.count!==1/0)return null;const e=Object.entries(i.attributes).sort(([t],[s])=>t.localeCompare(s)).map(([t,s])=>"isInterleavedBufferAttribute"in s?null:[t,s.itemSize,s.normalized,s.array.constructor.name,s.gpuType]);return e.some(t=>t===null)?null:JSON.stringify([i.index?.array.constructor.name??"non-indexed",e])}function Us(i,e){const t=[],s=new Set,n=new Set,r=!e&&(i.animations.length>0||i.mixer!==null);return r&&n.add("animation"),i.updateWorldMatrix(!0,!0),Re.copy(i.matrixWorld).invert(),i.traverseVisible(a=>{if(!(a instanceof o.Mesh))return;if(r){s.add(a);return}if(a instanceof o.SkinnedMesh){s.add(a),n.add("skinned");return}if(a.morphTargetInfluences){s.add(a),n.add("morph");return}if(Array.isArray(a.material)){s.add(a),n.add("material-array");return}const c=ks(a.material),l=js(a.geometry);if(!c){s.add(a),n.add(a.material.transparent||a.material.opacity<.999?"transparent":`material:${a.material.type}`);return}if(!l){s.add(a),n.add("geometry-layout");return}if(a.matrixWorld.determinant()<=0){s.add(a),n.add("negative-scale");return}t.push({mesh:a,localMatrix:Re.clone().multiply(a.matrixWorld),materialKey:c,geometryKey:l})}),t.length===0&&s.size===0&&n.add("empty"),{meshes:t,fallbackMeshes:s,fallbackReasons:n}}function zs(i,e){const t=Me.clone(i),s=[],n=[];return i.traverse(r=>{r instanceof o.Mesh&&s.push(r)}),t.traverse(r=>{r instanceof o.Mesh&&n.push(r)}),s.forEach((r,a)=>{e.has(r)&&n[a]&&(n[a].visible=!1)}),t}function Fs(i){const e=Me.clone(i),t=new Map,s=n=>{let r=t.get(n);return r||(r=n.clone(),t.set(n,r)),r};return e.traverse(n=>{n instanceof o.Mesh&&(n.material=Array.isArray(n.material)?n.material.map(s):s(n.material))}),e}function Ws(i){return Math.max(1,Math.ceil(Math.sqrt(Math.max(1,i))))}function Gs(i){const e=new o.DataTexture(new Float32Array(i*i*4),i,i,o.RGBAFormat,o.FloatType);return e.magFilter=o.NearestFilter,e.minFilter=o.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e}function Hs(i,e){const t=i.clone(),s=g.attribute("batchObjectIndex","float").toInt(),n=g.int(g.textureSize(g.textureLoad(e),g.int(0)).x).toConst(),r=s.mod(n).toConst(),a=s.div(n).toConst(),c=g.textureLoad(e,g.ivec2(r,a)),l=t.colorNode??g.materialColor,h=g.select(c.a.greaterThan(1.5),l.mul(c.rgb),c.rgb);return t.colorNode=g.select(c.a.greaterThan(.5),h,l),t.maskNode=c.a.greaterThan(-.5),t.needsUpdate=!0,t}function ke(i){let e=0,t=i.parent;for(;t;)e++,t=t.parent;return e}class $s extends F{objectIndices;states;#s;constructor(e,t,s,n){super(e,t),this.objectIndices=s,this.states=n,this.userData.editableGeometryBatch=!0}raycast(e,t){if(this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0)return!1;this.#s===void 0&&(this.#s=j.getGeometryBoundsTree(this.geometry));const s=[];this.#s?this.#s.raycastObject3D(this,e,s):super.raycast(e,s),s.forEach(n=>{const r=n.faceIndex;if(r==null)return;const a=r*3,c=this.geometry.index?.getX(a)??a,l=this.objectIndices[c],h=l===void 0?void 0:this.states[l],d=h?.instance;!h||h.materialized||!d||!yt(d)||d.getInstanceOpacity()<=.001||(n.object=d,n.batchObjectIndex=l,t.push(n))})}}class Vs extends q{isEditableGeometryBatchLayer=!0;type="EditableGeometryBatchLayer";options;stats={instances:0,sourceMeshes:0,batches:0,drawCallsSaved:0,vertices:0,indices:0,unsupportedInstances:0,unsupportedByReason:{}};#s=[];#a=new Set;#t=[];#e=new Map;#r=new Set;#n=null;#o=new o.Matrix4;#c=!1;#l=!1;#d=!1;constructor(e={}){super(),this.name="EditableGeometryBatches",this.options={maxVerticesPerBatch:e.maxVerticesPerBatch??15e5,maxIndicesPerBatch:e.maxIndicesPerBatch??45e5,freezeAnimations:e.freezeAnimations??!1}}addSource(e){if(this.#l)throw new Error("EditableGeometryBatchLayer has been disposed.");if(this.#c)throw new Error("EditableGeometryBatchLayer has already been built.");const{key:t,template:s,instances:n}=e,r=new Set;n.forEach(h=>{if(r.has(h)||this.#a.has(h))throw new Error("EditableGeometryBatchLayer cannot batch the same InstanceObject more than once.");r.add(h)});const{meshes:a,fallbackMeshes:c,fallbackReasons:l}=Us(s,this.options.freezeAnimations);return r.forEach(h=>this.#a.add(h)),this.#s.push({key:t,template:s,instances:[...n],meshes:a,fallbackMeshes:c,fallbackReasons:l,bounds:new o.Box3().setFromObject(s)}),a.length>0}build(){if(this.#l)throw new Error("EditableGeometryBatchLayer has been disposed.");if(this.#c)throw new Error("EditableGeometryBatchLayer.build() can only be called once.");this.#c=!0,this.updateWorldMatrix(!0,!1),this.#o.copy(this.matrixWorld).invert();const e=[],t=new Map,s=(r,a,c,l)=>{if(c.length===0)return;const h=l.size>0?[...l]:["unknown"];e.push({key:r.key,template:a,instances:c,reasons:h}),h.forEach(d=>{this.stats.unsupportedByReason[d]=(this.stats.unsupportedByReason[d]??0)+c.length})};this.#s.forEach(r=>{const a=[],c=[];r.instances.forEach(h=>{h.updateWorldMatrix(!0,!1),Z.multiplyMatrices(this.#o,h.matrixWorld),Z.determinant()<=0?c.push(h):a.push({instance:h,matrix:Z.clone()})});const l=r.fallbackReasons.size>0?r.fallbackReasons:new Set(["unknown"]);if(r.meshes.length===0){s(r,r.template,a.map(({instance:h})=>h),l),s(r,r.template,c,new Set([...l,"negative-scale"]));return}r.fallbackMeshes.size>0&&s(r,zs(r.template,new Set(r.meshes.map(({mesh:h})=>h))),a.map(({instance:h})=>h),l),s(r,r.template,c,new Set([...r.fallbackReasons,"negative-scale"])),a.forEach(({instance:h,matrix:d})=>{const u=this.#t.length,p=()=>this.materialize(h),f={instance:h,template:r.template,initialMatrix:d,objectIndex:u,materialized:!1,materializer:p,unsubscribe:()=>{}};f.unsubscribe=h.onInstanceRenderDirty(()=>this.#h(f)),this.#t.push(f),this.#e.set(h,f),h.setInstanceBounds(r.bounds),h.setInstanceMaterializer(p),this.#r.add(f),r.meshes.forEach(({mesh:S,localMatrix:C,materialKey:D,geometryKey:O})=>{Pe.multiplyMatrices(d,C);const w=S.geometry.clone().applyMatrix4(Pe),x=w.getAttribute("position");w.setAttribute("batchObjectIndex",new o.Float32BufferAttribute(new Float32Array(x.count).fill(u),1));const b=JSON.stringify([D,O,S.castShadow,S.receiveShadow,S.renderOrder]),y=t.get(b),E={geometry:w,material:S.material,castShadow:S.castShadow,receiveShadow:S.receiveShadow,renderOrder:S.renderOrder,objectIndices:new Array(x.count).fill(u)};y?y.push(E):t.set(b,[E]),this.stats.sourceMeshes++,this.stats.vertices+=x.count,this.stats.indices+=w.index?.count??x.count})})}),this.stats.instances=this.#t.length,this.stats.unsupportedInstances=e.reduce((r,a)=>r+a.instances.length,0);const n=Ws(this.#t.length);return this.#n=Gs(n),this.#i(),t.forEach(r=>this.#u(r)),this.stats.batches=this.children.length,this.stats.drawCallsSaved=Math.max(0,this.stats.sourceMeshes-this.stats.batches),this.children.forEach(r=>{r instanceof o.Mesh&&(r.onBeforeRender=()=>this.#i())}),{stats:{...this.stats},unsupported:e}}materialize(e){const t=this.#e.get(e);if(!t||t.materialized)return e.getInstanceRenderObject();const s=Fs(t.template);return s.position.set(0,0,0),s.quaternion.identity(),s.scale.set(1,1,1),s.matrix.identity(),t.materialized=!0,e.setInstanceRenderObject(s),s.updateWorldMatrix(!0,!0),this.#r.add(t),this.dispatchEvent({type:"materialize",instance:e,object:s}),s}#u(e){const t=[];let s=[],n=0,r=0;e.forEach(a=>{const c=a.geometry.getAttribute("position").count,l=a.geometry.index?.count??c;s.length>0&&(n+c>this.options.maxVerticesPerBatch||r+l>this.options.maxIndicesPerBatch)&&(t.push(s),s=[],n=0,r=0),s.push(a),n+=c,r+=l}),s.length>0&&t.push(s),t.forEach(a=>{const c=Ot.mergeGeometries(a.map(p=>p.geometry),!1);if(a.forEach(p=>p.geometry.dispose()),!c||!this.#n)return;c.computeBoundingBox(),c.computeBoundingSphere();const l=a[0],h=a.flatMap(p=>p.objectIndices),d=Hs(l.material,this.#n),u=new $s(c,d,h,this.#t);u.name=`EditableGeometryBatch:${this.children.length}`,u.castShadow=l.castShadow,u.receiveShadow=l.receiveShadow,u.renderOrder=l.renderOrder,u.matrixAutoUpdate=!1,this.add(u)})}#i(){if(!(!this.#n||this.#r.size===0||this.#d)){this.#d=!0;try{this.updateWorldMatrix(!0,!1),this.#o.copy(this.matrixWorld).invert();const e=this.#n.image.data;[...this.#r].sort((t,s)=>ke(t.instance)-ke(s.instance)).forEach(t=>{const{instance:s,objectIndex:n}=t;s.updateWorldMatrix(!0,!1),Z.multiplyMatrices(this.#o,s.matrixWorld),!t.materialized&&s.getInstanceRenderObject()!==null&&!s.hasInstanceMaterializer(t.materializer)&&(t.materialized=!0),!t.materialized&&!Ns(Z,t.initialMatrix)&&this.materialize(s),!t.materialized&&s.getInstanceOpacity()<.999&&this.materialize(s);const r=n*4,a=!t.materialized&&yt(s)&&s.getInstanceOpacity()>.001,c=s.getInstanceColor();e[r]=c.r,e[r+1]=c.g,e[r+2]=c.b,e[r+3]=a?s.getInstanceColorMode():-1,this.#r.delete(t)}),this.#n.needsUpdate=!0}finally{this.#d=!1}this.#r.size>0&&this.#i()}}#h(e){this.#r.add(e),this.#i()}dispose(){this.#l||(this.#l=!0,this.#t.forEach(e=>{e.unsubscribe(),e.instance.clearInstanceMaterializer(e.materializer)}),this.#t.length=0,this.#e.clear(),this.#a.clear(),this.#r.clear(),this.#s.length=0,this.#n?.dispose(),this.#n=null,this.traverse(e=>{if(!(e instanceof o.Mesh))return;e.geometry.dispose(),(Array.isArray(e.material)?e.material:[e.material]).forEach(s=>s.dispose())}),this.clear())}}const je=new o.Matrix4,re=new o.Matrix4,Ue=new o.Matrix4,ze=new o.Matrix4,Fe=new o.Box3,We=new o.Sphere,Ge=new o.Sphere,Ks=new o.Frustum,V=new o.Color,He=new o.Vector2,$e=new o.Vector3,Ve=new o.Matrix4,Ke=new o.Matrix4,qe=new o.Sphere,ie=[],bt=1e-6,U=1e-6,wt=.999,qs=0,Xe=1;function Xs(i,e,t){const s=i.elements;for(let n=0;n<16;n++)if(Math.abs(s[n]-e[t+n])>bt)return!1;return!0}function Ys(i,e,t,s){return Math.abs(i.r-t[s])<=U&&Math.abs(i.g-t[s+1])<=U&&Math.abs(i.b-t[s+2])<=U&&Math.abs(e-t[s+3])<=U}function Ye(i,e){const t=i.elements,s=e.elements;for(let n=0;n<16;n++)if(Math.abs(t[n]-s[n])>bt)return!1;return!0}function ue(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Qs(i){const e=i.geometry.morphAttributes;return Object.values(e).some(t=>t?.length)}function Js(i){const e=i.material;if(!Array.isArray(e))return!0;if(e.length===0||!e.every(Boolean))return!1;const t=i.geometry.groups;return t.length===0?!1:t.every(s=>{const n=s.materialIndex??0;return Number.isInteger(s.start)&&s.start>=0&&Number.isInteger(s.count)&&s.count>0&&Number.isInteger(n)&&n>=0&&n<e.length})}function Zs(i){return!i.isSkinnedMesh&&!Qs(i)&&Js(i)}function Qe(i){return Array.isArray(i)?i:[i]}function Mt(i){return i.transparent||i.opacity<wt}function Je(i,e,t){const s=i.clone(),n=g.instancedBufferAttribute(e,"vec4",4,0),r=g.instancedBufferAttribute(t,"float",1,0),a=s.colorNode??g.materialColor,c=s.opacityNode?g.float(s.opacityNode):g.materialOpacity,l=g.select(n.a.greaterThan(1.5),a.mul(n.rgb),n.rgb);return s.colorNode=g.select(n.a.greaterThan(.5),l,a),s.opacityNode=c.mul(r),s.transparent=Mt(i),s.needsUpdate=!0,s}function en(i,e,t){return Array.isArray(i)?i.map(s=>Je(s,e,t)):Je(i,e,t)}function tn(i){const e=[],t=new o.Matrix4;let s=!1;return i.updateWorldMatrix(!0,!0),t.copy(i.matrixWorld).invert(),i.traverse(n=>{if(!s&&!(!(n instanceof o.Mesh)||!n.visible)){if(!Zs(n)){s=!0;return}n.updateWorldMatrix(!0,!1),e.push({mesh:n,localMatrix:t.clone().multiply(n.matrixWorld)})}}),s?[]:e}function sn(i){const e=new o.Box3;return i.forEach(({mesh:t,localMatrix:s})=>{const n=t.geometry;n.boundingBox||n.computeBoundingBox(),n.boundingBox&&(Fe.copy(n.boundingBox).applyMatrix4(s),e.union(Fe))}),e}function K(i){const e=i;"needsUpdate"in e&&(e.needsUpdate=!0)}function Ze(i,e=Xe){let t=Math.max(Xe,e);for(;t<i;)t*=2;return t}function nn(i){return i!==null&&typeof i=="object"&&Symbol.iterator in i}class rn extends q{isModelInstancedLayer=!0;type="ModelInstancedLayer";#s=[];#a=new Map;#t=new Map;#e=new Map;#r=!0;#n=!1;#o=!0;#c=qs;#l;#d;constructor(e={}){super(),this.name=e.name??"ModelInstances",this.#l=e.instanceKind??"",this.#d=e.getHitUserData??(()=>({}))}get instanceKind(){return this.#l}getInstances(){const e=[];return this.#i(t=>e.push(t)),e}getInstanceById(e){return this.#w(),this.#e.get(e)}hasInstance(e){return this.#w(),this.#e.has(e)}getInstanceCulling(){return{enabled:this.#n,frustum:this.#o,minScreenRadius:this.#c}}setInstanceCulling(e={}){let t=!1;if(e.enabled!==void 0&&this.#n!==e.enabled&&(this.#n=e.enabled,t=!0),e.frustum!==void 0&&this.#o!==e.frustum&&(this.#o=e.frustum,t=!0),e.minScreenRadius!==void 0){const s=Math.max(0,e.minScreenRadius);Math.abs(this.#c-s)>U&&(this.#c=s,t=!0)}return t&&this.#s.forEach(s=>this.#v(s)),this}setInstanceVisible(e){return this.visible!==e&&(this.visible=e),this.#i(t=>{t.setInstanceVisible(e)}),this}setInstanceColor(e){return this.#i(t=>{t.setInstanceColor(e)}),this}resetInstanceColor(){return this.#i(e=>{e.resetInstanceColor()}),this}setInstanceOpacity(e){return this.#i(t=>{t.setInstanceOpacity(e)}),this}setInstanceHighlight(e,t,s=!1){return this.#i(n=>{n.setInstanceHighlight(e,t,s)}),this}clearInstanceHighlight(){return this.#i(e=>{e.clearInstanceHighlight()}),this}reserveBatch(e,t,s){const n=Math.floor(s);return n<=0?!1:this.#u(e,t,n)!==null}addInstance(e,t,s){return this.addInstances(e,t,[s])}addInstances(e,t,s){if(s.length===0)return!1;const n=this.#a.has(e),r=this.#u(e,t,s.length);if(!r)return!1;const a=[],c=new Set;return s.forEach(l=>{c.has(l)||(c.add(l),this.#t.get(l)===r)||a.push(l)}),a.length===0?!0:this.#C(a)?(a.forEach(l=>{const h=this.#t.get(l);h&&h!==r&&this.#S(h,l)}),this.#x(r,r.instances.length+a.length),a.forEach(l=>{l.setInstanceBounds(r.templateBounds),r.instances.push(l),this.#t.set(l,r),r.unsubscribeByInstance.set(l,l.onInstanceRenderDirty(()=>{this.#g(),this.#y(r)}))}),this.#g(),this.#b(r),this.#y(r),!0):(!n&&r.instances.length===0&&this.#m(r),!1)}removeInstance(e){return this.removeInstances([e])>0}removeInstances(e){const t=new Set,s=new Set,n=typeof e=="string"||!nn(e)?[e]:e;for(const a of n)typeof a=="string"?t.add(a):this.#t.has(a)&&s.add(a);t.size>0&&(this.#w(),t.forEach(a=>{const c=this.#e.get(a);c&&s.add(c)}));let r=0;return s.forEach(a=>{const c=this.#t.get(a);c&&this.#S(c,a)&&r++}),r}removeBatch(e){const t=this.#a.get(e);return t?(this.#m(t),!0):!1}clearBatches(){return[...this.#a.values()].forEach(e=>this.#m(e)),this}#u(e,t,s){const n=this.#a.get(e);if(n)return this.#x(n,s),n;if(t.animations?.length)return null;const r=tn(t);if(r.length===0)return null;const a=sn(r),c=new o.Group;c.name=e,this.add(c);const l={url:e,batch:c,templateMeshes:r,templateBounds:a,records:[],instances:[],unsubscribeByInstance:new Map,capacity:Ze(s)};return r.forEach(({mesh:h,localMatrix:d},u)=>{const p=this.#h(l,h,d,u);l.records.push(p),this.#s.push(p)}),this.#a.set(e,l),this.#b(l),l}#i(e){const t=new Set;this.#a.forEach(s=>{s.instances.forEach(n=>{t.has(n)||(t.add(n),e(n))})})}#h(e,t,s,n){const r=new o.InstancedBufferAttribute(new Float32Array(e.capacity*4),4),a=new o.InstancedBufferAttribute(new Float32Array(e.capacity).fill(1),1);r.setUsage(o.DynamicDrawUsage),a.setUsage(o.DynamicDrawUsage);const c=en(t.material,r,a),l=Qe(c),h=Qe(t.material).some(Mt),d=new o.InstancedMesh(t.geometry,c,e.capacity);d.instanceMatrix=new o.StorageInstancedBufferAttribute(e.capacity,16),d.count=0,d.name=t.name||`${e.url}#${n}`,d.castShadow=t.castShadow,d.receiveShadow=t.receiveShadow,d.frustumCulled=!0,d.matrixAutoUpdate=!1,d.instanceMatrix.setUsage(o.DynamicDrawUsage),d.userData.url=e.url;const u=new o.Mesh(t.geometry,c);u.matrixAutoUpdate=!1;const p={batchRecord:e,mesh:d,boundsTree:void 0,raycastMesh:u,localMatrix:s.clone(),fullBoundingSphere:new o.Sphere,materials:l,hasSourceTransparency:h,colorAttribute:r,opacityAttribute:a,renderedInstances:[],visibleInstances:[],lastCameraMatrixWorldInverse:new o.Matrix4,lastCameraProjectionMatrix:new o.Matrix4,lastViewportHeight:0,hasLastCameraState:!1,dirty:!0};d.userData.getInstanceObjectByRenderIndex=S=>p.renderedInstances[S],d.userData.raycastAcceleration="lazy";const f=d.raycast.bind(d);return d.raycast=(S,C)=>{if(this.#I(p),!this.#p(p,S))return;p.boundsTree===void 0&&(p.boundsTree=j.getGeometryBoundsTree(p.mesh.geometry),p.mesh.userData.raycastAcceleration=p.boundsTree?"three-mesh-bvh":"default");const D=C.length;p.boundsTree?this.#f(p,S,C):f(S,C);for(let O=D;O<C.length;){const w=C[O],x=w.instanceId;if(x===void 0){O++;continue}const b=p.renderedInstances[x];if(!b||!ue(b)){C.splice(O,1);continue}w.object=b,w.instanceObject=b,w.instanceObjectId=b.instanceId,w.instanceKind=b.instanceKind||this.#l,w.instanceName=b.instanceName,w.instanceIndex=x,Object.assign(w,this.#d(b,x)),O++}},d.onBeforeRender=(S,C,D)=>this.#I(p,S,D),e.batch.add(d),p}#p(e,t){const{mesh:s}=e;return s.count===0?!1:(s.boundingSphere===null&&s.computeBoundingSphere(),s.boundingSphere?(qe.copy(s.boundingSphere).applyMatrix4(s.matrixWorld),t.ray.intersectsSphere(qe)):!0)}#f(e,t,s){const{mesh:n,boundsTree:r,raycastMesh:a}=e;if(!(!r||n.count===0)){a.geometry=n.geometry,a.material=n.material;for(let c=0;c<n.count;c++)n.getMatrixAt(c,Ve),Ke.multiplyMatrices(n.matrixWorld,Ve),a.matrixWorld.copy(Ke),ie.length=0,r.raycastObject3D(a,t,ie),ie.forEach(l=>{l.instanceId=c,l.object=n,s.push(l)}),ie.length=0}}#x(e,t){if(t<=e.capacity)return;e.capacity=Ze(t,e.capacity);const s=new Set(e.records);s.forEach(n=>this.#E(n)),this.#s=this.#s.filter(n=>!s.has(n)),e.records=e.templateMeshes.map(({mesh:n,localMatrix:r},a)=>{const c=this.#h(e,n,r,a);return this.#s.push(c),c}),this.#y(e)}#S(e,t){const s=e.instances.indexOf(t);return s===-1?!1:(e.instances.splice(s,1),e.records.forEach(n=>n.visibleInstances.splice(s,1)),this.#t.delete(t),this.#g(),e.unsubscribeByInstance.get(t)?.(),e.unsubscribeByInstance.delete(t),e.instances.length===0?(this.#m(e),!0):(this.#b(e),this.#y(e),!0))}#m(e){e.unsubscribeByInstance.forEach(s=>s()),e.instances.forEach(s=>this.#t.delete(s)),e.unsubscribeByInstance.clear(),e.instances.length=0,this.#g();const t=new Set(e.records);t.forEach(s=>this.#E(s)),this.#s=this.#s.filter(s=>!t.has(s)),e.records.length=0,e.templateMeshes.length=0,this.#a.delete(e.url),this.remove(e.batch)}#E(e){e.batchRecord.batch.remove(e.mesh),e.mesh.dispose(),e.materials.forEach(t=>t.dispose())}#b(e){Object.assign(e.batch.userData,{url:e.url,count:e.instances.length,capacity:e.capacity,instanceKind:this.#l}),delete e.batch.userData.sceneInstances,delete e.batch.userData.facilities,e.records.forEach(t=>{delete t.mesh.userData.instances})}#C(e){const t=new Set(e),s=new Map;for(const r of e){const{instanceId:a}=r;if(!a)continue;const c=s.get(a);if(c&&c!==r)return!1;s.set(a,r)}let n=!0;return s.forEach((r,a)=>{n&&this.#i(c=>{!n||t.has(c)||c.instanceId===a&&(n=!1)})}),n}#w(){if(!this.#r)return;this.#e.clear();const e=new Set;this.#i(t=>{const{instanceId:s}=t;if(!s||e.has(s))return;const n=this.#e.get(s);if(n&&n!==t){this.#e.delete(s),e.add(s);return}this.#e.set(s,t)}),this.#r=!1}#g(){this.#r=!0}#y(e){e.records.forEach(t=>this.#v(t))}#v(e){e.dirty=!0,e.hasLastCameraState=!1,e.mesh.visible=!0,e.mesh.frustumCulled=!1,K(e.batchRecord.batch)}#I(e,t,s){const n=this.#O(t),r=this.#A(e,s,n);!e.dirty&&!this.#B(e)&&!r||this.#D(e,s,n)}#B(e){const{instances:t}=e.batchRecord;for(let s=0;s<t.length;s++)if(e.visibleInstances[s]!==ue(t[s]))return e.dirty=!0,K(e.batchRecord.batch),!0;return!1}#O(e){return e?.getDrawingBufferSize?(e.getDrawingBufferSize(He),He.y):0}#A(e,t,s){return this.#M(t,s)?e.hasLastCameraState?!Ye(e.lastCameraMatrixWorldInverse,t.matrixWorldInverse)||!Ye(e.lastCameraProjectionMatrix,t.projectionMatrix)||Math.abs(e.lastViewportHeight-s)>U:!0:!1}#M(e,t){return this.#n&&e!==void 0&&(this.#o||this.#c>0&&t>0)}#_(e,t){if(!this.#M(e,t))return null;let s=null;return this.#o&&(ze.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),s=Ks.setFromProjectionMatrix(ze)),{camera:e,frustum:s,viewportHeight:t}}#L(e,t){return t?t.frustum&&!t.frustum.intersectsSphere(e)?!1:this.#c<=0||t.viewportHeight<=0?!0:this.#T(e,t.camera,t.viewportHeight)>=this.#c:!0}#T(e,t,s){const n=Math.abs(t.projectionMatrix.elements[5]);if(n<=U)return 1/0;if(t.isOrthographicCamera)return e.radius*n*s*.5;$e.copy(e.center).applyMatrix4(t.matrixWorldInverse);const r=-$e.z;return r<=U?1/0:e.radius*n*s*.5/r}#D(e,t,s=0){this.updateWorldMatrix(!0,!1),je.copy(this.matrixWorld).invert();const n=e.mesh.instanceMatrix.array,r=e.colorAttribute.array,a=e.opacityAttribute.array,c=e.mesh.geometry;let l=!1,h=!1,d=!1,u=0,p=0,f=!1;const S=e.mesh.count,C=this.#_(t,s);c.boundingSphere||c.computeBoundingSphere(),e.fullBoundingSphere.makeEmpty(),e.renderedInstances.length=0,e.batchRecord.instances.forEach((w,x)=>{const b=ue(w);e.visibleInstances[x]=b,w.updateWorldMatrix(!0,!1),re.multiplyMatrices(je,w.matrixWorld).multiply(e.localMatrix);const y=w.getInstanceOpacity();if(!(b&&y>U)||(p++,c.boundingSphere&&(We.copy(c.boundingSphere).applyMatrix4(re),e.fullBoundingSphere.union(We),C&&(Ue.multiplyMatrices(w.matrixWorld,e.localMatrix),Ge.copy(c.boundingSphere).applyMatrix4(Ue),!this.#L(Ge,C)))))return;const M=u,I=M*16;Xs(re,n,I)||(e.mesh.setMatrixAt(M,re),l=!0),V.copy(w.getInstanceColor(V));const A=w.getInstanceColorMode(),v=M*4;Ys(V,A,r,v)||(e.colorAttribute.setXYZW(M,V.r,V.g,V.b,A),h=!0),y<wt&&(f=!0),Math.abs(y-a[M])>U&&(e.opacityAttribute.setX(M,y),d=!0),e.renderedInstances[M]=w,u++}),e.mesh.count=u,S!==u&&(l=!0,h=!0,d=!0,K(e.batchRecord.batch));const D=p>0;e.mesh.visible!==D&&(e.mesh.visible=D,K(e.batchRecord.batch)),e.mesh.frustumCulled!==!0&&(e.mesh.frustumCulled=!0,K(e.batchRecord.batch)),l&&(e.mesh.instanceMatrix.needsUpdate=!0),h&&(e.colorAttribute.needsUpdate=!0),d&&(e.opacityAttribute.needsUpdate=!0),e.mesh.boundingSphere===null&&(e.mesh.boundingSphere=new o.Sphere),e.mesh.boundingSphere.copy(e.fullBoundingSphere);const O=e.hasSourceTransparency||f;e.materials.forEach(w=>{w.transparent!==O&&(w.transparent=O,w.needsUpdate=!0,K(e.batchRecord.batch))}),t&&this.#M(t,s)?(e.lastCameraMatrixWorldInverse.copy(t.matrixWorldInverse),e.lastCameraProjectionMatrix.copy(t.projectionMatrix),e.lastViewportHeight=s,e.hasLastCameraState=!0):e.hasLastCameraState=!1,e.dirty=!1}}const xt="0.0.31";typeof window<"u"&&(window.__USPACE__={version:xt});exports.CSSRenderer=j.CSSRenderer;exports.CameraControls=j.CameraControls;exports.InteractionEvent=j.InteractionEvent;exports.InteractionManager=j.InteractionManager;exports.ObjectManager=j.ObjectManager;exports.RenderPipeline=j.RenderPipeline;exports.RoomEnvironment=j.RoomEnvironment;exports.Viewer=j.Viewer;exports.enableMeshBVHRaycast=j.enableMeshBVHRaycast;exports.getGeometryBoundsTree=j.getGeometryBoundsTree;Object.defineProperty(exports,"CSS2DObject",{enumerable:!0,get:()=>At.CSS2DObject});Object.defineProperty(exports,"CSS3DObject",{enumerable:!0,get:()=>et.CSS3DObject});Object.defineProperty(exports,"CSS3DSprite",{enumerable:!0,get:()=>et.CSS3DSprite});exports.AnnotationManager=Es;exports.BaseGroup=q;exports.BaseMesh=F;exports.BaseSprite=rt;exports.CircleMesh=is;exports.ClippingTool=xs;exports.EditableGeometryBatchLayer=Vs;exports.ExtrudeMesh=Se;exports.INSTANCE_COLOR_MODE_NONE=ye;exports.INSTANCE_COLOR_MODE_OVERRIDE=ae;exports.INSTANCE_COLOR_MODE_TINT=ft;exports.InstanceObject=_s;exports.LightManager=Tt;exports.MaterialEffects=H;exports.MeasureTool=Ss;exports.Model=G;exports.ModelDecodeWorkerClient=nt;exports.ModelDecodeWorkerUnavailableError=te;exports.ModelInstancedLayer=rn;exports.ModelLoaderManager=z;exports.ObjectUtils=W;exports.PlaneMesh=rs;exports.Poi=ns;exports.SBMLoader=me;exports.SBMXLoader=fe;exports.SceneManager=Lt;exports.Selection=_t;exports.ShapeMesh=xe;exports.SphereMesh=it;exports.TSLEffects=ps;exports.TextureLoaderManager=ts;exports.Topology=ss;exports.TubeMesh=ge;exports.Tween=pt;exports.isInstanceObject=Ls;exports.reinterpretType=fs;exports.reuseDecodedImageContent=st;exports.tweenAnimation=ws;exports.version=xt;
16
+ `,t.labelStyle)for(const h of Object.keys(t.labelStyle)){const d=t.labelStyle[h];d!==void 0&&(r.style[h]=d)}let a=null;const c=t.labelOffset||{x:0,y:2,z:0};if(t.showLeaderLine!==!1){const{lineColor:h=16777215}=t,d=new o.BufferGeometry().setFromPoints([new o.Vector3(0,0,0),new o.Vector3(c.x,c.y,c.z)]),u=new o.LineBasicMaterial({color:h});a=new o.Line(d,u),s.add(a)}if(this._createCSSObject){const h=this._createCSSObject(r);h.position.set(c.x,c.y,c.z),s.add(h)}this.scene.add(s);const l={id:e,options:t,group:s,labelElement:r,line:a};return this.annotations.set(e,l),l}addText(e,t,s={}){const n=`annotation_${this._idCounter++}`;return this.add(n,{position:t,content:e,...s})}updateContent(e,t){const s=this.annotations.get(e);s&&(s.labelElement.innerHTML=t,s.options.content=t)}updatePosition(e,t){const s=this.annotations.get(e);s&&(s.group.position.set(t.x,t.y,t.z),s.options.position=t)}show(e){const t=this.annotations.get(e);t&&(t.group.visible=!0)}hide(e){const t=this.annotations.get(e);t&&(t.group.visible=!1)}get(e){return this.annotations.get(e)}remove(e){const t=this.annotations.get(e);if(t){const s=[...t.group.children];for(const n of s)t.group.remove(n),n.geometry?.dispose(),n.material?.dispose();this.scene.remove(t.group),this.annotations.delete(e)}}removeAll(){const e=Array.from(this.annotations.keys());for(const t of e)this.remove(t)}showAll(){for(const e of this.annotations.values())e.group.visible=!0}hideAll(){for(const e of this.annotations.values())e.group.visible=!1}keys(){return Array.from(this.annotations.keys())}get size(){return this.annotations.size}dispose(){this.removeAll()}}const Te=new o.Matrix4,vs=1e-6,Is=1e-6,De="uSpaceInstanceOriginalMaterialState",ye=0,ae=1,ft=2;function Cs(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Bs(i,e){const t=i.elements,s=e.elements;for(let n=0;n<16;n++)if(Math.abs(t[n]-s[n])>vs)return!1;return!0}function mt(i){const e=i.material;return Array.isArray(e)?e:[e]}function gt(i){const e=i.userData,t=e[De];if(t)return t;const s={transparent:i.transparent,opacity:i.opacity};return e[De]=s,s}function Os(i,e){i.traverse(t=>{const s=t;s.isMesh&&mt(s).forEach(n=>{if(!n)return;const r=n,a=gt(r),c=a.opacity*e;r.transparent=a.transparent||c<1,r.opacity=c,r.needsUpdate=!0})})}function As(i){i.traverse(e=>{const t=e;t.isMesh&&mt(t).forEach(s=>{if(!s)return;const n=s,r=gt(n);n.transparent=r.transparent,n.opacity=r.opacity,n.needsUpdate=!0})})}class _s extends q{isInstanceObject=!0;type="InstanceObject";instanceId="";instanceKind="";instanceName="";geometry=new o.BufferGeometry;boundingBox=null;boundingSphere=null;#s={color:null,colorMode:ye,opacity:1};#a=null;#t=null;#e=null;#r=null;#n=new Set;#o=new o.Matrix4;#c=!1;#l=!0;#d=!1;#u;constructor(e={}){super(),this.#u=e.boundsName??"InstanceBounds"}setInstanceIdentity(e){let t=!1;if(e.id!==void 0){const s=e.id??"";this.instanceId!==s&&(this.instanceId=s,t=!0)}if(e.kind!==void 0){const s=e.kind??"";this.instanceKind!==s&&(this.instanceKind=s,t=!0)}if(e.name!==void 0){const s=e.name??"";this.instanceName!==s&&(this.instanceName=s,t=!0)}return t&&this.markInstanceRenderDirty(),this}setInstanceBounds(e){if(e.isEmpty())return this;this.#t&&this.remove(this.#t);const t=new o.BufferGeometry;t.boundingBox=e.clone();const s=new o.Object3D;return s.name=this.#u,s.visible=!1,s.geometry=t,s.raycast=()=>{},this.#t=s,this.add(s),this.#h(),this.markInstanceRenderDirty(),this}setInstanceRenderObject(e){return this.#e&&this.#e!==e&&this.#e.parent===this&&this.remove(this.#e),this.#e=e,e&&e.parent!==this&&this.add(e),this.#f(),this.#h(),this.markInstanceRenderDirty(),this}getInstanceRenderObject(){return this.#e}setInstanceMaterializer(e){return this.#r=e,this}hasInstanceMaterializer(e){return this.#r===e}clearInstanceMaterializer(e){return(e===void 0||this.#r===e)&&(this.#r=null),this}materialize(){return this.#r?.()??this.#e??null}computeBoundingBox(){this.boundingBox===null&&(this.boundingBox=new o.Box3),this.getInstanceBoundingBox(this.boundingBox,!1)}computeBoundingSphere(){if(this.boundingSphere===null&&(this.boundingSphere=new o.Sphere),this.boundingBox===null&&this.computeBoundingBox(),!this.boundingBox||this.boundingBox.isEmpty()){this.boundingSphere.makeEmpty();return}this.boundingBox.getBoundingSphere(this.boundingSphere)}getInstanceBoundingBox(e=new o.Box3,t=!1){const s=this.#t?.geometry?.boundingBox;return s?(e.copy(s),t&&(this.updateWorldMatrix(!0,!1),e.applyMatrix4(this.matrixWorld)),e):this.#e?(e.setFromObject(this.#e),t||(this.updateWorldMatrix(!0,!1),Te.copy(this.matrixWorld).invert(),e.applyMatrix4(Te)),e):e.makeEmpty()}setInstanceVisible(e){return this.visible===e?this:(this.visible=e,this.markInstanceRenderDirty(),this)}setInstanceColor(e){return this.#s.color=new o.Color(e),this.#s.colorMode=ae,this.#f(),this.markInstanceRenderDirty(),this}resetInstanceColor(){return this.#s.color===null?this:(this.#s.color=null,this.#s.colorMode=ye,this.#f(),this.markInstanceRenderDirty(),this)}setInstanceOpacity(e){const t=Math.max(0,Math.min(1,e));return Math.abs(this.#s.opacity-t)<=Is?this:(this.#s.opacity=t,this.#f(),this.markInstanceRenderDirty(),this)}getInstanceColor(e=new o.Color){const t=this.#p();return t.color?e.copy(t.color):e.setRGB(1,1,1)}hasInstanceColor(){return this.#p().color!==null}getInstanceOpacity(){return this.#p().opacity}setInstanceHighlight(e,t,s=!1){return this.#a={color:new o.Color(e),colorMode:s?ae:ft,opacity:Math.max(0,Math.min(1,t))},this.#f(),this.markInstanceRenderDirty(),this}clearInstanceHighlight(){return this.#a===null?this:(this.#a=null,this.#f(),this.markInstanceRenderDirty(),this)}getInstanceColorMode(){return this.#p().colorMode}onInstanceRenderDirty(e){return this.#n.add(e),()=>this.#n.delete(e)}markInstanceRenderDirty(){return this.#n.forEach(e=>e()),this}updateMatrixWorld(e){super.updateMatrixWorld(e),this.#i()}updateWorldMatrix(e,t){super.updateWorldMatrix(e,t),this.#i()}#i(){const e=Cs(this);(!this.#c||!Bs(this.matrixWorld,this.#o)||!this.#d||e!==this.#l)&&(this.#c=!0,this.#d=!0,this.#o.copy(this.matrixWorld),this.#l=e,this.markInstanceRenderDirty())}#h(){this.boundingBox=null,this.boundingSphere=null}#p(){return this.#a??this.#s}#f(){if(!this.#e)return;const e=this.#p();if(e.color){As(this.#e),H.highlightColor(this.#e,{color:e.color,opacity:e.opacity,overwrite:e.colorMode===ae,multiplyOpacity:!0});return}H.removeHighlightColor(this.#e),Os(this.#e,e.opacity)}}function Ls(i){return i.isInstanceObject===!0}const Ts=new Set(["MeshBasicMaterial","MeshLambertMaterial","MeshPhongMaterial","MeshStandardMaterial","MeshPhysicalMaterial"]),Ne=new WeakMap;let Ds=1;const Re=new o.Matrix4,Z=new o.Matrix4,Pe=new o.Matrix4;function Ns(i,e,t=1e-6){const s=i.elements,n=e.elements;for(let r=0;r<16;r++)if(Math.abs(s[r]-n[r])>t)return!1;return!0}function yt(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Rs(i){const e=i.source.data;if(!e||typeof e!="object"&&typeof e!="function")return`texture:${i.uuid}`;let t=Ne.get(e);return t===void 0&&(t=Ds++,Ne.set(e,t)),`source:${t}`}function Ps(i){return JSON.stringify([Rs(i),i.mapping,i.channel,i.wrapS,i.wrapT,i.magFilter,i.minFilter,i.anisotropy,i.format,i.internalFormat,i.type,i.offset.toArray(),i.repeat.toArray(),i.center.toArray(),i.rotation,i.matrixAutoUpdate,i.matrix.toArray(),i.generateMipmaps,i.premultiplyAlpha,i.flipY,i.unpackAlignment,i.colorSpace,"compareFunction"in i?i.compareFunction:null])}function be(i){if(Array.isArray(i))return i.map(be);if(!i||typeof i!="object")return i;const e=i;return Object.fromEntries(Object.keys(e).sort().map(t=>[t,be(e[t])]))}function we(i,e){if(Array.isArray(i))return i.map(s=>we(s,e));if(!i||typeof i!="object")return typeof i=="string"?e.get(i)??i:i;const t=i;return Object.fromEntries(Object.keys(t).filter(s=>s!=="metadata"&&s!=="uuid"&&s!=="name").sort().map(s=>[s,we(t[s],e)]))}function ks(i){if(!Ts.has(i.type)||i.transparent||i.opacity<.999||i.visible===!1)return null;const e=i;if(Object.keys(e).some(r=>r.endsWith("Node")&&e[r]!=null)||Object.hasOwn(i,"onBeforeCompile"))return null;const t=new Map;Object.values(e).forEach(r=>{r instanceof o.Texture&&t.set(r.uuid,Ps(r))});const s={geometries:{},materials:{},textures:{},images:{},shapes:{},skeletons:{},animations:{},nodes:{}},n=i.toJSON(s);return JSON.stringify(be(we(n,t)))}function js(i){if(Object.keys(i.morphAttributes).length>0||i.drawRange.start!==0||i.drawRange.count!==1/0)return null;const e=Object.entries(i.attributes).sort(([t],[s])=>t.localeCompare(s)).map(([t,s])=>"isInterleavedBufferAttribute"in s?null:[t,s.itemSize,s.normalized,s.array.constructor.name,s.gpuType]);return e.some(t=>t===null)?null:JSON.stringify([i.index?.array.constructor.name??"non-indexed",e])}function Us(i,e){const t=[],s=new Set,n=new Set,r=!e&&(i.animations.length>0||i.mixer!==null);return r&&n.add("animation"),i.updateWorldMatrix(!0,!0),Re.copy(i.matrixWorld).invert(),i.traverseVisible(a=>{if(!(a instanceof o.Mesh))return;if(r){s.add(a);return}if(a instanceof o.SkinnedMesh){s.add(a),n.add("skinned");return}if(a.morphTargetInfluences){s.add(a),n.add("morph");return}if(Array.isArray(a.material)){s.add(a),n.add("material-array");return}const c=ks(a.material),l=js(a.geometry);if(!c){s.add(a),n.add(a.material.transparent||a.material.opacity<.999?"transparent":`material:${a.material.type}`);return}if(!l){s.add(a),n.add("geometry-layout");return}if(a.matrixWorld.determinant()<=0){s.add(a),n.add("negative-scale");return}t.push({mesh:a,localMatrix:Re.clone().multiply(a.matrixWorld),materialKey:c,geometryKey:l})}),t.length===0&&s.size===0&&n.add("empty"),{meshes:t,fallbackMeshes:s,fallbackReasons:n}}function zs(i,e){const t=Me.clone(i),s=[],n=[];return i.traverse(r=>{r instanceof o.Mesh&&s.push(r)}),t.traverse(r=>{r instanceof o.Mesh&&n.push(r)}),s.forEach((r,a)=>{e.has(r)&&n[a]&&(n[a].visible=!1)}),t}function Fs(i){const e=Me.clone(i),t=new Map,s=n=>{let r=t.get(n);return r||(r=n.clone(),t.set(n,r)),r};return e.traverse(n=>{n instanceof o.Mesh&&(n.material=Array.isArray(n.material)?n.material.map(s):s(n.material))}),e}function Ws(i){return Math.max(1,Math.ceil(Math.sqrt(Math.max(1,i))))}function Gs(i){const e=new o.DataTexture(new Float32Array(i*i*4),i,i,o.RGBAFormat,o.FloatType);return e.magFilter=o.NearestFilter,e.minFilter=o.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e}function Hs(i,e){const t=i.clone(),s=g.attribute("batchObjectIndex","float").toInt(),n=g.int(g.textureSize(g.textureLoad(e),g.int(0)).x).toConst(),r=s.mod(n).toConst(),a=s.div(n).toConst(),c=g.textureLoad(e,g.ivec2(r,a)),l=t.colorNode??g.materialColor,h=g.select(c.a.greaterThan(1.5),l.mul(c.rgb),c.rgb);return t.colorNode=g.select(c.a.greaterThan(.5),h,l),t.maskNode=c.a.greaterThan(-.5),t.needsUpdate=!0,t}function ke(i){let e=0,t=i.parent;for(;t;)e++,t=t.parent;return e}class $s extends F{objectIndices;states;#s;constructor(e,t,s,n){super(e,t),this.objectIndices=s,this.states=n,this.userData.editableGeometryBatch=!0}raycast(e,t){if(this.visible===!1&&this.ignoreInvisibleWhenRaycast===!0)return!1;this.#s===void 0&&(this.#s=j.getGeometryBoundsTree(this.geometry));const s=[];this.#s?this.#s.raycastObject3D(this,e,s):super.raycast(e,s),s.forEach(n=>{const r=n.faceIndex;if(r==null)return;const a=r*3,c=this.geometry.index?.getX(a)??a,l=this.objectIndices[c],h=l===void 0?void 0:this.states[l],d=h?.instance;!h||h.materialized||!d||!yt(d)||d.getInstanceOpacity()<=.001||(n.object=d,n.batchObjectIndex=l,t.push(n))})}}class Vs extends q{isEditableGeometryBatchLayer=!0;type="EditableGeometryBatchLayer";options;stats={instances:0,sourceMeshes:0,batches:0,drawCallsSaved:0,vertices:0,indices:0,unsupportedInstances:0,unsupportedByReason:{}};#s=[];#a=new Set;#t=[];#e=new Map;#r=new Set;#n=null;#o=new o.Matrix4;#c=!1;#l=!1;#d=!1;constructor(e={}){super(),this.name="EditableGeometryBatches",this.options={maxVerticesPerBatch:e.maxVerticesPerBatch??15e5,maxIndicesPerBatch:e.maxIndicesPerBatch??45e5,freezeAnimations:e.freezeAnimations??!1}}addSource(e){if(this.#l)throw new Error("EditableGeometryBatchLayer has been disposed.");if(this.#c)throw new Error("EditableGeometryBatchLayer has already been built.");const{key:t,template:s,instances:n}=e,r=new Set;n.forEach(h=>{if(r.has(h)||this.#a.has(h))throw new Error("EditableGeometryBatchLayer cannot batch the same InstanceObject more than once.");r.add(h)});const{meshes:a,fallbackMeshes:c,fallbackReasons:l}=Us(s,this.options.freezeAnimations);return r.forEach(h=>this.#a.add(h)),this.#s.push({key:t,template:s,instances:[...n],meshes:a,fallbackMeshes:c,fallbackReasons:l,bounds:new o.Box3().setFromObject(s)}),a.length>0}build(){if(this.#l)throw new Error("EditableGeometryBatchLayer has been disposed.");if(this.#c)throw new Error("EditableGeometryBatchLayer.build() can only be called once.");this.#c=!0,this.updateWorldMatrix(!0,!1),this.#o.copy(this.matrixWorld).invert();const e=[],t=new Map,s=(r,a,c,l)=>{if(c.length===0)return;const h=l.size>0?[...l]:["unknown"];e.push({key:r.key,template:a,instances:c,reasons:h}),h.forEach(d=>{this.stats.unsupportedByReason[d]=(this.stats.unsupportedByReason[d]??0)+c.length})};this.#s.forEach(r=>{const a=[],c=[];r.instances.forEach(h=>{h.updateWorldMatrix(!0,!1),Z.multiplyMatrices(this.#o,h.matrixWorld),Z.determinant()<=0?c.push(h):a.push({instance:h,matrix:Z.clone()})});const l=r.fallbackReasons.size>0?r.fallbackReasons:new Set(["unknown"]);if(r.meshes.length===0){s(r,r.template,a.map(({instance:h})=>h),l),s(r,r.template,c,new Set([...l,"negative-scale"]));return}r.fallbackMeshes.size>0&&s(r,zs(r.template,new Set(r.meshes.map(({mesh:h})=>h))),a.map(({instance:h})=>h),l),s(r,r.template,c,new Set([...r.fallbackReasons,"negative-scale"])),a.forEach(({instance:h,matrix:d})=>{const u=this.#t.length,p=()=>this.materialize(h),f={instance:h,template:r.template,initialMatrix:d,objectIndex:u,materialized:!1,materializer:p,unsubscribe:()=>{}};f.unsubscribe=h.onInstanceRenderDirty(()=>this.#h(f)),this.#t.push(f),this.#e.set(h,f),h.setInstanceBounds(r.bounds),h.setInstanceMaterializer(p),this.#r.add(f),r.meshes.forEach(({mesh:S,localMatrix:C,materialKey:D,geometryKey:O})=>{Pe.multiplyMatrices(d,C);const w=S.geometry.clone().applyMatrix4(Pe),x=w.getAttribute("position");w.setAttribute("batchObjectIndex",new o.Float32BufferAttribute(new Float32Array(x.count).fill(u),1));const b=JSON.stringify([D,O,S.castShadow,S.receiveShadow,S.renderOrder]),y=t.get(b),E={geometry:w,material:S.material,castShadow:S.castShadow,receiveShadow:S.receiveShadow,renderOrder:S.renderOrder,objectIndices:new Array(x.count).fill(u)};y?y.push(E):t.set(b,[E]),this.stats.sourceMeshes++,this.stats.vertices+=x.count,this.stats.indices+=w.index?.count??x.count})})}),this.stats.instances=this.#t.length,this.stats.unsupportedInstances=e.reduce((r,a)=>r+a.instances.length,0);const n=Ws(this.#t.length);return this.#n=Gs(n),this.#i(),t.forEach(r=>this.#u(r)),this.stats.batches=this.children.length,this.stats.drawCallsSaved=Math.max(0,this.stats.sourceMeshes-this.stats.batches),this.children.forEach(r=>{r instanceof o.Mesh&&(r.onBeforeRender=()=>this.#i())}),{stats:{...this.stats},unsupported:e}}materialize(e){const t=this.#e.get(e);if(!t||t.materialized)return e.getInstanceRenderObject();const s=Fs(t.template);return s.position.set(0,0,0),s.quaternion.identity(),s.scale.set(1,1,1),s.matrix.identity(),t.materialized=!0,e.setInstanceRenderObject(s),s.updateWorldMatrix(!0,!0),this.#r.add(t),this.dispatchEvent({type:"materialize",instance:e,object:s}),s}#u(e){const t=[];let s=[],n=0,r=0;e.forEach(a=>{const c=a.geometry.getAttribute("position").count,l=a.geometry.index?.count??c;s.length>0&&(n+c>this.options.maxVerticesPerBatch||r+l>this.options.maxIndicesPerBatch)&&(t.push(s),s=[],n=0,r=0),s.push(a),n+=c,r+=l}),s.length>0&&t.push(s),t.forEach(a=>{const c=Ot.mergeGeometries(a.map(p=>p.geometry),!1);if(a.forEach(p=>p.geometry.dispose()),!c||!this.#n)return;c.computeBoundingBox(),c.computeBoundingSphere();const l=a[0],h=a.flatMap(p=>p.objectIndices),d=Hs(l.material,this.#n),u=new $s(c,d,h,this.#t);u.name=`EditableGeometryBatch:${this.children.length}`,u.castShadow=l.castShadow,u.receiveShadow=l.receiveShadow,u.renderOrder=l.renderOrder,u.matrixAutoUpdate=!1,this.add(u)})}#i(){if(!(!this.#n||this.#r.size===0||this.#d)){this.#d=!0;try{this.updateWorldMatrix(!0,!1),this.#o.copy(this.matrixWorld).invert();const e=this.#n.image.data;[...this.#r].sort((t,s)=>ke(t.instance)-ke(s.instance)).forEach(t=>{const{instance:s,objectIndex:n}=t;s.updateWorldMatrix(!0,!1),Z.multiplyMatrices(this.#o,s.matrixWorld),!t.materialized&&s.getInstanceRenderObject()!==null&&!s.hasInstanceMaterializer(t.materializer)&&(t.materialized=!0),!t.materialized&&!Ns(Z,t.initialMatrix)&&this.materialize(s),!t.materialized&&s.getInstanceOpacity()<.999&&this.materialize(s);const r=n*4,a=!t.materialized&&yt(s)&&s.getInstanceOpacity()>.001,c=s.getInstanceColor();e[r]=c.r,e[r+1]=c.g,e[r+2]=c.b,e[r+3]=a?s.getInstanceColorMode():-1,this.#r.delete(t)}),this.#n.needsUpdate=!0}finally{this.#d=!1}this.#r.size>0&&this.#i()}}#h(e){this.#r.add(e),this.#i()}dispose(){this.#l||(this.#l=!0,this.#t.forEach(e=>{e.unsubscribe(),e.instance.clearInstanceMaterializer(e.materializer)}),this.#t.length=0,this.#e.clear(),this.#a.clear(),this.#r.clear(),this.#s.length=0,this.#n?.dispose(),this.#n=null,this.traverse(e=>{if(!(e instanceof o.Mesh))return;e.geometry.dispose(),(Array.isArray(e.material)?e.material:[e.material]).forEach(s=>s.dispose())}),this.clear())}}const je=new o.Matrix4,re=new o.Matrix4,Ue=new o.Matrix4,ze=new o.Matrix4,Fe=new o.Box3,We=new o.Sphere,Ge=new o.Sphere,Ks=new o.Frustum,V=new o.Color,He=new o.Vector2,$e=new o.Vector3,Ve=new o.Matrix4,Ke=new o.Matrix4,qe=new o.Sphere,ie=[],bt=1e-6,U=1e-6,wt=.999,qs=0,Xe=1;function Xs(i,e,t){const s=i.elements;for(let n=0;n<16;n++)if(Math.abs(s[n]-e[t+n])>bt)return!1;return!0}function Ys(i,e,t,s){return Math.abs(i.r-t[s])<=U&&Math.abs(i.g-t[s+1])<=U&&Math.abs(i.b-t[s+2])<=U&&Math.abs(e-t[s+3])<=U}function Ye(i,e){const t=i.elements,s=e.elements;for(let n=0;n<16;n++)if(Math.abs(t[n]-s[n])>bt)return!1;return!0}function ue(i){let e=i;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}function Qs(i){const e=i.geometry.morphAttributes;return Object.values(e).some(t=>t?.length)}function Js(i){const e=i.material;if(!Array.isArray(e))return!0;if(e.length===0||!e.every(Boolean))return!1;const t=i.geometry.groups;return t.length===0?!1:t.every(s=>{const n=s.materialIndex??0;return Number.isInteger(s.start)&&s.start>=0&&Number.isInteger(s.count)&&s.count>0&&Number.isInteger(n)&&n>=0&&n<e.length})}function Zs(i){return!i.isSkinnedMesh&&!Qs(i)&&Js(i)}function Qe(i){return Array.isArray(i)?i:[i]}function Mt(i){return i.transparent||i.opacity<wt}function Je(i,e,t){const s=i.clone(),n=g.instancedBufferAttribute(e,"vec4",4,0),r=g.instancedBufferAttribute(t,"float",1,0),a=s.colorNode??g.materialColor,c=s.opacityNode?g.float(s.opacityNode):g.materialOpacity,l=g.select(n.a.greaterThan(1.5),a.mul(n.rgb),n.rgb);return s.colorNode=g.select(n.a.greaterThan(.5),l,a),s.opacityNode=c.mul(r),s.transparent=Mt(i),s.needsUpdate=!0,s}function en(i,e,t){return Array.isArray(i)?i.map(s=>Je(s,e,t)):Je(i,e,t)}function tn(i){const e=[],t=new o.Matrix4;let s=!1;return i.updateWorldMatrix(!0,!0),t.copy(i.matrixWorld).invert(),i.traverse(n=>{if(!s&&!(!(n instanceof o.Mesh)||!n.visible)){if(!Zs(n)){s=!0;return}n.updateWorldMatrix(!0,!1),e.push({mesh:n,localMatrix:t.clone().multiply(n.matrixWorld)})}}),s?[]:e}function sn(i){const e=new o.Box3;return i.forEach(({mesh:t,localMatrix:s})=>{const n=t.geometry;n.boundingBox||n.computeBoundingBox(),n.boundingBox&&(Fe.copy(n.boundingBox).applyMatrix4(s),e.union(Fe))}),e}function K(i){const e=i;"needsUpdate"in e&&(e.needsUpdate=!0)}function Ze(i,e=Xe){let t=Math.max(Xe,e);for(;t<i;)t*=2;return t}function nn(i){return i!==null&&typeof i=="object"&&Symbol.iterator in i}class rn extends q{isModelInstancedLayer=!0;type="ModelInstancedLayer";#s=[];#a=new Map;#t=new Map;#e=new Map;#r=!0;#n=!1;#o=!0;#c=qs;#l;#d;constructor(e={}){super(),this.name=e.name??"ModelInstances",this.#l=e.instanceKind??"",this.#d=e.getHitUserData??(()=>({}))}get instanceKind(){return this.#l}getInstances(){const e=[];return this.#i(t=>e.push(t)),e}getInstanceById(e){return this.#w(),this.#e.get(e)}hasInstance(e){return this.#w(),this.#e.has(e)}getInstanceCulling(){return{enabled:this.#n,frustum:this.#o,minScreenRadius:this.#c}}setInstanceCulling(e={}){let t=!1;if(e.enabled!==void 0&&this.#n!==e.enabled&&(this.#n=e.enabled,t=!0),e.frustum!==void 0&&this.#o!==e.frustum&&(this.#o=e.frustum,t=!0),e.minScreenRadius!==void 0){const s=Math.max(0,e.minScreenRadius);Math.abs(this.#c-s)>U&&(this.#c=s,t=!0)}return t&&this.#s.forEach(s=>this.#v(s)),this}setInstanceVisible(e){return this.visible!==e&&(this.visible=e),this.#i(t=>{t.setInstanceVisible(e)}),this}setInstanceColor(e){return this.#i(t=>{t.setInstanceColor(e)}),this}resetInstanceColor(){return this.#i(e=>{e.resetInstanceColor()}),this}setInstanceOpacity(e){return this.#i(t=>{t.setInstanceOpacity(e)}),this}setInstanceHighlight(e,t,s=!1){return this.#i(n=>{n.setInstanceHighlight(e,t,s)}),this}clearInstanceHighlight(){return this.#i(e=>{e.clearInstanceHighlight()}),this}reserveBatch(e,t,s){const n=Math.floor(s);return n<=0?!1:this.#u(e,t,n)!==null}addInstance(e,t,s){return this.addInstances(e,t,[s])}addInstances(e,t,s){if(s.length===0)return!1;const n=this.#a.has(e),r=this.#u(e,t,s.length);if(!r)return!1;const a=[],c=new Set;return s.forEach(l=>{c.has(l)||(c.add(l),this.#t.get(l)===r)||a.push(l)}),a.length===0?!0:this.#C(a)?(a.forEach(l=>{const h=this.#t.get(l);h&&h!==r&&this.#S(h,l)}),this.#x(r,r.instances.length+a.length),a.forEach(l=>{l.setInstanceBounds(r.templateBounds),r.instances.push(l),this.#t.set(l,r),r.unsubscribeByInstance.set(l,l.onInstanceRenderDirty(()=>{this.#g(),this.#y(r)}))}),this.#g(),this.#b(r),this.#y(r),!0):(!n&&r.instances.length===0&&this.#m(r),!1)}removeInstance(e){return this.removeInstances([e])>0}removeInstances(e){const t=new Set,s=new Set,n=typeof e=="string"||!nn(e)?[e]:e;for(const a of n)typeof a=="string"?t.add(a):this.#t.has(a)&&s.add(a);t.size>0&&(this.#w(),t.forEach(a=>{const c=this.#e.get(a);c&&s.add(c)}));let r=0;return s.forEach(a=>{const c=this.#t.get(a);c&&this.#S(c,a)&&r++}),r}removeBatch(e){const t=this.#a.get(e);return t?(this.#m(t),!0):!1}clearBatches(){return[...this.#a.values()].forEach(e=>this.#m(e)),this}#u(e,t,s){const n=this.#a.get(e);if(n)return this.#x(n,s),n;if(t.animations?.length)return null;const r=tn(t);if(r.length===0)return null;const a=sn(r),c=new o.Group;c.name=e,this.add(c);const l={url:e,batch:c,templateMeshes:r,templateBounds:a,records:[],instances:[],unsubscribeByInstance:new Map,capacity:Ze(s)};return r.forEach(({mesh:h,localMatrix:d},u)=>{const p=this.#h(l,h,d,u);l.records.push(p),this.#s.push(p)}),this.#a.set(e,l),this.#b(l),l}#i(e){const t=new Set;this.#a.forEach(s=>{s.instances.forEach(n=>{t.has(n)||(t.add(n),e(n))})})}#h(e,t,s,n){const r=new o.InstancedBufferAttribute(new Float32Array(e.capacity*4),4),a=new o.InstancedBufferAttribute(new Float32Array(e.capacity).fill(1),1);r.setUsage(o.DynamicDrawUsage),a.setUsage(o.DynamicDrawUsage);const c=en(t.material,r,a),l=Qe(c),h=Qe(t.material).some(Mt),d=new o.InstancedMesh(t.geometry,c,e.capacity);d.instanceMatrix=new o.StorageInstancedBufferAttribute(e.capacity,16),d.count=0,d.name=t.name||`${e.url}#${n}`,d.castShadow=t.castShadow,d.receiveShadow=t.receiveShadow,d.frustumCulled=!0,d.matrixAutoUpdate=!1,d.instanceMatrix.setUsage(o.DynamicDrawUsage),d.userData.url=e.url;const u=new o.Mesh(t.geometry,c);u.matrixAutoUpdate=!1;const p={batchRecord:e,mesh:d,boundsTree:void 0,raycastMesh:u,localMatrix:s.clone(),fullBoundingSphere:new o.Sphere,materials:l,hasSourceTransparency:h,colorAttribute:r,opacityAttribute:a,renderedInstances:[],visibleInstances:[],lastCameraMatrixWorldInverse:new o.Matrix4,lastCameraProjectionMatrix:new o.Matrix4,lastViewportHeight:0,hasLastCameraState:!1,dirty:!0};d.userData.getInstanceObjectByRenderIndex=S=>p.renderedInstances[S],d.userData.raycastAcceleration="lazy";const f=d.raycast.bind(d);return d.raycast=(S,C)=>{if(this.#I(p),!this.#p(p,S))return;p.boundsTree===void 0&&(p.boundsTree=j.getGeometryBoundsTree(p.mesh.geometry),p.mesh.userData.raycastAcceleration=p.boundsTree?"three-mesh-bvh":"default");const D=C.length;p.boundsTree?this.#f(p,S,C):f(S,C);for(let O=D;O<C.length;){const w=C[O],x=w.instanceId;if(x===void 0){O++;continue}const b=p.renderedInstances[x];if(!b||!ue(b)){C.splice(O,1);continue}w.object=b,w.instanceObject=b,w.instanceObjectId=b.instanceId,w.instanceKind=b.instanceKind||this.#l,w.instanceName=b.instanceName,w.instanceIndex=x,Object.assign(w,this.#d(b,x)),O++}},d.onBeforeRender=(S,C,D)=>this.#I(p,S,D),e.batch.add(d),p}#p(e,t){const{mesh:s}=e;return s.count===0?!1:(s.boundingSphere===null&&s.computeBoundingSphere(),s.boundingSphere?(qe.copy(s.boundingSphere).applyMatrix4(s.matrixWorld),t.ray.intersectsSphere(qe)):!0)}#f(e,t,s){const{mesh:n,boundsTree:r,raycastMesh:a}=e;if(!(!r||n.count===0)){a.geometry=n.geometry,a.material=n.material;for(let c=0;c<n.count;c++)n.getMatrixAt(c,Ve),Ke.multiplyMatrices(n.matrixWorld,Ve),a.matrixWorld.copy(Ke),ie.length=0,r.raycastObject3D(a,t,ie),ie.forEach(l=>{l.instanceId=c,l.object=n,s.push(l)}),ie.length=0}}#x(e,t){if(t<=e.capacity)return;e.capacity=Ze(t,e.capacity);const s=new Set(e.records);s.forEach(n=>this.#E(n)),this.#s=this.#s.filter(n=>!s.has(n)),e.records=e.templateMeshes.map(({mesh:n,localMatrix:r},a)=>{const c=this.#h(e,n,r,a);return this.#s.push(c),c}),this.#y(e)}#S(e,t){const s=e.instances.indexOf(t);return s===-1?!1:(e.instances.splice(s,1),e.records.forEach(n=>n.visibleInstances.splice(s,1)),this.#t.delete(t),this.#g(),e.unsubscribeByInstance.get(t)?.(),e.unsubscribeByInstance.delete(t),e.instances.length===0?(this.#m(e),!0):(this.#b(e),this.#y(e),!0))}#m(e){e.unsubscribeByInstance.forEach(s=>s()),e.instances.forEach(s=>this.#t.delete(s)),e.unsubscribeByInstance.clear(),e.instances.length=0,this.#g();const t=new Set(e.records);t.forEach(s=>this.#E(s)),this.#s=this.#s.filter(s=>!t.has(s)),e.records.length=0,e.templateMeshes.length=0,this.#a.delete(e.url),this.remove(e.batch)}#E(e){e.batchRecord.batch.remove(e.mesh),e.mesh.dispose(),e.materials.forEach(t=>t.dispose())}#b(e){Object.assign(e.batch.userData,{url:e.url,count:e.instances.length,capacity:e.capacity,instanceKind:this.#l}),delete e.batch.userData.sceneInstances,delete e.batch.userData.facilities,e.records.forEach(t=>{delete t.mesh.userData.instances})}#C(e){const t=new Set(e),s=new Map;for(const r of e){const{instanceId:a}=r;if(!a)continue;const c=s.get(a);if(c&&c!==r)return!1;s.set(a,r)}let n=!0;return s.forEach((r,a)=>{n&&this.#i(c=>{!n||t.has(c)||c.instanceId===a&&(n=!1)})}),n}#w(){if(!this.#r)return;this.#e.clear();const e=new Set;this.#i(t=>{const{instanceId:s}=t;if(!s||e.has(s))return;const n=this.#e.get(s);if(n&&n!==t){this.#e.delete(s),e.add(s);return}this.#e.set(s,t)}),this.#r=!1}#g(){this.#r=!0}#y(e){e.records.forEach(t=>this.#v(t))}#v(e){e.dirty=!0,e.hasLastCameraState=!1,e.mesh.visible=!0,e.mesh.frustumCulled=!1,K(e.batchRecord.batch)}#I(e,t,s){const n=this.#O(t),r=this.#A(e,s,n);!e.dirty&&!this.#B(e)&&!r||this.#D(e,s,n)}#B(e){const{instances:t}=e.batchRecord;for(let s=0;s<t.length;s++)if(e.visibleInstances[s]!==ue(t[s]))return e.dirty=!0,K(e.batchRecord.batch),!0;return!1}#O(e){return e?.getDrawingBufferSize?(e.getDrawingBufferSize(He),He.y):0}#A(e,t,s){return this.#M(t,s)?e.hasLastCameraState?!Ye(e.lastCameraMatrixWorldInverse,t.matrixWorldInverse)||!Ye(e.lastCameraProjectionMatrix,t.projectionMatrix)||Math.abs(e.lastViewportHeight-s)>U:!0:!1}#M(e,t){return this.#n&&e!==void 0&&(this.#o||this.#c>0&&t>0)}#_(e,t){if(!this.#M(e,t))return null;let s=null;return this.#o&&(ze.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),s=Ks.setFromProjectionMatrix(ze)),{camera:e,frustum:s,viewportHeight:t}}#L(e,t){return t?t.frustum&&!t.frustum.intersectsSphere(e)?!1:this.#c<=0||t.viewportHeight<=0?!0:this.#T(e,t.camera,t.viewportHeight)>=this.#c:!0}#T(e,t,s){const n=Math.abs(t.projectionMatrix.elements[5]);if(n<=U)return 1/0;if(t.isOrthographicCamera)return e.radius*n*s*.5;$e.copy(e.center).applyMatrix4(t.matrixWorldInverse);const r=-$e.z;return r<=U?1/0:e.radius*n*s*.5/r}#D(e,t,s=0){this.updateWorldMatrix(!0,!1),je.copy(this.matrixWorld).invert();const n=e.mesh.instanceMatrix.array,r=e.colorAttribute.array,a=e.opacityAttribute.array,c=e.mesh.geometry;let l=!1,h=!1,d=!1,u=0,p=0,f=!1;const S=e.mesh.count,C=this.#_(t,s);c.boundingSphere||c.computeBoundingSphere(),e.fullBoundingSphere.makeEmpty(),e.renderedInstances.length=0,e.batchRecord.instances.forEach((w,x)=>{const b=ue(w);e.visibleInstances[x]=b,w.updateWorldMatrix(!0,!1),re.multiplyMatrices(je,w.matrixWorld).multiply(e.localMatrix);const y=w.getInstanceOpacity();if(!(b&&y>U)||(p++,c.boundingSphere&&(We.copy(c.boundingSphere).applyMatrix4(re),e.fullBoundingSphere.union(We),C&&(Ue.multiplyMatrices(w.matrixWorld,e.localMatrix),Ge.copy(c.boundingSphere).applyMatrix4(Ue),!this.#L(Ge,C)))))return;const M=u,I=M*16;Xs(re,n,I)||(e.mesh.setMatrixAt(M,re),l=!0),V.copy(w.getInstanceColor(V));const A=w.getInstanceColorMode(),v=M*4;Ys(V,A,r,v)||(e.colorAttribute.setXYZW(M,V.r,V.g,V.b,A),h=!0),y<wt&&(f=!0),Math.abs(y-a[M])>U&&(e.opacityAttribute.setX(M,y),d=!0),e.renderedInstances[M]=w,u++}),e.mesh.count=u,S!==u&&(l=!0,h=!0,d=!0,K(e.batchRecord.batch));const D=p>0;e.mesh.visible!==D&&(e.mesh.visible=D,K(e.batchRecord.batch)),e.mesh.frustumCulled!==!0&&(e.mesh.frustumCulled=!0,K(e.batchRecord.batch)),l&&(e.mesh.instanceMatrix.needsUpdate=!0),h&&(e.colorAttribute.needsUpdate=!0),d&&(e.opacityAttribute.needsUpdate=!0),e.mesh.boundingSphere===null&&(e.mesh.boundingSphere=new o.Sphere),e.mesh.boundingSphere.copy(e.fullBoundingSphere);const O=e.hasSourceTransparency||f;e.materials.forEach(w=>{w.transparent!==O&&(w.transparent=O,w.needsUpdate=!0,K(e.batchRecord.batch))}),t&&this.#M(t,s)?(e.lastCameraMatrixWorldInverse.copy(t.matrixWorldInverse),e.lastCameraProjectionMatrix.copy(t.projectionMatrix),e.lastViewportHeight=s,e.hasLastCameraState=!0):e.hasLastCameraState=!1,e.dirty=!1}}const xt="0.0.32";typeof window<"u"&&(window.__USPACE__={version:xt});exports.CSSRenderer=j.CSSRenderer;exports.CameraControls=j.CameraControls;exports.InteractionEvent=j.InteractionEvent;exports.InteractionManager=j.InteractionManager;exports.ObjectManager=j.ObjectManager;exports.RenderPipeline=j.RenderPipeline;exports.RoomEnvironment=j.RoomEnvironment;exports.Viewer=j.Viewer;exports.enableMeshBVHRaycast=j.enableMeshBVHRaycast;exports.getGeometryBoundsTree=j.getGeometryBoundsTree;Object.defineProperty(exports,"CSS2DObject",{enumerable:!0,get:()=>At.CSS2DObject});Object.defineProperty(exports,"CSS3DObject",{enumerable:!0,get:()=>et.CSS3DObject});Object.defineProperty(exports,"CSS3DSprite",{enumerable:!0,get:()=>et.CSS3DSprite});exports.AnnotationManager=Es;exports.BaseGroup=q;exports.BaseMesh=F;exports.BaseSprite=rt;exports.CircleMesh=is;exports.ClippingTool=xs;exports.EditableGeometryBatchLayer=Vs;exports.ExtrudeMesh=Se;exports.INSTANCE_COLOR_MODE_NONE=ye;exports.INSTANCE_COLOR_MODE_OVERRIDE=ae;exports.INSTANCE_COLOR_MODE_TINT=ft;exports.InstanceObject=_s;exports.LightManager=Tt;exports.MaterialEffects=H;exports.MeasureTool=Ss;exports.Model=G;exports.ModelDecodeWorkerClient=nt;exports.ModelDecodeWorkerUnavailableError=te;exports.ModelInstancedLayer=rn;exports.ModelLoaderManager=z;exports.ObjectUtils=W;exports.PlaneMesh=rs;exports.Poi=ns;exports.SBMLoader=me;exports.SBMXLoader=fe;exports.SceneManager=Lt;exports.Selection=_t;exports.ShapeMesh=xe;exports.SphereMesh=it;exports.TSLEffects=ps;exports.TextureLoaderManager=ts;exports.Topology=ss;exports.TubeMesh=ge;exports.Tween=pt;exports.isInstanceObject=Ls;exports.reinterpretType=fs;exports.reuseDecodedImageContent=st;exports.tweenAnimation=ws;exports.version=xt;
package/dist/index.js CHANGED
@@ -3524,7 +3524,7 @@ class wi extends pe {
3524
3524
  }), t && this.#x(t, s) ? (e.lastCameraMatrixWorldInverse.copy(t.matrixWorldInverse), e.lastCameraProjectionMatrix.copy(t.projectionMatrix), e.lastViewportHeight = s, e.hasLastCameraState = !0) : e.hasLastCameraState = !1, e.dirty = !1;
3525
3525
  }
3526
3526
  }
3527
- const Ur = "0.0.31";
3527
+ const Ur = "0.0.32";
3528
3528
  typeof window < "u" && (window.__USPACE__ = { version: Ur });
3529
3529
  export {
3530
3530
  mi as AnnotationManager,