import{A as e,Ar as t,B as n,Cn as r,Cr as i,E as a,En as o,F as s,Gn as c,I as l,Ir as u,It as d,Jn as f,Jt as p,Kn as m,Kt as h,Lr as g,Mt as _,Nt as v,O as y,Qn as ee,Qt as te,Rt as ne,S as re,Sr as ie,St as b,Tt as ae,Xt as x,Zn as oe,Zt as S,_ as se,_n as ce,an as le,at as C,cn as w,cr as ue,dr as de,dt as fe,er as pe,fn as me,gn as he,hr as T,jr as ge,jt as E,kr as D,ln as _e,lr as ve,mn as ye,on as be,pn as xe,tr as Se,tt as Ce,ur as we,vn as Te,vr as Ee,vt as De,wn as O,x as k,xr as Oe,y as A,yt as ke,zt as Ae}from"./three@0.169.19.js";import{S as je,a as Me,i as Ne,o as Pe}from"./three-examples@0.169.19.js";var Fe=class extends S{constructor(e,n,r,i=128){if(n<=0||r<=0||i<=0)throw Error(`GroundedSkybox height, radius, and resolution must be positive.`);let a=new we(r,2*i,i);a.scale(1,1,-1);let o=a.getAttribute(`position`),s=new t;for(let e=0;e.9&&(r.visible=!1)),this.axis===`Y`&&(P.setFromEuler(Je.set(0,0,Math.PI/2)),r.quaternion.copy(t).multiply(P),Math.abs(F.copy(R).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`Z`&&(P.setFromEuler(Je.set(0,Math.PI/2,0)),r.quaternion.copy(t).multiply(P),Math.abs(F.copy(z).applyQuaternion(t).dot(this.eye))>.9&&(r.visible=!1)),this.axis===`XYZE`&&(P.setFromEuler(Je.set(0,Math.PI/2,0)),F.copy(this.rotationAxis),r.quaternion.setFromRotationMatrix(Xe.lookAt(Ye,F,R)),r.quaternion.multiply(P),r.visible=this.dragging),this.axis===`E`&&(r.visible=!1)):r.name===`START`?(r.position.copy(this.worldPositionStart),r.visible=this.dragging):r.name===`END`?(r.position.copy(this.worldPosition),r.visible=this.dragging):r.name===`DELTA`?(r.position.copy(this.worldPositionStart),r.quaternion.copy(this.worldQuaternionStart),M.set(1e-10,1e-10,1e-10).add(this.worldPositionStart).sub(this.worldPosition).multiplyScalar(-1),M.applyQuaternion(this.worldQuaternionStart.clone().invert()),r.scale.copy(M),r.visible=this.dragging):(r.quaternion.copy(t),this.dragging?r.position.copy(this.worldPositionStart):r.position.copy(this.worldPosition),this.axis&&(r.visible=this.axis.search(r.name)!==-1));continue}if(r.quaternion.copy(t),this.mode===`translate`||this.mode===`scale`){let e=.99,n=.2;r.name===`X`&&Math.abs(F.copy(L).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Y`&&Math.abs(F.copy(R).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`Z`&&Math.abs(F.copy(z).applyQuaternion(t).dot(this.eye))>e&&(r.scale.set(1e-10,1e-10,1e-10),r.visible=!1),r.name===`XY`&&Math.abs(F.copy(z).applyQuaternion(t).dot(this.eye))Math.PI&&(r-=V),i<-Math.PI?i+=V:i>Math.PI&&(i-=V),r<=i?this._spherical.theta=Math.max(r,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(r+i)/2?Math.max(r,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let a=!1;if(this.enableDamping?this._currentScale=p.lerp(this._currentScale,this._scale,this.dampingFactor):this._currentScale=this._scale,this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{let e=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._currentScale),a=Math.abs(e-this._spherical.radius)>U*100}if(B.setFromSpherical(this._spherical),B.applyQuaternion(this._quatInverse),n.copy(this.target).add(B),this.object.parent?this.object.parent.worldToLocal(n):this.object.position.copy(n),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let e=null;if(this.object.isPerspectiveCamera){let t=B.length();e=this._clampDistance(t*this._currentScale);let n=t-e;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),a=Math.abs(n)>U}else if(this.object.isOrthographicCamera){let n=new t(this._mouse.x,this._mouse.y,0);n.unproject(this.object);let r=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._currentScale)),this.object.updateProjectionMatrix(),a=Math.abs(r-this.object.zoom)>U;let i=new t(this._mouse.x,this._mouse.y,0);i.unproject(this.object),this.object.position.sub(i).add(n),this.object.updateMatrixWorld(),e=B.length()}else console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.`),this.zoomToCursor=!1;e!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(e).add(this.object.position):(ut.origin.copy(this.object.position),ut.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(ut.direction))U&&(this.object.updateProjectionMatrix(),a=!0)}return this._scale=1,a||this._lastPosition.distanceToSquared(this.object.position)>U||8*(1-this._lastQuaternion.dot(this.object.quaternion))>U||this._lastTargetPosition.distanceToSquared(this.target)>U?(this.dispatchEvent(ot),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),this._lastIsDamping=!0,this._isDamping=!0,!0):(this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),this.state===H.NONE&&(this._lastIsDamping=this._isDamping,this._isDamping=!1),this._lastIsDamping&&!this._isDamping&&this.state===H.NONE&&(this._isDamping=!1,this._lastIsDamping=!1,this.dispatchEvent(lt)),this._performCursorZoom=!1,!1)}_getAutoRotationAngle(e){return e===null?V/60/60*this.autoRotateSpeed:V/60*this.autoRotateSpeed*e}_getZoomScale(e){let t=Math.abs(e*.01);return .95**(this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){B.setFromMatrixColumn(t,0),B.multiplyScalar(-e),this._panOffset.add(B)}_panUp(e,t){this.screenSpacePanning===!0?B.setFromMatrixColumn(t,1):(B.setFromMatrixColumn(t,0),B.crossVectors(this.object.up,B)),B.multiplyScalar(e),this._panOffset.add(B)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){this.object.getWorldPosition(B).sub(this.target);let r=B.length();r*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*r/n.clientHeight,this.object.matrixWorld),this._panUp(2*t*r/n.clientHeight,this.object.matrixWorld)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrixWorld),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrixWorld)):(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.`),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;let n=this.domElement.getBoundingClientRect(),r=e-n.left,i=t-n.top,a=n.width,o=n.height;this._mouse.x=r/a*2-1,this._mouse.y=-(i/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(V*this._rotateDelta.x/t.clientHeight),this._rotateUp(V*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this._rotateUp(V*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this._rotateUp(-V*this.rotateSpeed/this.domElement.clientHeight):this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this._rotateLeft(V*this.rotateSpeed/this.domElement.clientHeight):this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this._rotateLeft(-V*this.rotateSpeed/this.domElement.clientHeight):this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateStart.set(n,r)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panStart.set(n,r)}}_handleTouchStartDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateEnd.set(n,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(V*this._rotateDelta.x/t.clientHeight),this._rotateUp(V*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panEnd.set(n,r)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyEnd.set(0,i),this._dollyDelta.set(0,(this._dollyEnd.y/this._dollyStart.y)**+this.zoomSpeed),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);let a=(e.pageX+t.x)*.5,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t4?n=e.array[i*e.itemSize+t]:(t===0?n=e.getX(i):t===1?n=e.getY(i):t===2?n=e.getZ(i):t===3&&(n=e.getW(i)),e.normalized===!0&&(n=p.normalize(n,e.array))),r.min[t]=Math.min(r.min[t],n),r.max[t]=Math.max(r.max[t],n)}return r}function Kt(e){return Math.ceil(e/4)*4}function qt(e,t=0){let n=Kt(e.byteLength);if(n!==e.byteLength){let r=new Uint8Array(n);if(r.set(new Uint8Array(e)),t!==0)for(let i=e.byteLength;i`u`&&typeof OffscreenCanvas<`u`?new OffscreenCanvas(1,1):document.createElement(`canvas`)}function Yt(e,t){if(e.toBlob!==void 0)return new Promise(n=>e.toBlob(n,t));let n;return t===`image/jpeg`?n=.92:t===`image/webp`&&(n=.8),e.convertToBlob({type:t,quality:n})}var Xt=class{constructor(){this.plugins=[],this.options={},this.pending=[],this.buffers=[],this.byteOffset=0,this.buffers=[],this.nodeMap=new Map,this.skins=[],this.extensionsUsed={},this.extensionsRequired={},this.uids=new Map,this.uid=0,this.json={asset:{version:`2.0`,generator:`THREE.GLTFExporter r`+o}},this.cache={meshes:new Map,attributes:new Map,attributesNormalized:new Map,materials:new Map,textures:new Map,images:new Map}}setPlugins(e){this.plugins=e}async write(e,t,n={}){this.options=Object.assign({binary:!1,trs:!1,onlyVisible:!0,maxTextureSize:1/0,animations:[],includeCustomExtensions:!1},n),this.options.animations.length>0&&(this.options.trs=!0),this.processInput(e),await Promise.all(this.pending);let r=this,i=r.buffers,a=r.json;n=r.options;let o=r.extensionsUsed,s=r.extensionsRequired,c=new Blob(i,{type:`application/octet-stream`}),l=Object.keys(o),u=Object.keys(s);if(l.length>0&&(a.extensionsUsed=l),u.length>0&&(a.extensionsRequired=u),a.buffers&&a.buffers.length>0&&(a.buffers[0].byteLength=c.size),n.binary===!0){let e=new FileReader;e.readAsArrayBuffer(c),e.onloadend=function(){let n=qt(e.result),r=new DataView(new ArrayBuffer(zt));r.setUint32(0,n.byteLength,!0),r.setUint32(4,Vt,!0);let i=qt(Ut(JSON.stringify(a)),32),o=new DataView(new ArrayBuffer(zt));o.setUint32(0,i.byteLength,!0),o.setUint32(4,Bt,!0);let s=new ArrayBuffer(It),c=new DataView(s);c.setUint32(0,Lt,!0),c.setUint32(4,Rt,!0);let l=It+o.byteLength+i.byteLength+r.byteLength+n.byteLength;c.setUint32(8,l,!0);let u=new Blob([s,o,i,r,n],{type:`application/octet-stream`}),d=new FileReader;d.readAsArrayBuffer(u),d.onloadend=function(){t(d.result)}}}else if(a.buffers&&a.buffers.length>0){let e=new FileReader;e.readAsDataURL(c),e.onloadend=function(){let n=e.result;a.buffers[0].uri=n,t(a)}}else t(a)}serializeUserData(e,t){if(Object.keys(e.userData).length===0)return;let n=this.options,r=this.extensionsUsed;try{let i=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&i.gltfExtensions){t.extensions===void 0&&(t.extensions={});for(let e in i.gltfExtensions)t.extensions[e]=i.gltfExtensions[e],r[e]=!0;delete i.gltfExtensions}Object.keys(i).length>0&&(t.extras=i)}catch(t){console.warn(`THREE.GLTFExporter: userData of '`+e.name+`' won't be serialized because of JSON.stringify error - `+t.message)}}getUID(e,t=!1){if(this.uids.has(e)===!1){let t=new Map;t.set(!0,this.uid++),t.set(!1,this.uid++),this.uids.set(e,t)}return this.uids.get(e).get(t)}isNormalizedNormalAttribute(e){if(this.cache.attributesNormalized.has(e))return!1;let n=new t;for(let t=0,r=e.count;t5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let n=this.cache;if(n.attributesNormalized.has(e))return n.attributesNormalized.get(e);let r=e.clone(),i=new t;for(let e=0,t=r.count;e4?r=e.array[i*e.itemSize+n]:(n===0?r=e.getX(i):n===1?r=e.getY(i):n===2?r=e.getZ(i):n===3&&(r=e.getW(i)),e.normalized===!0&&(r=p.normalize(r,e.array))),t===W.FLOAT?l.setFloat32(u,r,!0):t===W.INT?l.setInt32(u,r,!0):t===W.UNSIGNED_INT?l.setUint32(u,r,!0):t===W.SHORT?l.setInt16(u,r,!0):t===W.UNSIGNED_SHORT?l.setUint16(u,r,!0):t===W.BYTE?l.setInt8(u,r):t===W.UNSIGNED_BYTE&&l.setUint8(u,r),u+=o}u%s!==0&&(u+=s-u%s)}let d={buffer:this.processBuffer(l.buffer),byteOffset:this.byteOffset,byteLength:c};return i!==void 0&&(d.target=i),i===W.ARRAY_BUFFER&&(d.byteStride=s),this.byteOffset+=c,a.bufferViews.push(d),{id:a.bufferViews.length-1,byteLength:0}}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||=[],new Promise(function(r){let i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){let e=qt(i.result),a={buffer:t.processBuffer(e),byteOffset:t.byteOffset,byteLength:e.byteLength};t.byteOffset+=e.byteLength,r(n.bufferViews.push(a)-1)}})}processAccessor(e,t,n,r){let i=this.json,a={1:`SCALAR`,2:`VEC2`,3:`VEC3`,4:`VEC4`,9:`MAT3`,16:`MAT4`},o;if(e.array.constructor===Float32Array)o=W.FLOAT;else if(e.array.constructor===Int32Array)o=W.INT;else if(e.array.constructor===Uint32Array)o=W.UNSIGNED_INT;else if(e.array.constructor===Int16Array)o=W.SHORT;else if(e.array.constructor===Uint16Array)o=W.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)o=W.BYTE;else if(e.array.constructor===Uint8Array)o=W.UNSIGNED_BYTE;else throw Error(`THREE.GLTFExporter: Unsupported bufferAttribute component type: `+e.array.constructor.name);if(n===void 0&&(n=0),(r===void 0||r===1/0)&&(r=e.count),r===0)return null;let s=Gt(e,n,r),c;t!==void 0&&(c=e===t.index?W.ELEMENT_ARRAY_BUFFER:W.ARRAY_BUFFER);let l=this.processBufferView(e,o,n,r,c),u={bufferView:l.id,byteOffset:l.byteOffset,componentType:o,count:r,max:s.max,min:s.min,type:a[e.itemSize]};return e.normalized===!0&&(u.normalized=!0),i.accessors||=[],i.accessors.push(u)-1}processImage(e,t,n,r=`image/png`){if(e!==null){let i=this,a=i.cache,o=i.json,s=i.options,c=i.pending;a.images.has(e)||a.images.set(e,{});let l=a.images.get(e),u=r+`:flipY/`+n.toString();if(l[u]!==void 0)return l[u];o.images||=[];let d={mimeType:r},f=Jt();f.width=Math.min(e.width,s.maxTextureSize),f.height=Math.min(e.height,s.maxTextureSize);let p=f.getContext(`2d`,{willReadFrequently:!0});if(n===!0&&(p.translate(0,f.height),p.scale(1,-1)),e.data!==void 0){t!==1023&&console.error(`GLTFExporter: Only RGBAFormat is supported.`,t),(e.width>s.maxTextureSize||e.height>s.maxTextureSize)&&console.warn(`GLTFExporter: Image size is bigger than maxTextureSize`,e);let n=new Uint8ClampedArray(e.height*e.width*4);for(let t=0;ti.processBufferViewImage(e)).then(e=>{d.bufferView=e})):f.toDataURL===void 0?c.push(Yt(f,r).then(e=>new FileReader().readAsDataURL(e)).then(e=>{d.uri=e})):d.uri=f.toDataURL(r);let m=o.images.push(d)-1;return l[u]=m,m}else throw Error(`THREE.GLTFExporter: No valid image data found. Unable to process texture.`)}processSampler(e){let t=this.json;t.samplers||=[];let n={magFilter:G[e.magFilter],minFilter:G[e.minFilter],wrapS:G[e.wrapS],wrapT:G[e.wrapT]};return t.samplers.push(n)-1}processTexture(e){let t=this.options,n=this.cache,r=this.json;if(n.textures.has(e))return n.textures.get(e);let i={keep:!0,newTexture:null};if(this._invokeAll(function(t){t.beforeWriteTexture&&t.beforeWriteTexture(e,i)}),i.keep===!1)return null;i.newTexture!=null&&(e=i.newTexture),r.textures||=[],e instanceof s&&(e=At(e,t.maxTextureSize));let a=e.userData.mimeType;a===`image/webp`&&(a=`image/png`);let o={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,a)};e.name&&(o.name=e.name),this._invokeAll(function(t){t.writeTexture&&t.writeTexture(e,o)});let c=r.textures.push(o)-1;return n.textures.set(e,c),c}processMaterial(e){let t=this.cache,n=this.json;if(t.materials.has(e))return t.materials.get(e);if(e.isShaderMaterial)return console.warn(`GLTFExporter: THREE.ShaderMaterial not supported.`),null;n.materials||=[];let r={pbrMetallicRoughness:{}};e.isMeshStandardMaterial!==!0&&e.isMeshBasicMaterial!==!0&&console.warn(`GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.`);let i=e.color.toArray().concat([e.opacity]);Ht(i,[1,1,1,1])||(r.pbrMetallicRoughness.baseColorFactor=i),e.isMeshStandardMaterial?(r.pbrMetallicRoughness.metallicFactor=e.metalness,r.pbrMetallicRoughness.roughnessFactor=e.roughness):(r.pbrMetallicRoughness.metallicFactor=.5,r.pbrMetallicRoughness.roughnessFactor=.5);let a=e.metalnessMap?.image?e.metalnessMap:void 0,o=e.roughnessMap?.image?e.roughnessMap:void 0;if(a||o){let e=this.buildMetalRoughTexture(a,o),t={index:this.processTexture(e),channel:e.channel};this.applyTextureTransform(t,e),r.pbrMetallicRoughness.metallicRoughnessTexture=t}if(e.map){let t={index:this.processTexture(e.map),texCoord:e.map.channel};this.applyTextureTransform(t,e.map),r.pbrMetallicRoughness.baseColorTexture=t}if(e.emissive){let t=e.emissive;if(Math.max(t.r,t.g,t.b)>0&&(r.emissiveFactor=e.emissive.toArray()),e.emissiveMap?.image){let t={index:this.processTexture(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(t,e.emissiveMap),r.emissiveTexture=t}}if(e.normalMap?.image){let t={index:this.processTexture(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&e.normalScale.x!==1&&(t.scale=e.normalScale.x),this.applyTextureTransform(t,e.normalMap),r.normalTexture=t}if(e.aoMap?.image){let t={index:this.processTexture(e.aoMap),texCoord:e.aoMap.channel};e.aoMapIntensity!==1&&(t.strength=e.aoMapIntensity),this.applyTextureTransform(t,e.aoMap),r.occlusionTexture=t}e.transparent?r.alphaMode=`BLEND`:e.alphaTest>0&&(r.alphaMode=`MASK`,r.alphaCutoff=e.alphaTest),e.side===2&&(r.doubleSided=!0),e.name!==``&&(r.name=e.name),this.serializeUserData(e,r),this._invokeAll(function(t){t.writeMaterial&&t.writeMaterial(e,r)});let s=n.materials.push(r)-1;return t.materials.set(e,s),s}processMesh(e){let t={keep:!0};if(this._invokeAll(function(n){n.beforeWriteMesh&&n.beforeWriteMesh(e,t)}),t.keep!=1)return null;let n=this.cache,r=this.json,i=[e.geometry.uuid];if(Array.isArray(e.material))for(let t=0,n=e.material.length;t0){let t=[],r=[],i={};if(e.morphTargetDictionary!==void 0)for(let t in e.morphTargetDictionary)i[e.morphTargetDictionary[t]]=t;for(let a=0;a0&&(c.extras={},c.extras.targetNames=r)}let h=Array.isArray(e.material);if(h&&o.groups.length===0)return null;let g=!1;if(h&&o.index===null){let e=[];for(let t=0,n=o.attributes.position.count;t0&&(t.targets=d),o.index!==null){let r=this.getUID(o.index);(v[e].start!==void 0||v[e].count!==void 0)&&(r+=`:`+v[e].start+`:`+v[e].count),n.attributes.has(r)?t.indices=n.attributes.get(r):(t.indices=this.processAccessor(o.index,o,v[e].start,v[e].count),n.attributes.set(r,t.indices)),t.indices===null&&delete t.indices}let r=this.processMaterial(_[v[e].materialIndex]);r!==null&&(t.material=r),u.push(t)}g===!0&&o.setIndex(null),c.primitives=u,r.meshes||=[],this._invokeAll(function(t){t.writeMesh&&t.writeMesh(e,c)});let y=r.meshes.push(c)-1;return n.meshes.set(a,y),y}detectMeshQuantization(e,t){if(this.extensionsUsed[Nt])return;let n;switch(t.array.constructor){case Int8Array:n=`byte`;break;case Uint8Array:n=`unsigned byte`;break;case Int16Array:n=`short`;break;case Uint16Array:n=`unsigned short`;break;default:return}t.normalized&&(n+=` normalized`);let r=e.split(`_`,1)[0];jt[r]&&jt[r].includes(n)&&(this.extensionsUsed[Nt]=!0,this.extensionsRequired[Nt]=!0)}processCamera(e){let t=this.json;t.cameras||=[];let n=e.isOrthographicCamera,r={type:n?`orthographic`:`perspective`};return n?r.orthographic={xmag:e.right*2,ymag:e.top*2,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:p.degToRad(e.fov),zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near},e.name!==``&&(r.name=e.type),t.cameras.push(r)-1}processAnimation(e,t){let n=this.json,i=this.nodeMap;n.animations||=[],e=Mt.Utils.mergeMorphTargetTracks(e.clone(),t);let a=e.tracks,o=[],s=[];for(let e=0;e0){let t=[];for(let n=0,i=e.children.length;n0&&(a.children=t)}this._invokeAll(function(t){t.writeNode&&t.writeNode(e,a)});let o=n.nodes.push(a)-1;return i.set(e,o),o}processScene(e){let t=this.json,n=this.options;t.scenes||(t.scenes=[],t.scene=0);let r={};e.name!==``&&(r.name=e.name),t.scenes.push(r);let i=[];for(let t=0,r=e.children.length;t0&&(r.nodes=i),this.serializeUserData(e,r)}processObjects(e){let t=new ee;t.name=`AuxScene`;for(let n=0;n0&&this.processObjects(n);for(let e=0;e0&&(a.range=e.distance)):e.isSpotLight&&(a.type=`spot`,e.distance>0&&(a.range=e.distance),a.spot={},a.spot.innerConeAngle=(1-e.penumbra)*e.angle,a.spot.outerConeAngle=e.angle),e.decay!==void 0&&e.decay!==2&&console.warn(`THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2.`),e.target&&(e.target.parent!==e||e.target.position.x!==0||e.target.position.y!==0||e.target.position.z!==-1)&&console.warn(`THREE.GLTFExporter: Light direction may be lost. For best results, make light.target a child of the light with position 0,0,-1.`),i[this.name]||(r.extensions=r.extensions||{},r.extensions[this.name]={lights:[]},i[this.name]=!0);let o=r.extensions[this.name].lights;o.push(a),t.extensions=t.extensions||{},t.extensions[this.name]={light:o.length-1}}},Qt=class{constructor(e){this.writer=e,this.name=`KHR_materials_unlit`}writeMaterial(e,t){if(!e.isMeshBasicMaterial)return;let n=this.writer.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},n[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}},$t=class{constructor(e){this.writer=e,this.name=`KHR_materials_clearcoat`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.clearcoat===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.clearcoatFactor=e.clearcoat,e.clearcoatMap){let t={index:n.processTexture(e.clearcoatMap),texCoord:e.clearcoatMap.channel};n.applyTextureTransform(t,e.clearcoatMap),i.clearcoatTexture=t}if(i.clearcoatRoughnessFactor=e.clearcoatRoughness,e.clearcoatRoughnessMap){let t={index:n.processTexture(e.clearcoatRoughnessMap),texCoord:e.clearcoatRoughnessMap.channel};n.applyTextureTransform(t,e.clearcoatRoughnessMap),i.clearcoatRoughnessTexture=t}if(e.clearcoatNormalMap){let t={index:n.processTexture(e.clearcoatNormalMap),texCoord:e.clearcoatNormalMap.channel};e.clearcoatNormalScale.x!==1&&(t.scale=e.clearcoatNormalScale.x),n.applyTextureTransform(t,e.clearcoatNormalMap),i.clearcoatNormalTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},en=class{constructor(e){this.writer=e,this.name=`KHR_materials_dispersion`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.dispersion===0)return;let n=this.writer.extensionsUsed,r={};r.dispersion=e.dispersion,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},tn=class{constructor(e){this.writer=e,this.name=`KHR_materials_iridescence`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.iridescence===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.iridescenceFactor=e.iridescence,e.iridescenceMap){let t={index:n.processTexture(e.iridescenceMap),texCoord:e.iridescenceMap.channel};n.applyTextureTransform(t,e.iridescenceMap),i.iridescenceTexture=t}if(i.iridescenceIor=e.iridescenceIOR,i.iridescenceThicknessMinimum=e.iridescenceThicknessRange[0],i.iridescenceThicknessMaximum=e.iridescenceThicknessRange[1],e.iridescenceThicknessMap){let t={index:n.processTexture(e.iridescenceThicknessMap),texCoord:e.iridescenceThicknessMap.channel};n.applyTextureTransform(t,e.iridescenceThicknessMap),i.iridescenceThicknessTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},nn=class{constructor(e){this.writer=e,this.name=`KHR_materials_transmission`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.transmissionFactor=e.transmission,e.transmissionMap){let t={index:n.processTexture(e.transmissionMap),texCoord:e.transmissionMap.channel};n.applyTextureTransform(t,e.transmissionMap),i.transmissionTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},rn=class{constructor(e){this.writer=e,this.name=`KHR_materials_volume`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.transmission===0)return;let n=this.writer,r=n.extensionsUsed,i={};if(i.thicknessFactor=e.thickness,e.thicknessMap){let t={index:n.processTexture(e.thicknessMap),texCoord:e.thicknessMap.channel};n.applyTextureTransform(t,e.thicknessMap),i.thicknessTexture=t}e.attenuationDistance!==1/0&&(i.attenuationDistance=e.attenuationDistance),i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},an=class{constructor(e){this.writer=e,this.name=`KHR_materials_ior`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.ior===1.5)return;let n=this.writer.extensionsUsed,r={};r.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},on=class{constructor(e){this.writer=e,this.name=`KHR_materials_specular`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.specularIntensity===1&&e.specularColor.equals(Ft)&&!e.specularIntensityMap&&!e.specularColorMap)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.specularIntensityMap){let t={index:n.processTexture(e.specularIntensityMap),texCoord:e.specularIntensityMap.channel};n.applyTextureTransform(t,e.specularIntensityMap),i.specularTexture=t}if(e.specularColorMap){let t={index:n.processTexture(e.specularColorMap),texCoord:e.specularColorMap.channel};n.applyTextureTransform(t,e.specularColorMap),i.specularColorTexture=t}i.specularFactor=e.specularIntensity,i.specularColorFactor=e.specularColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},sn=class{constructor(e){this.writer=e,this.name=`KHR_materials_sheen`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.sheen==0)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.sheenRoughnessMap){let t={index:n.processTexture(e.sheenRoughnessMap),texCoord:e.sheenRoughnessMap.channel};n.applyTextureTransform(t,e.sheenRoughnessMap),i.sheenRoughnessTexture=t}if(e.sheenColorMap){let t={index:n.processTexture(e.sheenColorMap),texCoord:e.sheenColorMap.channel};n.applyTextureTransform(t,e.sheenColorMap),i.sheenColorTexture=t}i.sheenRoughnessFactor=e.sheenRoughness,i.sheenColorFactor=e.sheenColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},cn=class{constructor(e){this.writer=e,this.name=`KHR_materials_anisotropy`}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||e.anisotropy==0)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.anisotropyMap){let t={index:n.processTexture(e.anisotropyMap)};n.applyTextureTransform(t,e.anisotropyMap),i.anisotropyTexture=t}i.anisotropyStrength=e.anisotropy,i.anisotropyRotation=e.anisotropyRotation,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},ln=class{constructor(e){this.writer=e,this.name=`KHR_materials_emissive_strength`}writeMaterial(e,t){if(!e.isMeshStandardMaterial||e.emissiveIntensity===1)return;let n=this.writer.extensionsUsed,r={};r.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=r,n[this.name]=!0}},un=class{constructor(e){this.writer=e,this.name=`EXT_materials_bump`}writeMaterial(e,t){if(!e.isMeshStandardMaterial||e.bumpScale===1&&!e.bumpMap)return;let n=this.writer,r=n.extensionsUsed,i={};if(e.bumpMap){let t={index:n.processTexture(e.bumpMap),texCoord:e.bumpMap.channel};n.applyTextureTransform(t,e.bumpMap),i.bumpTexture=t}i.bumpFactor=e.bumpScale,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}},dn=class{constructor(e){this.writer=e,this.name=`EXT_mesh_gpu_instancing`}writeNode(e,n){if(!e.isInstancedMesh)return;let r=this.writer,i=e,a=new Float32Array(i.count*3),o=new Float32Array(i.count*4),s=new Float32Array(i.count*3),c=new x,l=new t,u=new O,d=new t;for(let e=0;ee.times[e.times.length-1]){if(Math.abs(e.times[e.times.length-1]-t)t){i.set(e.times.slice(0,c+1),0),i[c+1]=t,i.set(e.times.slice(c+1),c+2),a.set(e.values.slice(0,(c+1)*r),0),a.set(o.evaluate(t),(c+1)*r),a.set(e.values.slice((c+1)*r),(c+2)*r),s=c+1;break}}return e.times=i,e.values=a,s},mergeMorphTargetTracks:function(e,t){let n=[],i={},a=e.tracks;for(let e=0;e{e.isMesh&&(e.material.envMap=this.envMap,e.material.needsUpdate=!0)}),this)}updateMatrixWorld(e){super.updateMatrixWorld(e),this.motionController&&(this.motionController.updateFromGamepad(),Object.values(this.motionController.components).forEach(e=>{Object.values(e.visualResponses).forEach(e=>{let{valueNode:t,minNode:n,maxNode:r,value:i,valueNodeProperty:a}=e;t&&(a===Ne.VisualResponseProperty.VISIBILITY?t.visible=i:a===Ne.VisualResponseProperty.TRANSFORM&&(t.quaternion.slerpQuaternions(n.quaternion,r.quaternion,i),t.position.lerpVectors(n.position,r.position,i)))})}))}};function hn(e,t){Object.values(e.components).forEach(e=>{let{type:n,touchPointNodeName:r,visualResponses:i}=e;if(n===Ne.ComponentType.TOUCHPAD)if(e.touchPointNode=t.getObjectByName(r),e.touchPointNode){let t=new S(new we(.001),new te({color:255}));e.touchPointNode.add(t)}else console.warn(`Could not find touch dot, ${e.touchPointNodeName}, in touchpad component ${e.id}`);Object.values(i).forEach(e=>{let{valueNodeName:n,minNodeName:r,maxNodeName:i,valueNodeProperty:a}=e;if(a===Ne.VisualResponseProperty.TRANSFORM){if(e.minNode=t.getObjectByName(r),e.maxNode=t.getObjectByName(i),!e.minNode){console.warn(`Could not find ${r} in the model`);return}if(!e.maxNode){console.warn(`Could not find ${i} in the model`);return}}e.valueNode=t.getObjectByName(n),e.valueNode||console.warn(`Could not find ${n} in the model`)})})}function gn(e,t){hn(e.motionController,t),e.envMap&&t.traverse(t=>{t.isMesh&&(t.material.envMap=e.envMap,t.material.needsUpdate=!0)}),e.layers.mask!=0&&t.traverse(t=>{t.layers.mask=e.layers.mask}),e.add(t)}var _n=class{constructor(e=null,t=null){this.gltfLoader=e,this.path=fn,this._assetCache={},this.onLoad=t,this.gltfLoader||=new je}setPath(e){return this.path=e,this}createControllerModel(e){let t=new mn,n=null;return e.addEventListener(`connected`,e=>{let r=e.data;r.targetRayMode!==`tracked-pointer`||!r.gamepad||r.hand||Pe(r,this.path,pn).then(({profile:e,assetPath:i})=>{t.motionController=new Me(r,e,i);let a=this._assetCache[t.motionController.assetUrl];if(a)n=a.scene.clone(),gn(t,n),this.onLoad&&this.onLoad(n);else{if(!this.gltfLoader)throw Error(`GLTFLoader not set.`);this.gltfLoader.setPath(``),this.gltfLoader.load(t.motionController.assetUrl,e=>{this._assetCache[t.motionController.assetUrl]=e,n=e.scene.clone(),gn(t,n),this.onLoad&&this.onLoad(n)},null,()=>{throw Error(`Asset ${t.motionController.assetUrl} missing or malformed.`)})}}).catch(e=>{console.warn(e)})}),e.addEventListener(`disconnected`,()=>{t.motionController=null,t.remove(n),n=null}),t}},vn=`https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/`,yn=class{constructor(e,t,n,r,i=null,a=null){this.controller=t,this.handModel=e,this.bones=[],i===null&&(i=new je,i.setPath(n||vn)),i.load(`${r}.glb`,e=>{let t=e.scene.children[0];this.handModel.add(t),t.layers.mask=this.handModel.layers.mask;let n=t.getObjectByProperty(`type`,`SkinnedMesh`);n.frustumCulled=!1,n.castShadow=!0,n.receiveShadow=!0,[`wrist`,`thumb-metacarpal`,`thumb-phalanx-proximal`,`thumb-phalanx-distal`,`thumb-tip`,`index-finger-metacarpal`,`index-finger-phalanx-proximal`,`index-finger-phalanx-intermediate`,`index-finger-phalanx-distal`,`index-finger-tip`,`middle-finger-metacarpal`,`middle-finger-phalanx-proximal`,`middle-finger-phalanx-intermediate`,`middle-finger-phalanx-distal`,`middle-finger-tip`,`ring-finger-metacarpal`,`ring-finger-phalanx-proximal`,`ring-finger-phalanx-intermediate`,`ring-finger-phalanx-distal`,`ring-finger-tip`,`pinky-finger-metacarpal`,`pinky-finger-phalanx-proximal`,`pinky-finger-phalanx-intermediate`,`pinky-finger-phalanx-distal`,`pinky-finger-tip`].forEach(e=>{let n=t.getObjectByName(e);n===void 0?console.warn(`Couldn't find ${e} in ${r} hand mesh`):n.jointName=e,this.bones.push(n)}),a&&a(t)})}updateMesh(){let e=this.controller.joints;for(let t=0;t #include #include #include #include uniform float linewidth; uniform vec2 resolution; attribute vec3 instanceStart; attribute vec3 instanceEnd; attribute vec3 instanceColorStart; attribute vec3 instanceColorEnd; #ifdef WORLD_UNITS varying vec4 worldPos; varying vec3 worldStart; varying vec3 worldEnd; #ifdef USE_DASH varying vec2 vUv; #endif #else varying vec2 vUv; #endif #ifdef USE_DASH uniform float dashScale; attribute float instanceDistanceStart; attribute float instanceDistanceEnd; varying float vLineDistance; #endif void trimSegment( const in vec4 start, inout vec4 end ) { // trim end segment so it terminates between the camera plane and the near plane // conservative estimate of the near plane float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column float nearEstimate = - 0.5 * b / a; float alpha = ( nearEstimate - start.z ) / ( end.z - start.z ); end.xyz = mix( start.xyz, end.xyz, alpha ); } void main() { #ifdef USE_COLOR vColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd; #endif #ifdef USE_DASH vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd; vUv = uv; #endif float aspect = resolution.x / resolution.y; // camera space vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 ); vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 ); #ifdef WORLD_UNITS worldStart = start.xyz; worldEnd = end.xyz; #else vUv = uv; #endif // special case for perspective projection, and segments that terminate either in, or behind, the camera plane // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space // but we need to perform ndc-space calculations in the shader, so we must address this issue directly // perhaps there is a more elegant solution -- WestLangley bool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column if ( perspective ) { if ( start.z < 0.0 && end.z >= 0.0 ) { trimSegment( start, end ); } else if ( end.z < 0.0 && start.z >= 0.0 ) { trimSegment( end, start ); } } // clip space vec4 clipStart = projectionMatrix * start; vec4 clipEnd = projectionMatrix * end; // ndc space vec3 ndcStart = clipStart.xyz / clipStart.w; vec3 ndcEnd = clipEnd.xyz / clipEnd.w; // direction vec2 dir = ndcEnd.xy - ndcStart.xy; // account for clip-space aspect ratio dir.x *= aspect; dir = normalize( dir ); #ifdef WORLD_UNITS vec3 worldDir = normalize( end.xyz - start.xyz ); vec3 tmpFwd = normalize( mix( start.xyz, end.xyz, 0.5 ) ); vec3 worldUp = normalize( cross( worldDir, tmpFwd ) ); vec3 worldFwd = cross( worldDir, worldUp ); worldPos = position.y < 0.5 ? start: end; // height offset float hw = linewidth * 0.5; worldPos.xyz += position.x < 0.0 ? hw * worldUp : - hw * worldUp; // don't extend the line if we're rendering dashes because we // won't be rendering the endcaps #ifndef USE_DASH // cap extension worldPos.xyz += position.y < 0.5 ? - hw * worldDir : hw * worldDir; // add width to the box worldPos.xyz += worldFwd * hw; // endcaps if ( position.y > 1.0 || position.y < 0.0 ) { worldPos.xyz -= worldFwd * 2.0 * hw; } #endif // project the worldpos vec4 clip = projectionMatrix * worldPos; // shift the depth of the projected points so the line // segments overlap neatly vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd; clip.z = clipPose.z * clip.w; #else vec2 offset = vec2( dir.y, - dir.x ); // undo aspect ratio adjustment dir.x /= aspect; offset.x /= aspect; // sign flip if ( position.x < 0.0 ) offset *= - 1.0; // endcaps if ( position.y < 0.0 ) { offset += - dir; } else if ( position.y > 1.0 ) { offset += dir; } // adjust for linewidth offset *= linewidth; // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ... offset /= resolution.y; // select end vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd; // back to clip space offset *= clip.w; clip.xy += offset; #endif gl_Position = clip; vec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation #include #include #include } `,fragmentShader:` uniform vec3 diffuse; uniform float opacity; uniform float linewidth; #ifdef USE_DASH uniform float dashOffset; uniform float dashSize; uniform float gapSize; #endif varying float vLineDistance; #ifdef WORLD_UNITS varying vec4 worldPos; varying vec3 worldStart; varying vec3 worldEnd; #ifdef USE_DASH varying vec2 vUv; #endif #else varying vec2 vUv; #endif #include #include #include #include #include vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) { float mua; float mub; vec3 p13 = p1 - p3; vec3 p43 = p4 - p3; vec3 p21 = p2 - p1; float d1343 = dot( p13, p43 ); float d4321 = dot( p43, p21 ); float d1321 = dot( p13, p21 ); float d4343 = dot( p43, p43 ); float d2121 = dot( p21, p21 ); float denom = d2121 * d4343 - d4321 * d4321; float numer = d1343 * d4321 - d1321 * d4343; mua = numer / denom; mua = clamp( mua, 0.0, 1.0 ); mub = ( d1343 + d4321 * ( mua ) ) / d4343; mub = clamp( mub, 0.0, 1.0 ); return vec2( mua, mub ); } void main() { #include #ifdef USE_DASH if ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps if ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX #endif float alpha = opacity; #ifdef WORLD_UNITS // Find the closest points on the view ray and the line segment vec3 rayEnd = normalize( worldPos.xyz ) * 1e5; vec3 lineDir = worldEnd - worldStart; vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd ); vec3 p1 = worldStart + lineDir * params.x; vec3 p2 = rayEnd * params.y; vec3 delta = p1 - p2; float len = length( delta ); float norm = len / linewidth; #ifndef USE_DASH #ifdef USE_ALPHA_TO_COVERAGE float dnorm = fwidth( norm ); alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm ); #else if ( norm > 0.5 ) { discard; } #endif #endif #else #ifdef USE_ALPHA_TO_COVERAGE // artifacts appear on some hardware if a derivative is taken within a conditional float a = vUv.x; float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0; float len2 = a * a + b * b; float dlen = fwidth( len2 ); if ( abs( vUv.y ) > 1.0 ) { alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 ); } #else if ( abs( vUv.y ) > 1.0 ) { float a = vUv.x; float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0; float len2 = a * a + b * b; if ( len2 > 1.0 ) discard; } #endif #endif vec4 diffuseColor = vec4( diffuse, alpha ); #include #include gl_FragColor = vec4( diffuseColor.rgb, alpha ); #include #include #include #include } `};var Cn=class extends Se{constructor(e){super({type:`LineMaterial`,uniforms:i.clone(pe.line.uniforms),vertexShader:pe.line.vertexShader,fragmentShader:pe.line.fragmentShader,clipping:!0}),this.isLineMaterial=!0,this.setValues(e)}get color(){return this.uniforms.diffuse.value}set color(e){this.uniforms.diffuse.value=e}get worldUnits(){return`WORLD_UNITS`in this.defines}set worldUnits(e){e===!0?this.defines.WORLD_UNITS=``:delete this.defines.WORLD_UNITS}get linewidth(){return this.uniforms.linewidth.value}set linewidth(e){this.uniforms.linewidth&&(this.uniforms.linewidth.value=e)}get dashed(){return`USE_DASH`in this.defines}set dashed(e){e===!0!==this.dashed&&(this.needsUpdate=!0),e===!0?this.defines.USE_DASH=``:delete this.defines.USE_DASH}get dashScale(){return this.uniforms.dashScale.value}set dashScale(e){this.uniforms.dashScale.value=e}get dashSize(){return this.uniforms.dashSize.value}set dashSize(e){this.uniforms.dashSize.value=e}get dashOffset(){return this.uniforms.dashOffset.value}set dashOffset(e){this.uniforms.dashOffset.value=e}get gapSize(){return this.uniforms.gapSize.value}set gapSize(e){this.uniforms.gapSize.value=e}get opacity(){return this.uniforms.opacity.value}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}get resolution(){return this.uniforms.resolution.value}set resolution(e){this.uniforms.resolution.value.copy(e)}get alphaToCoverage(){return`USE_ALPHA_TO_COVERAGE`in this.defines}set alphaToCoverage(e){this.defines&&(e===!0!==this.alphaToCoverage&&(this.needsUpdate=!0),e===!0?this.defines.USE_ALPHA_TO_COVERAGE=``:delete this.defines.USE_ALPHA_TO_COVERAGE)}},wn=new ge,Tn=new t,En=new t,K=new ge,q=new ge,J=new ge,Dn=new t,On=new x,Y=new _,kn=new t,An=new se,jn=new ve,X=new ge,Z,Q;function Mn(e,t,n){return X.set(0,0,-t,1).applyMatrix4(e.projectionMatrix),X.multiplyScalar(1/X.w),X.x=Q/n.width,X.y=Q/n.height,X.applyMatrix4(e.projectionMatrixInverse),X.multiplyScalar(1/X.w),Math.abs(Math.max(X.x,X.y))}function Nn(e,n){let r=e.matrixWorld,i=e.geometry,a=i.attributes.instanceStart,o=i.attributes.instanceEnd,s=Math.min(i.instanceCount,a.count);for(let i=0,c=s;id&&q.z>d)continue;if(K.z>d){let e=K.z-q.z,t=(K.z-d)/e;K.lerp(q,t)}else if(q.z>d){let e=q.z-K.z,t=(q.z-d)/e;q.lerp(K,t)}K.applyMatrix4(i),q.applyMatrix4(i),K.multiplyScalar(1/K.w),q.multiplyScalar(1/q.w),K.x*=a.x/2,K.y*=a.y/2,q.x*=a.x/2,q.y*=a.y/2,Y.start.copy(K),Y.start.z=0,Y.end.copy(q),Y.end.z=0;let s=Y.closestPointToPointParameter(Dn,!0);Y.at(s,kn);let u=p.lerp(K.z,q.z,s),f=u>=-1&&u<=1,m=Dn.distanceTo(kn){this.scheduleUpdate||=setTimeout(()=>this.update(),16)});t.observe(e,{attributes:!0,childList:!0,subtree:!0,characterData:!0}),this.observer=t}dispatchDOMEvent(e){e.data&&Hn(this.dom,e.type,e.data.x,e.data.y)}update(){this.image=Vn(this.dom),this.needsUpdate=!0,this.scheduleUpdate=null}dispose(){this.observer&&this.observer.disconnect(),this.scheduleUpdate=clearTimeout(this.scheduleUpdate),super.dispose()}},Bn=new WeakMap;function Vn(t){let n=document.createRange(),r=new e;function i(e){let t=[],n=!1;function r(){if(n&&(n=!1,e.restore()),t.length===0)return;let r=-1/0,i=-1/0,a=1/0,o=1/0;for(let e=0;eparseFloat(e[t])),c=(a-t)/(r-t)*(p-m);o(i,u+m/4,p,m/2,m/4),d.fillStyle=s,d.strokeStyle=n,d.lineWidth=1,d.fill(),d.stroke(),o(i,u+m/4,c+m/2,m/2,m/4),d.fillStyle=n,d.fill(),o(i+c,u,m,m,m/2),d.fillStyle=n,d.fill()}(e.type===`color`||e.type===`text`||e.type===`number`)&&(f.add({x:i,y:u,width:p,height:m}),a(t,i+parseInt(t.paddingLeft),u+parseInt(t.paddingTop),e.value),f.remove())}}let h=t.overflow===`auto`||t.overflow===`hidden`;h&&f.add({x:i,y:u,width:p,height:m});for(let n=0;na.left&&na.top&&rparseFloat(e[t])),i=a.width,o=(n-a.x)/i;e.value=t+(r-t)*o,e.dispatchEvent(new InputEvent(`input`,{bubbles:!0}))}for(let t=0;t0){let e=o[0],t=e.object,n=e.uv;$.type=i.type,$.data.set(n.x,1-n.y),t.dispatchEvent($)}}i.addEventListener(`pointerdown`,a),i.addEventListener(`pointerup`,a),i.addEventListener(`pointermove`,a),i.addEventListener(`mousedown`,a),i.addEventListener(`mouseup`,a),i.addEventListener(`mousemove`,a),i.addEventListener(`click`,a)}listenToXRControllerEvents(e){let t=this,n={move:`mousemove`,select:`click`,selectstart:`mousedown`,selectend:`mouseup`};function r(e){let r=e.target;Wn.setFromXRController(r);let i=Wn.intersectObjects(t.children,!1);if(i.length>0){let t=i[0],r=t.object,a=t.uv;$.type=n[e.type],$.data.set(a.x,1-a.y),r.dispatchEvent($)}}e.addEventListener(`move`,r),e.addEventListener(`select`,r),e.addEventListener(`selectstart`,r),e.addEventListener(`selectend`,r)}},Kn=class{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error(`THREE.Pass: .render() must be implemented in derived pass.`)}dispose(){}};new ye(-1,1,1,-1,0,1),new class extends re{constructor(){super(),this.setAttribute(`position`,new C([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute(`uv`,new C([0,2,0,0,2,0],2))}};export{In as a,_n as c,Ve as d,it as f,Ln as i,Mt as l,Gn as n,Cn as o,Fe as p,Rn as r,yn as s,Kn as t,pt as u};