From daed4a7aa268347f18a4e88192edef3be4fd3e37 Mon Sep 17 00:00:00 2001 From: tailuge Date: Fri, 27 Oct 2023 07:50:36 +0100 Subject: [PATCH] zoom --- dist/diagram.js | 2 +- dist/index.js | 2 +- src/events/keyboard.ts | 13 ++++++------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dist/diagram.js b/dist/diagram.js index b3939202..cf40923c 100644 --- a/dist/diagram.js +++ b/dist/diagram.js @@ -15,4 +15,4 @@ #else gl_FragColor = texture2D( blitTexture, vUv); #endif - }`})),o.uniforms.blitTexture.value=e,o.defines.IS_SRGB=e.colorSpace==d.KI_,o.needsUpdate=!0,s||((s=new d.Kj0(i,o)).frustrumCulled=!1);let a=new d.cPb,l=new d.xsS;l.add(s),n||(n=r=new d.CP7({antialias:!1})),n.setSize(Math.min(e.image.width,t),Math.min(e.image.height,t)),n.clear(),n.render(l,a);let c=new d.xEZ(n.domElement);return c.minFilter=e.minFilter,c.magFilter=e.magFilter,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.name=e.name,r&&(r.dispose(),r=null),c}let x={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class T{constructor(){this.pluginCallbacks=[],this.register(function(e){return new N(e)}),this.register(function(e){return new L(e)}),this.register(function(e){return new F(e)}),this.register(function(e){return new U(e)}),this.register(function(e){return new D(e)}),this.register(function(e){return new G(e)}),this.register(function(e){return new B(e)}),this.register(function(e){return new H(e)}),this.register(function(e){return new z(e)}),this.register(function(e){return new K(e)}),this.register(function(e){return new V(e)})}register(e){return -1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return -1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i=new C,o=[];for(let e=0,t=this.pluginCallbacks.length;ee.toBlob(n,t)):("image/jpeg"===t?n=.92:"image/webp"===t&&(n=.8),e.convertToBlob({type:t,quality:n}))}class C{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"}},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.buffers,i=this.json;n=this.options;let o=this.extensionsUsed,s=this.extensionsRequired,a=new Blob(r,{type:"application/octet-stream"}),l=Object.keys(o),c=Object.keys(s);if(l.length>0&&(i.extensionsUsed=l),c.length>0&&(i.extensionsRequired=c),i.buffers&&i.buffers.length>0&&(i.buffers[0].byteLength=a.size),!0===n.binary){let e=new FileReader;e.readAsArrayBuffer(a),e.onloadend=function(){var n;let r=_(e.result),o=new DataView(new ArrayBuffer(8));o.setUint32(0,r.byteLength,!0),o.setUint32(4,5130562,!0);let s=_((n=JSON.stringify(i),new TextEncoder().encode(n).buffer),32),a=new DataView(new ArrayBuffer(8));a.setUint32(0,s.byteLength,!0),a.setUint32(4,1313821514,!0);let l=new ArrayBuffer(12),c=new DataView(l);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0);let u=12+a.byteLength+s.byteLength+o.byteLength+r.byteLength;c.setUint32(8,u,!0);let h=new Blob([l,a,s,o,r],{type:"application/octet-stream"}),f=new FileReader;f.readAsArrayBuffer(h),f.onloadend=function(){t(f.result)}}}else if(i.buffers&&i.buffers.length>0){let e=new FileReader;e.readAsDataURL(a),e.onloadend=function(){let n=e.result;i.buffers[0].uri=n,t(i)}}else t(i)}serializeUserData(e,t){if(0===Object.keys(e.userData).length)return;let n=this.options,r=this.extensionsUsed;try{let i=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&i.gltfExtensions){for(let e in void 0===t.extensions&&(t.extensions={}),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(!1===this.uids.has(e)){let t=new Map;t.set(!0,this.uid++),t.set(!1,this.uid++),this.uids.set(e,t)}let n=this.uids.get(e);return n.get(t)}isNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return!1;let n=new d.Pa4;for(let t=0,r=e.count;t5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);let n=e.clone(),r=new d.Pa4;for(let e=0,t=n.count;e4?r=e.array[i*e.itemSize+n]:(0===n?r=e.getX(i):1===n?r=e.getY(i):2===n?r=e.getZ(i):3===n&&(r=e.getW(i)),!0===e.normalized&&(r=d.M8C.normalize(r,e.array))),t===R.FLOAT?l.setFloat32(c,r,!0):t===R.INT?l.setInt32(c,r,!0):t===R.UNSIGNED_INT?l.setUint32(c,r,!0):t===R.SHORT?l.setInt16(c,r,!0):t===R.UNSIGNED_SHORT?l.setUint16(c,r,!0):t===R.BYTE?l.setInt8(c,r):t===R.UNSIGNED_BYTE&&l.setUint8(c,r),c+=o}let u={buffer:this.processBuffer(l.buffer),byteOffset:this.byteOffset,byteLength:a};void 0!==i&&(u.target=i),i===R.ARRAY_BUFFER&&(u.byteStride=e.itemSize*o),this.byteOffset+=a,s.bufferViews.push(u);let h={id:s.bufferViews.length-1,byteLength:0};return h}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||(n.bufferViews=[]),new Promise(function(r){let i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){let e=_(i.result),o={buffer:t.processBuffer(e),byteOffset:t.byteOffset,byteLength:e.byteLength};t.byteOffset+=e.byteLength,r(n.bufferViews.push(o)-1)}})}processAccessor(e,t,n,r){let i,o;let s=this.json;if(e.array.constructor===Float32Array)i=R.FLOAT;else if(e.array.constructor===Int32Array)i=R.INT;else if(e.array.constructor===Uint32Array)i=R.UNSIGNED_INT;else if(e.array.constructor===Int16Array)i=R.SHORT;else if(e.array.constructor===Uint16Array)i=R.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)i=R.BYTE;else if(e.array.constructor===Uint8Array)i=R.UNSIGNED_BYTE;else throw Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(void 0===n&&(n=0),void 0===r&&(r=e.count),0===r)return null;let a=function(e,t,n){let r={min:Array(e.itemSize).fill(Number.POSITIVE_INFINITY),max:Array(e.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let i=t;i4?n=e.array[i*e.itemSize+t]:(0===t?n=e.getX(i):1===t?n=e.getY(i):2===t?n=e.getZ(i):3===t&&(n=e.getW(i)),!0===e.normalized&&(n=d.M8C.normalize(n,e.array))),r.min[t]=Math.min(r.min[t],n),r.max[t]=Math.max(r.max[t],n)}return r}(e,n,r);void 0!==t&&(o=e===t.index?R.ELEMENT_ARRAY_BUFFER:R.ARRAY_BUFFER);let l=this.processBufferView(e,i,n,r,o),c={bufferView:l.id,byteOffset:l.byteOffset,componentType:i,count:r,max:a.max,min:a.min,type:{1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"}[e.itemSize]};return!0===e.normalized&&(c.normalized=!0),s.accessors||(s.accessors=[]),s.accessors.push(c)-1}processImage(e,t,n,r="image/png"){if(null!==e){let i=this,o=i.cache,s=i.json,a=i.options,l=i.pending;o.images.has(e)||o.images.set(e,{});let c=o.images.get(e),u=r+":flipY/"+n.toString();if(void 0!==c[u])return c[u];s.images||(s.images=[]);let h={mimeType:r},f=I();f.width=Math.min(e.width,a.maxTextureSize),f.height=Math.min(e.height,a.maxTextureSize);let p=f.getContext("2d");if(!0===n&&(p.translate(0,f.height),p.scale(1,-1)),void 0!==e.data){t!==d.wk1&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>a.maxTextureSize||e.height>a.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=>{h.bufferView=e})):void 0!==f.toDataURL?h.uri=f.toDataURL(r):l.push(j(f,r).then(e=>new FileReader().readAsDataURL(e)).then(e=>{h.uri=e}));let v=s.images.push(h)-1;return c[u]=v,v}throw Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){let t=this.json;t.samplers||(t.samplers=[]);let n={magFilter:E[e.magFilter],minFilter:E[e.minFilter],wrapS:E[e.wrapS],wrapT:E[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);r.textures||(r.textures=[]),e instanceof d.EB7&&(e=k(e,t.maxTextureSize));let i=e.userData.mimeType;"image/webp"===i&&(i="image/png");let o={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,i)};e.name&&(o.name=e.name),this._invokeAll(function(t){t.writeTexture&&t.writeTexture(e,o)});let s=r.textures.push(o)-1;return n.textures.set(e,s),s}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||(n.materials=[]);let r={pbrMetallicRoughness:{}};!0!==e.isMeshStandardMaterial&&!0!==e.isMeshBasicMaterial&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");let i=e.color.toArray().concat([e.opacity]);if(O(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),e.metalnessMap||e.roughnessMap){let t=this.buildMetalRoughTexture(e.metalnessMap,e.roughnessMap),n={index:this.processTexture(t),channel:t.channel};this.applyTextureTransform(n,t),r.pbrMetallicRoughness.metallicRoughnessTexture=n}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,n=Math.max(t.r,t.g,t.b);if(n>0&&(r.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let t={index:this.processTexture(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(t,e.emissiveMap),r.emissiveTexture=t}}if(e.normalMap){let t={index:this.processTexture(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&1!==e.normalScale.x&&(t.scale=e.normalScale.x),this.applyTextureTransform(t,e.normalMap),r.normalTexture=t}if(e.aoMap){let t={index:this.processTexture(e.aoMap),texCoord:e.aoMap.channel};1!==e.aoMapIntensity&&(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===d.ehD&&(r.doubleSided=!0),""!==e.name&&(r.name=e.name),this.serializeUserData(e,r),this._invokeAll(function(t){t.writeMaterial&&t.writeMaterial(e,r)});let o=n.materials.push(r)-1;return t.materials.set(e,o),o}processMesh(e){let t;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(void 0!==e.morphTargetDictionary)for(let t in e.morphTargetDictionary)i[e.morphTargetDictionary[t]]=t;for(let o=0;o0&&(a.extras={},a.extras.targetNames=r)}let v=Array.isArray(e.material);if(v&&0===s.groups.length)return null;let m=v?e.material:[e.material],y=v?s.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let e=0,r=y.length;e0&&(r.targets=u),null!==s.index){let t=this.getUID(s.index);(void 0!==y[e].start||void 0!==y[e].count)&&(t+=":"+y[e].start+":"+y[e].count),n.attributes.has(t)?r.indices=n.attributes.get(t):(r.indices=this.processAccessor(s.index,s,y[e].start,y[e].count),n.attributes.set(t,r.indices)),null===r.indices&&delete r.indices}let i=this.processMaterial(m[y[e].materialIndex]);null!==i&&(r.material=i),c.push(r)}a.primitives=c,r.meshes||(r.meshes=[]),this._invokeAll(function(t){t.writeMesh&&t.writeMesh(e,a)});let b=r.meshes.push(a)-1;return n.meshes.set(o,b),b}detectMeshQuantization(e,t){let n;if(this.extensionsUsed[A])return;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];x[r]&&x[r].includes(n)&&(this.extensionsUsed[A]=!0,this.extensionsRequired[A]=!0)}processCamera(e){let t=this.json;t.cameras||(t.cameras=[]);let n=e.isOrthographicCamera,r={type:n?"orthographic":"perspective"};return n?r.orthographic={xmag:2*e.right,ymag:2*e.top,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:d.M8C.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,r=this.nodeMap;n.animations||(n.animations=[]),e=T.Utils.mergeMorphTargetTracks(e.clone(),t);let i=e.tracks,o=[],s=[];for(let e=0;e0){let t=[];for(let r=0,i=e.children.length;r0&&(i.children=t)}this._invokeAll(function(t){t.writeNode&&t.writeNode(e,i)});let o=t.nodes.push(i)-1;return r.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 d.xsS;t.name="AuxScene";for(let n=0;n0&&this.processObjects(n);for(let e=0;e0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),void 0!==e.decay&&2!==e.decay&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||0!==e.target.position.x||0!==e.target.position.y||-1!==e.target.position.z)&&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 s=r.extensions[this.name].lights;s.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:s.length-1}}}class L{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}writeMaterial(e,t){if(!e.isMeshBasicMaterial)return;let n=this.writer,r=n.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},r[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}}class B{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.clearcoat)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};n.applyTextureTransform(t,e.clearcoatNormalMap),i.clearcoatNormalTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class H{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.iridescence)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}}class F{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)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}}class U{constructor(e){this.writer=e,this.name="KHR_materials_volume"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)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}i.attenuationDistance=e.attenuationDistance,i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class D{constructor(e){this.writer=e,this.name="KHR_materials_ior"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1.5===e.ior)return;let n=this.writer,r=n.extensionsUsed,i={};i.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class G{constructor(e){this.writer=e,this.name="KHR_materials_specular"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1===e.specularIntensity&&e.specularColor.equals(S)&&!e.specularIntensityMap&&!e.specularColorTexture)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}}class z{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.sheen)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}}class K{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.anisotropy)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}}class V{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}writeMaterial(e,t){if(!e.isMeshStandardMaterial||1===e.emissiveIntensity)return;let n=this.writer,r=n.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}function X(e,t){if(t===d.WwZ)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t!==d.z$h&&t!==d.UlW)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e;{let n=e.getIndex();if(null===n){let t=[],r=e.getAttribute("position");if(void 0===r)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;eMath.abs(e.times[0]-t))return 0;i[0]=t,i.set(e.times,1),o.set(s.evaluate(t),0),o.set(e.values,r),n=0}else if(t>e.times[e.times.length-1]){if(.001>Math.abs(e.times[e.times.length-1]-t))return e.times.length-1;i[i.length-1]=t,i.set(e.times,0),o.set(e.values,0),o.set(s.evaluate(t),e.values.length),n=i.length-1}else for(let a=0;aMath.abs(e.times[a]-t))return a;if(e.times[a]t){i.set(e.times.slice(0,a+1),0),i[a+1]=t,i.set(e.times.slice(a+1),a+2),o.set(e.values.slice(0,(a+1)*r),0),o.set(s.evaluate(t),(a+1)*r),o.set(e.values.slice((a+1)*r),(a+2)*r),n=a+1;break}}return e.times=i,e.values=o,n},mergeMorphTargetTracks:function(e,t){let n=[],r={},i=e.tracks;for(let e=0;e=2.0 are supported."));return}let l=new eN(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});l.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e=0&&void 0===s[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}l.setExtensions(o),l.setPlugins(s),l.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}}function W(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}let Z={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class J{constructor(e){this.parser=e,this.name=Z.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n=0))return null;throw Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures")}return t.loadTextureImage(e,i.source,o)}}class el{constructor(e){this.parser=e,this.name=Z.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let o=i.extensions[t],s=r.images[o.source],a=n.textureLoader;if(s.uri){let e=n.options.manager.getHandler(s.uri);null!==e&&(a=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){let t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class ec{constructor(e){this.parser=e,this.name=Z.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let o=i.extensions[t],s=r.images[o.source],a=n.textureLoader;if(s.uri){let e=n.options.manager.getHandler(s.uri);null!==e&&(a=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){let t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class eu{constructor(e){this.name=Z.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(!n.extensions||!n.extensions[this.name])return null;{let e=n.extensions[this.name],r=this.parser.getDependency("buffer",e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(!(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0))return null;throw Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files")}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,o=e.count,s=e.byteStride,a=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(o,s,a,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(o*s);return i.decodeGltfBuffer(new Uint8Array(t),o,s,a,e.mode,e.filter),t})})}}}class eh{constructor(e){this.name=Z.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||void 0===n.mesh)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==ek.TRIANGLES&&e.mode!==ek.TRIANGLE_STRIP&&e.mode!==ek.TRIANGLE_FAN&&void 0!==e.mode)return null;let i=n.extensions[this.name],o=i.attributes,s=[],a={};for(let e in o)s.push(this.parser.getDependency("accessor",o[e]).then(t=>(a[e]=t,a[e])));return s.length<1?null:(s.push(this.parser.createNodeMesh(e)),Promise.all(s).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new d.yGw,n=new d.Pa4,o=new d._fP,s=new d.Pa4(1,1,1),l=new d.SPe(e.geometry,e.material,r);for(let e=0;e-1)?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),"undefined"==typeof createImageBitmap||n||r&&i<98?this.textureLoader=new d.dpR(this.options.manager):this.textureLoader=new d.QRU(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new d.hH6(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(t){let o={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return eM(i,o,r),e_(o,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(o)})).then(function(){e(o)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n{let n=this.associations.get(e);for(let[r,o]of(null!=n&&this.associations.set(t,n),e.children.entries()))i(o,t.children[r])};return i(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n=2&&o.setY(t,h[e*a+1]),a>=3&&o.setZ(t,h[e*a+2]),a>=4&&o.setW(t,h[e*a+3]),a>=5)throw Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return o})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e],i=r.source,o=t.images[i],s=this.textureLoader;if(o.uri){let e=n.manager.getHandler(o.uri);null!==e&&(s=e)}return this.loadTextureImage(e,i,s)}loadTextureImage(e,t,n){let r=this,i=this.json,o=i.textures[e],s=i.images[t],a=(s.uri||s.bufferView)+":"+o.sampler;if(this.textureCache[a])return this.textureCache[a];let l=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=o.name||s.name||"",""===t.name&&"string"==typeof s.uri&&!1===s.uri.startsWith("data:image/")&&(t.name=s.uri);let n=i.samplers||{},a=n[o.sampler]||{};return t.magFilter=eT[a.magFilter]||d.wem,t.minFilter=eT[a.minFilter]||d.D1R,t.wrapS=eR[a.wrapS]||d.rpg,t.wrapT=eR[a.wrapT]||d.rpg,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[a]=l,l}loadImageSource(e,t){let n=this.json,r=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());let i=n.images[e],o=self.URL||self.webkitURL,s=i.uri||"",a=!1;if(void 0!==i.bufferView)s=this.getDependency("bufferView",i.bufferView).then(function(e){a=!0;let t=new Blob([e],{type:i.mimeType});return s=o.createObjectURL(t)});else if(void 0===i.uri)throw Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");let l=Promise.resolve(s).then(function(e){return new Promise(function(n,i){let o=n;!0===t.isImageBitmapLoader&&(o=function(e){let t=new d.xEZ(e);t.needsUpdate=!0,n(t)}),t.load(d.Zp0.resolveURL(e,r.path),o,void 0,i)})}).then(function(e){var t;return!0===a&&o.revokeObjectURL(s),e.userData.mimeType=i.mimeType||((t=i.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){let i=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(void 0!==n.texCoord&&n.texCoord>0&&((o=o.clone()).channel=n.texCoord),i.extensions[Z.KHR_TEXTURE_TRANSFORM]){let e=void 0!==n.extensions?n.extensions[Z.KHR_TEXTURE_TRANSFORM]:void 0;if(e){let t=i.associations.get(o);o=i.extensions[Z.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),i.associations.set(o,t)}}return void 0!==r&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=void 0===t.attributes.tangent,i=void 0!==t.attributes.color,o=void 0===t.attributes.normal;if(e.isPoints){let e="PointsMaterial:"+n.uuid,t=this.cache.get(e);t||(t=new d.UY4,d.F5T.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e="LineBasicMaterial:"+n.uuid,t=this.cache.get(e);t||(t=new d.nls,d.F5T.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||o){let e="ClonedMaterial:"+n.uuid+":";r&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),o&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return d.Wid}loadMaterial(e){let t;let n=this,r=this.json,i=this.extensions,o=r.materials[e],s={},a=o.extensions||{},l=[];if(a[Z.KHR_MATERIALS_UNLIT]){let e=i[Z.KHR_MATERIALS_UNLIT];t=e.getMaterialType(),l.push(e.extendParams(s,o,n))}else{let r=o.pbrMetallicRoughness||{};if(s.color=new d.Ilk(1,1,1),s.opacity=1,Array.isArray(r.baseColorFactor)){let e=r.baseColorFactor;s.color.setRGB(e[0],e[1],e[2],d.GUF),s.opacity=e[3]}void 0!==r.baseColorTexture&&l.push(n.assignTexture(s,"map",r.baseColorTexture,d.KI_)),s.metalness=void 0!==r.metallicFactor?r.metallicFactor:1,s.roughness=void 0!==r.roughnessFactor?r.roughnessFactor:1,void 0!==r.metallicRoughnessTexture&&(l.push(n.assignTexture(s,"metalnessMap",r.metallicRoughnessTexture)),l.push(n.assignTexture(s,"roughnessMap",r.metallicRoughnessTexture))),t=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,s)})))}!0===o.doubleSided&&(s.side=d.ehD);let c=o.alphaMode||eO.OPAQUE;if(c===eO.BLEND?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,c===eO.MASK&&(s.alphaTest=void 0!==o.alphaCutoff?o.alphaCutoff:.5)),void 0!==o.normalTexture&&t!==d.vBJ&&(l.push(n.assignTexture(s,"normalMap",o.normalTexture)),s.normalScale=new d.FM8(1,1),void 0!==o.normalTexture.scale)){let e=o.normalTexture.scale;s.normalScale.set(e,e)}if(void 0!==o.occlusionTexture&&t!==d.vBJ&&(l.push(n.assignTexture(s,"aoMap",o.occlusionTexture)),void 0!==o.occlusionTexture.strength&&(s.aoMapIntensity=o.occlusionTexture.strength)),void 0!==o.emissiveFactor&&t!==d.vBJ){let e=o.emissiveFactor;s.emissive=new d.Ilk().setRGB(e[0],e[1],e[2],d.GUF)}return void 0!==o.emissiveTexture&&t!==d.vBJ&&l.push(n.assignTexture(s,"emissiveMap",o.emissiveTexture,d.KI_)),Promise.all(l).then(function(){let r=new t(s);return o.name&&(r.name=o.name),e_(r,o),n.associations.set(r,{materials:e}),o.extensions&&eM(i,r,o),r})}createUniqueName(e){let t=d.iUV.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache,i=[];for(let o=0,s=e.length;o0&&function(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let n=0,r=t.weights.length;n1?new d.ZAu:1===t.length?t[0]:new d.Tme)!==t[0])for(let e=0,n=t.length;e{let t=new Map;for(let[e,n]of r.associations)(e instanceof d.F5T||e instanceof d.xEZ)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);null!=n&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let o;let s=[],a=e.name?e.name:e.uuid,l=[];switch(eP[i.path]===eP.weights?e.traverse(function(e){e.morphTargetInfluences&&l.push(e.name?e.name:e.uuid)}):l.push(a),eP[i.path]){case eP.weights:o=d.dUE;break;case eP.rotation:o=d.iLg;break;case eP.position:case eP.scale:o=d.yC1;break;default:o=1===n.itemSize?d.dUE:d.yC1}let c=void 0!==r.interpolation?eS[r.interpolation]:d.NMF,u=this._getArrayFromAccessor(n);for(let e=0,n=l.length;e3&&void 0!==arguments[3]?arguments[3]:function(){};new Y().load(e,function(e){e.scene.scale.set(y.R/.5,y.R/.5,y.R/.5),e.scene.matrixAutoUpdate=!1,e.scene.visible=n,e.scene.updateMatrix(),t.add(e.scene),r()},function(e){return console.log(e.loaded+" bytes loaded")},eB)}var eF=n("./src/view/tablegeometry.ts");function eU(e,t){for(var n=0;nthis.radius-y.R){var r=this.pos.clone().sub(e.pos).normalize().setZ(0);n>-y.R/2&&e.vel.addScaledVector(r,7*y.R*t*y.g),0>e.vel.dot(r)&&(e.ballmesh.trace.forceTrace(e.pos),e.vel.x=r.x*e.vel.length()/2,e.vel.y=r.y*e.vel.length()/2)}var i=this.restingDepth(e);n2&&void 0!==arguments[2]?arguments[2]:this.cloth;this.cylinder(e.pos,e.radius,.75*y.R/.5,t,n).position.setZ(-(.25*y.R)/.5/2)}},{key:"cylinder",value:function(e,t,n,r,i){var o=new d.fHI(t,t,n,16),s=new d.Kj0(o,i);return s.position.copy(e),s.geometry.applyMatrix4(new d.yGw().identity().makeRotationAxis(new d.Pa4(1,0,0),Math.PI/2)),r.add(s),s}},{key:"addCushions",value:function(e,t){var n=10*y.R/.5;this.plane(new d.Pa4(0,0,-y.R-n/2),2*eF.H.X,2*eF.H.Y,n,e,this.cloth);var r=1*y.R/.5,i=.75*y.R/.5,o=-(.25*y.R)/.5/2,s=eF.H.X,a=eF.H.Y,l=Math.abs(eJ.pockets.pocketNW.knuckleNE.pos.x-eJ.pockets.pocketN.knuckleNW.pos.x),c=Math.abs(eJ.pockets.pocketNW.knuckleSW.pos.y-eJ.pockets.pocketSW.knuckleNW.pos.y);t||(l=2*eF.H.Y,c=2*eF.H.Y+4*y.R),this.plane(new d.Pa4(s+r/2,0,o),r,c,i,e),this.plane(new d.Pa4(-s-r/2,0,o),r,c,i,e),this.plane(new d.Pa4(-s/2,a+r/2,o),l,r,i,e),this.plane(new d.Pa4(-s/2,-a-r/2,o),l,r,i,e),this.plane(new d.Pa4(s/2,a+r/2,o),l,r,i,e),this.plane(new d.Pa4(s/2,-a-r/2,o),l,r,i,e)}},{key:"plane",value:function(e,t,n,r,i){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:this.cushion,s=new d.DvJ(t,n,r),a=new d.Kj0(s,o);a.receiveShadow=!0,a.position.copy(e),i.add(a)}}],eq(n.prototype,e),t&&eq(n,t),n}(),e0=n("./src/events/watchevent.ts");function e1(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}!function(e){e.Pot="Pot",e.Cushion="Cushion",e.Collision="Collision",e.Hit="Hit"}(a||(a={}));var e2=function(){var e;function t(e,n,r,i){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),e1(this,"type",void 0),e1(this,"timestamp",void 0),e1(this,"ballA",null),e1(this,"ballB",null),e1(this,"incidentSpeed",void 0),this.type=e,this.ballA=n,this.ballB=r,this.incidentSpeed=i,this.timestamp=Date.now()}return e=[{key:"pot",value:function(e,n){return new t("Pot",e,e,n)}},{key:"cushion",value:function(e,n){return new t("Cushion",e,e,n)}},{key:"collision",value:function(e,n,r){return new t("Collision",e,n,r)}},{key:"hit",value:function(e,n){return new t("Hit",e,e,n)}},{key:"isCueBallPotted",value:function(e,t){return t.some(function(t){return"Pot"==t.type&&t.ballA===e})}},{key:"isBallPottedNoFoul",value:function(e,n){return n.some(function(e){return"Pot"==e.type&&null!==e.ballA})&&!t.isCueBallPotted(e,n)}},{key:"pots",value:function(e){return e.filter(function(e){return"Pot"==e.type}).map(function(e){return e.ballA})}},{key:"potCount",value:function(e){return this.pots(e).length}},{key:"onlyRedsPotted",value:function(e){return this.pots(e).every(function(e){return e.id>6})}},{key:"isThreeCushionPoint",value:function(e,n){n=t.cueBallFirst(e,n).filter(function(t){return t.ballA===e});var r=new Set,i=0,o=!0,s=!1,a=void 0;try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var u=l.value;if("Cushion"===u.type&&i++,"Collision"===u.type&&(r.add(u.ballB),2===r.size))return i>=3}}catch(e){s=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(s)throw a}}return!1}},{key:"cueBallFirst",value:function(e,t){return t.forEach(function(t){"Collision"===t.type&&t.ballB===e&&(t.ballB=t.ballA,t.ballA=e)}),t}}],function(e,t){for(var n=0;n-eF.H.tableX&&n.overlapsAny(r,t);)r.x-=y.R/8;t.pos.copy(r),t.state=eV.Z.Stationary}}],function(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1500;if(!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),tb(tm(r=i.call(this,e)),"delay",void 0),tb(tm(r),"shots",void 0),tb(tm(r),"firstShot",void 0),tb(tm(r),"timer",void 0),tb(tm(r),"init",void 0),r.init=t,r.shots=tk(n),r.firstShot=r.shots[0],r.delay=a,r.container.table.showTraces(!0),r.container.table.updateFromShortSerialised(r.init),s){var l=new tp.l(t,n);l.retry=!0,r.container.eventQueue.push(l)}else r.container.view.camera.forceMode(r.container.view.camera.topView),r.playNextShot(1.5*r.delay);return r}return n=[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===c.t.RERACK){td.K.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var r=e3.f.fromJson(n);this.container.table.cueball=this.container.table.balls[r.i],this.container.table.cueball.pos.copy(r.pos),this.container.table.cue.aim=r,this.container.table.cue.updateAimInput(),this.container.table.cue.t=1,clearTimeout(this.timer),this.timer=setTimeout(function(){t.container.eventQueue.push(new e8.O(t.container.table.cue.aim)),t.timer=void 0},e)}},{key:"handleHit",value:function(e){return this.hit(),this}},{key:"handleStationary",value:function(e){return this.shots.length>0&&void 0===this.timer&&this.playNextShot(this.delay),this}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}},{key:"handleBreak",value:function(e){return(this.container.table.updateFromShortSerialised(e.init),this.shots=tk(e.shots),this.container.table.showSpin(!0),e.retry)?this.retry():(this.playNextShot(this.delay),this)}},{key:"retry",value:function(){clearTimeout(this.timer),this.timer=void 0,this.container.table.updateFromShortSerialised(this.init);var e=e3.f.fromJson(this.firstShot);return this.container.table.cueball=this.container.table.balls[e.i],this.container.rules.cueball=this.container.table.cueball,this.container.table.cueball.pos.copy(e.pos),this.container.table.cue.aim=e,this.container.view.camera.forceMode(this.container.view.camera.aimView),new tE(this.container)}}],ty(o.prototype,n),r&&ty(o,r),o}(tl);function tT(e,t){for(var n=0;n2)||void 0===arguments[2]||arguments[2],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:tG.h_,o=e.futurePosition(n);if(t.willBounceLong(o,r)){var s=o.y>eF.H.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(s,e,i)}if(t.willBounceShort(o,r)){var a=o.x>eF.H.tableX?0:Math.PI;return t.bounceIn(a,e,i)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(eJ.pockets.pocketNW.knuckleSW.pos.y,eJ.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(eF.H.Y,-eF.H.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(eJ.pockets.pocketNW.knuckleNE.pos.x,eJ.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(eJ.pockets.pocketN.knuckleNE.pos.x,eJ.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-eF.H.X,eF.H.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xeF.H.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yeF.H.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,tG.ZI)(e,t.vel,t.rvel,n);return t.vel.add(r.v),t.rvel.add(r.w),r.v.length()}}],function(e,t){for(var n=0;n100)throw Error("Depth exceeded resolving collisions");this.balls.forEach(function(t){t.update(e)})}},{key:"prepareAdvanceAll",value:function(e){var t=this;return this.pairs.every(function(n){return t.prepareAdvancePair(n.a,n.b,e)})&&this.balls.every(function(n){return t.prepareAdvanceToCushions(n,e)})}},{key:"prepareAdvancePair",value:function(e,t,n){if(tK.willCollide(e,t,n)){var r=tK.collide(e,t);return this.outcome.push(e2.collision(e,t,r)),!1}return!0}},{key:"prepareAdvanceToCushions",value:function(e,t){if(!e.onTable())return!0;var n=e.futurePosition(t);if(Math.abs(n.y)1&&void 0!==arguments[1]?arguments[1]:this.cueball;return this.balls.filter(function(e){return e!==t}).some(function(t){return t.pos.distanceTo(e)<2*y.R})}}],t=[{key:"fromSerialised",value:function(e){var t=new n(e.balls.map(function(e){return eV.e.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&tX(n.prototype,e),t&&tX(n,t),n}();function tZ(e,t){for(var n=0;n0){if(this.previousPotRed)this.previousPotRed=!1,this.respot(e);else if(e2.onlyRedsPotted(e))this.previousPotRed=!0;else if(1===t){var n=e2.pots(e)[0].id;n>1&&this.container.table.balls.filter(function(e){return e.id0}).some(function(e){return e.onTable()})&&this.respot(e)}else this.respot(e)}return t1(t2(o.prototype),"update",this).call(this,e)}},{key:"respot",value:function(e){var t=this.respotAllPottedColours(e);if(t.length>0){var n={balls:t.map(function(e){return e.serialise()}),rerack:!0},r=new e0.g(n);this.container.sendEvent(r),this.container.recoder.record(r)}}},{key:"respotAllPottedColours",value:function(e){var t=this;return e2.pots(e).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(e){return e5.respot(e,t.container.table)})}}],t$(o.prototype,n),r&&t$(o,r),o}(tq);function t3(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],no(n.prototype,e),t&&no(n,t),n}();function nl(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:0;if(this.loadAssets){var r,i,o=d.Hmr.getContext();if((null==o?void 0:o.state)==="suspended"){(null===(i=navigator)||void 0===i?void 0:null===(r=i.userActivation)||void 0===r?void 0:r.hasBeenActive)&&o.resume();return}e.setVolume(t),e.isPlaying&&e.stop(),e.play(d.M8C.randFloat(0,.01)),e.setDetune(n)}}},{key:"outcomeToSound",value:function(e){"Collision"===e.type&&this.play(this.ballcollision,e.incidentSpeed/80,5*e.incidentSpeed),"Pot"===e.type&&this.play(this.pot,e.incidentSpeed/10,-1e3+10*e.incidentSpeed),"Cushion"===e.type&&this.play(this.cushion,e.incidentSpeed/70),"Hit"===e.type&&this.play(this.cue,e.incidentSpeed/30)}},{key:"processOutcomes",value:function(e){var t=this;e.every(function(e){return!(e.timestamp>t.lastOutcomeTime)||(t.lastOutcomeTime=e.timestamp,t.outcomeToSound(e),!1)})}},{key:"playNotify",value:function(){this.play(this.pot,1)}},{key:"playSuccess",value:function(e){this.play(this.success,.1,100*e-2200)}}],nl(n.prototype,e),t&&nl(n,t),n}();function nh(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function nf(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==c.t.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}],nv(n.prototype,e),t&&nv(n,t),n}(),nb=n("./src/view/sliders.ts"),ng=n("./node_modules/jsoncrush/JSONCrush.js");function nw(e,t){for(var n=0;n0&&"RERACK"===this.shots[e].type&&e--,e}},{key:"lastShot",value:function(){var e=this.last();return this.state(this.states[e],[this.shots[e]])}},{key:"currentBreak",value:function(){if(void 0!==this.breakStart)return this.state(this.states[this.breakStart],this.shots.slice(this.breakStart))}},{key:"state",value:function(e,t){return{init:e,shots:t}}},{key:"updateBreak",value:function(e){var t=this.container.rules.isPartOfBreak(e),n=this.container.rules.isEndOfGame(e),r=e2.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r),n&&this.breakLink(n),!t){this.breakStart=void 0;return}void 0===this.breakStart&&(this.breakStart=this.last())}},{key:"lastShotLink",value:function(e,t){var n="⚈".repeat(t>1?t-1:0)+(e?"⚈":"⚆"),r=JSON.stringify(this.lastShot());this.generateLink(n,r)}},{key:"breakLink",value:function(e){var t=this.currentBreak();if(t&&(e||t.shots.pop(),1!==t.shots.length)){var n="break(".concat(t.shots.length,")"),r=JSON.stringify(t),i=ng.Z.crush(r);this.generateLink(n,i)}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(e.shots.length,")"),n=JSON.stringify(e),r=ng.Z.crush(n);this.generateLink(t,r)}},{key:"generateLink",value:function(e,t){var n="".concat(this.replayUrl).concat(encodeURIComponent(t)),r='').concat(e,"");this.container.eventQueue.push(new tU.s(null,"".concat(r)))}}],nw(n.prototype,e),t&&nw(n,t),n}();function nT(e,t){for(var n=0;n').concat(e,"")));r.push(new tU.s(null,s))})},this.redo.onclick=function(e){var r=new tp.l(t.init,t.shots);r.retry=!0,n.interuptEventQueue(r)},this.replay.onclick=function(e){n.interuptEventQueue(t)}}},{key:"interuptEventQueue",value:function(e){this.container.table.halt();var t=this.container.eventQueue;t.length=0,t.push(new p),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],nI(n.prototype,e),t&&nI(n,t),n}();function nN(e,t){for(var n=0;n2)||void 0===arguments[2]||arguments[2],i=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,s=arguments.length>5?arguments[5]:void 0,a=arguments.length>6?arguments[6]:void 0,l=this;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,n),nL(this,"table",void 0),nL(this,"view",void 0),nL(this,"controller",void 0),nL(this,"inputQueue",[]),nL(this,"eventQueue",[]),nL(this,"keyboard",void 0),nL(this,"sound",void 0),nL(this,"chat",void 0),nL(this,"sliders",void 0),nL(this,"recoder",void 0),nL(this,"id",""),nL(this,"isSinglePlayer",!0),nL(this,"rules",void 0),nL(this,"menu",void 0),nL(this,"last",performance.now()),nL(this,"step",.001953125),nL(this,"broadcast",void 0),nL(this,"log",void 0),nL(this,"sendChat",function(e){l.sendEvent(new tU.s(l.id,e))}),nL(this,"throttle",new ny(200,function(e){l.broadcast(e)})),nL(this,"lastEventTime",performance.now()),this.log=t,this.rules=n_.create(i,this),this.table=this.rules.table(),this.view=new t6(e,s,this.table,r,this.rules.asset()),this.table.cue.aimInputs=new na(this),this.keyboard=o,this.sound=new nu(this.view.camera.camera,r),this.chat=new nd(this.sendChat),this.sliders=new nb.E,this.recoder=new nx(this),this.id=a,this.menu=new nC(this),this.table.addToScene(this.view.scene),this.updateController(new nt(this))}return e=[{key:"sendEvent",value:function(e){this.throttle.send(e)}},{key:"advance",value:function(e){for(var t=Math.floor(e/this.step),n=t*this.step,r=this.table.allStationary(),i=0;i0;){this.lastEventTime=this.last;var t=this.inputQueue.shift();t&&this.updateController(this.controller.handleInput(t))}if(this.table.allStationary()){var n=this.eventQueue.shift();n&&(this.lastEventTime=performance.now(),this.updateController(n.applyToController(this.controller)))}}},{key:"animate",value:function(e){var t=this;this.advance((e-this.last)/1e3),this.last=e,this.processEvents(),(e{var r,i,o,s,a,l,c,u,h,f=n("./src/model/physics/physics.ts"),p=n("./node_modules/three/build/three.module.js");function d(e,t){for(var n=0;n4&&void 0!==arguments[4]?arguments[4]:.9,o={dx:n-e,dy:r-t},s={x:o.dx*i+e,y:o.dy*i+t},a={dx:n-s.x,dy:r-s.y};this.context.beginPath(),this.context.moveTo(e,t),this.context.lineTo(s.x,s.y),this.context.moveTo(s.x+.5*a.dy,s.y-.5*a.dx),this.context.lineTo(s.x-.5*a.dy,s.y+.5*a.dx),this.context.lineTo(n,r),this.context.closePath(),this.context.stroke()}}],d(n.prototype,e),t&&d(n,t),n}();function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n{n.d(t,{Y:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{f:()=>f});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts"),s=n("./node_modules/three/build/three.module.js");function a(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){for(var n=0;n{n.d(t,{Z:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{l:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{s:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r;n.d(t,{t:()=>r}),function(e){e.BEGIN="BEGIN",e.BREAK="BREAK",e.WATCHAIM="WATCHAIM",e.AIM="AIM",e.HIT="HIT",e.STATIONARY="STATIONARY",e.CHAT="CHAT",e.ABORT="ABORT",e.PLACEBALL="PLACEBALL",e.REJOIN="REJOIN",e.RERACK="RERACK"}(r||(r={}))},"./src/events/gameevent.ts":(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{Z:()=>i});var i=function e(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"type",void 0),r(this,"sequence",void 0)}},"./src/events/hitevent.ts":(e,t,n)=>{n.d(t,{O:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{I:()=>i});var i=function e(t,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"t",void 0),r(this,"key",void 0),this.t=t,this.key=n}},"./src/events/keyboard.ts":(e,t,n)=>{n.d(t,{N:()=>l});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t){for(var n=0;n3*Math.abs(i)){var s,a=null!==(s=t.released.movementY)&&void 0!==s?s:0;t.released.movementY=a+o;return}var l=null!==(n=t.released.movementX)&&void 0!==n?n:0;t.released.movementX=l+i}),this.addHandlers(e),/Android|iPhone/i.test(navigator.userAgent)||(e.contentEditable="true")}return e=[{key:"getEvents",value:function(){var e=this,t=Object.keys(this.pressed).filter(function(e){return!/Shift/.test(e)}).filter(function(e){return!/Control/.test(e)}),n=Object.keys(this.pressed).some(function(e){return/Shift/.test(e)}),i=Object.keys(this.pressed).some(function(e){return/Control/.test(e)}),o=[];return t.forEach(function(t){var s=performance.now()-e.pressed[t];o.push(new r.I(i?s/3:s,n?"Shift"+t:t)),"Space"!=t&&(e.pressed[t]=performance.now())}),Object.keys(this.released).forEach(function(t){return o.push(new r.I(e.released[t],t+"Up"))}),this.released={},o}},{key:"addHandlers",value:function(e){var t=this;e.addEventListener("keydown",this.keydown),e.addEventListener("keyup",this.keyup),e.focus(),o()(e).draggable({listeners:{move:function(e){t.mousetouch(e)}}})}}],s(n.prototype,e),t&&s(n,t),n}()},"./src/events/placeballevent.ts":(e,t,n)=>{n.d(t,{I:()=>h});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts");function s(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){for(var n=0;n{n.d(t,{K:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{g:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{e:()=>m,Z:()=>r});var r,i=n("./src/utils/utils.ts"),o=n("./src/model/physics/physics.ts"),s=n("./node_modules/three/build/three.module.js"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;nMath.PI/32?.01*a.R:a.R,i=this.lastPos.distanceTo(e);this.addTraceGiven(e,t,i,r,n)}}},{key:"addTraceGiven",value:function(e,t,n,r,i){var o=this.geometry.drawRange.count;0!==o&&n1&&i<1e-4&&o--,this.lastPos.copy(e),this.lastVel.copy(t),this.addPoint(e,o))}},{key:"addPoint",value:function(e,t){var n=3*t;n>this.positions.length||(this.positions[n++]=e.x,this.positions[n++]=e.y,this.positions[n]=e.z,this.geometry.setDrawRange(0,t+1),this.line.geometry.attributes.position.needsUpdate=!0)}}],l(n.prototype,e),t&&l(n,t),n}();function h(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.bM),this.rvel.copy(i.bM),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.E9)(this.vel,this.rvel).length(){n.d(t,{Dt:()=>c,Ew:()=>v,G3:()=>w,Hz:()=>i,I:()=>o,Mz:()=>r,R:()=>f,Xm:()=>k,_5:()=>u,dE:()=>y,e:()=>p,f7:()=>g,fN:()=>m,g:()=>s,m:()=>h,mu:()=>a,zq:()=>b,zv:()=>l});var r,i,o,s=9.8,a=.00985,l=.105,c=.8,u=.024,h=.23,f=.03275,p=.86;function d(){r=a*h*s*2/3*u,i=7/(5*Math.sqrt(2))*f*a*h*s,o=.4*h*f*f}function v(e){f=e,d()}function m(e){h=e,d()}function y(e){a=e,d()}function b(e){u=e,d()}function g(e){l=e}function w(e){p=e}function k(e){c=e}d()},"./src/model/physics/physics.ts":(e,t,n)=>{n.d(t,{E9:()=>a,Fn:()=>R,IT:()=>h,NP:()=>g,QC:()=>u,Vp:()=>c,WL:()=>P,ZI:()=>f,al:()=>b,c0:()=>y,h_:()=>A,s0:()=>m,vZ:()=>w});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/utils/utils.ts"),o=n("./src/model/physics/constants.ts"),s=new r.Pa4;function a(e,t){return s.copy(e).addScaledVector((0,i.a1)(t),o.R)}var l={v:new r.Pa4,w:new r.Pa4};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.KO)(n).multiplyScalar(-o.zv*o.g)),l.w.copy((0,i.KO)((0,i.a1)(n)).multiplyScalar(2.5*o.zv*o.g/o.R)),l.w.setZ(-2.5*(o.Mz/(o.R*o.R))*Math.sign(t.z)),l}function u(e){var t=new r.Pa4(e.x,e.y,0).length(),n=5/7*o.Hz/(o.m*o.R)/t,i=5/7*o.Hz/(o.m*o.R*o.R)/t;return l.v.set(-n*e.y,n*e.x,0),l.w.set(-i*e.x,-i*e.y,-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(e.z)),l}function h(e,t){var n=t.z;t.copy((0,i.a1)(e).multiplyScalar(1/o.R)),t.setZ(n)}function f(e,t,n,r){var o=r(t.clone().applyAxisAngle(i.up,e),n.clone().applyAxisAngle(i.up,e));return o.v.applyAxisAngle(i.up,-e),o.w.applyAxisAngle(i.up,-e),o}Object.freeze(l);var p=Math.asin(.1*o.R/o.R),d=Math.sin(p),v=Math.cos(p);function m(e,t){return new r.Pa4(e.x*d-e.z*v+o.R*t.y,-e.y-o.R*t.z*v+o.R*t.x*d)}function y(e){return e.x*v}function b(e){var t=3.5/o.m;return e.length()/t}function g(e){var t,n=1/o.m,i=.39+.257*(t=new r.Pa4(e/v,0,0)).x-.044*t.x*t.x;return o.Dt*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(m(e,t))<=n}function k(e,t){return{c:y(e),s:m(e,t),A:3.5/o.m,B:1/o.m}}function x(e,t){var n=k(e,t),r=n.c,i=n.s,s=n.A,a=n.B,l=(1+o.e)*(r/a);return E(-i.x/s*d-l*v,i.y/s,i.x/s*v-l*d)}function T(e,t){var n=k(e,t),r=n.c,i=n.B,s=(1+o.e)*(r/i),a=.471-.241*Math.atan2(Math.abs(e.y),e.x),l=Math.atan2(e.y,e.x),c=Math.cos(l),u=-a*s*c*v-s*v,h=a*s*c*v-s*d;return E(u,a*s*Math.sin(l),h)}function R(e,t){return w(e,t)?x(e,t):T(e,t)}function A(e,t){var n=x(e,t),r=T(e,t),i=Math.sign(e.y)===Math.sign(t.z)?Math.cos(Math.atan2(e.y,e.x)):1;return{v:r.v.lerp(n.v,i),w:r.w.lerp(n.w,i)}}function E(e,t,n){return{v:new r.Pa4(e/o.m,t/o.m),w:new r.Pa4(-o.R/o.I*t*d,o.R/o.I*(e*d-n*v),o.R/o.I*t*v)}}function P(e,t){var n=Math.atan2(-e.x,e.y),r=2.5*t.length()*(e.length()*o.R)/(o.R*o.R),s=t.clone().normalize();return(0,i.a1)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/utils/utils.ts":(e,t,n)=>{n.d(t,{$2:()=>y,AA:()=>p,Bh:()=>s,KO:()=>u,Ls:()=>f,NM:()=>d,Xp:()=>v,a1:()=>l,bM:()=>i,up:()=>o,wK:()=>m});var r=n("./node_modules/three/build/three.module.js"),i=new r.Pa4(0,0,0),o=new r.Pa4(0,0,1);function s(e){return new r.Pa4(e.x,e.y,e.z)}var a=new r.Pa4;function l(e){return a.copy(o).cross(e)}var c=new r.Pa4;function u(e){return c.copy(e).normalize()}var h=new r.Pa4;function f(e,t){return 0>=h.copy(e).add(t).dot(e)}function p(e){return new r.Pa4(1,0,0).applyAxisAngle(o,e)}function d(e){return Math.sign(e)*Math.floor((Math.abs(e)+Number.EPSILON)*1e4)/1e4}function v(e){return Math.round((e+Number.EPSILON)*100)/100}function m(e){return e.x=d(e.x),e.y=d(e.y),e.z=d(e.z),e}function y(e){return e.x=v(e.x),e.y=v(e.y),e.z=v(e.z),e}},"./src/view/cameratop.ts":(e,t,n)=>{n.d(t,{c:()=>a});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/view/tablegeometry.ts"),o=n("./src/model/physics/constants.ts");function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"viewPoint",value:function(e,n){var s=t.zoomFactor/(2*Math.tan(n*Math.PI/360));if(e>this.portrait){var a=e>t.aspectLimit?2.75*i.H.tableY:2.4*i.H.tableX/e;return new r.Pa4(0,-.01*o.R,s*a)}var l=e>1/t.aspectLimit?4.9*i.H.tableY:1.35*i.H.tableX/e;return new r.Pa4(-.01*o.R,0,s*l)}}],function(e,t){for(var n=0;n{n.d(t,{N:()=>d});var r=n("./src/view/tablegeometry.ts"),i=n("./src/utils/utils.ts"),o=n("./src/events/aimevent.ts"),s=n("./src/model/ball.ts"),a=n("./src/model/physics/physics.ts"),l=n("./src/model/physics/constants.ts"),c=n("./node_modules/three/build/three.module.js");function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var h=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"createHelper",value:function(){var e=new c.fHI(l.R,l.R,30*l.R/.5,12,1,!0),t=new c.Kj0(e,this.helpermaterial);return t.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(i.up,-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(15*l.R/.5,0,-(.01*l.R)/.5)),t.visible=!1,t.renderOrder=-1,t.material.depthTest=!1,t}},{key:"createPlacer",value:function(){var e=new c.fHI(.01*l.R/.5,l.R,l.R,4),n=new c.Kj0(e,t.helpermaterial);return n.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(new c.Pa4(1,0,0),-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(0,0,.7*l.R/.5)),n.visible=!1,n}},{key:"createCue",value:function(e,n,r){var o=new c.fHI(e,n,r,11),s=new c.Kj0(o,t.material);return s.castShadow=!1,s.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(new c.Pa4(1,0,0),-.1)).applyMatrix4(new c.yGw().identity().makeRotationAxis(i.up,-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(-r/2-l.R,0,2*l.R)),s}}],function(e,t){for(var n=0;nthis.offCenterLimit&&e.normalize().multiplyScalar(this.offCenterLimit),this.aim.offset=(0,i.$2)(e),this.updateAimInput()}},{key:"updateAimInput",value:function(){var e,t;null===(e=this.aimInputs)||void 0===e||e.updateVisualState(this.aim.offset.x,this.aim.offset.y),null===(t=this.aimInputs)||void 0===t||t.updatePowerSlider(this.aim.power/this.maxPower)}},{key:"moveTo",value:function(e){this.aim.pos.copy(e),this.mesh.rotation.z=this.aim.angle,this.helperMesh.rotation.z=this.aim.angle;var t=(0,i.a1)((0,i.AA)(this.aim.angle)).multiplyScalar(2*this.aim.offset.x*l.R).setZ(2*this.aim.offset.y*l.R),n=(Math.sin(this.t+Math.PI/2)-1)*3*l.R*(this.aim.power/this.maxPower),r=(0,i.AA)(this.aim.angle).clone().multiplyScalar(n);this.mesh.position.copy(e.clone().add(t).add(r)),this.helperMesh.position.copy(e),this.placerMesh.position.copy(e),this.placerMesh.rotation.z=this.t}},{key:"update",value:function(e){this.t+=e,this.moveTo(this.aim.pos)}},{key:"placeBallMode",value:function(){this.mesh.visible=!1,this.placerMesh.visible=!0,this.aim.angle=0}},{key:"aimMode",value:function(){this.mesh.visible=!0,this.placerMesh.visible=!1}},{key:"intersectsAnything",value:function(e){var t=e.cueball.pos.clone().addScaledVector((0,i.AA)(this.aim.angle),-this.length/2);t.z=this.aim.offset.y;var n=(0,i.AA)(this.aim.angle);return new c.iMs(t,n,0,this.length/2-.6).intersectObjects(e.balls.map(function(e){return e.ballmesh.mesh})).length>0}},{key:"showHelper",value:function(e){this.helperMesh.visible=e}},{key:"toggleHelper",value:function(){this.showHelper(!this.helperMesh.visible)}}],f(n.prototype,e),t&&f(n,t),n}()},"./src/view/sliders.ts":(e,t,n)=>{n.d(t,{E:()=>s});var r=n("./src/model/physics/constants.ts");function i(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:1,i=this,o=this.getInputElement(e);o.step="0.001",o.min="0.01",o.max="".concat(r),o.value=t,this.showValue(e,t),o.oninput=function(t){var r=parseFloat(t.target.value);n(r),i.showValue(e,r),i.notify()}}},{key:"showValue",value:function(e,t){var n=document.querySelector("label[for=".concat(e,"]"));n&&(n.innerHTML="".concat(e,"=").concat(t))}}],i(n.prototype,e),t&&i(n,t),n}()},"./src/view/tablegeometry.ts":(e,t,n)=>{n.d(t,{H:()=>o});var r=n("./src/model/physics/constants.ts");function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"scaleToRadius",value:function(e){t.tableX=43*e,t.tableY=21*e,t.X=t.tableX+e,t.Y=t.tableY+e}}],function(e,t){for(var n=0;n{e(e.s="./src/diagrams.ts")}]); \ No newline at end of file + }`})),o.uniforms.blitTexture.value=e,o.defines.IS_SRGB=e.colorSpace==d.KI_,o.needsUpdate=!0,s||((s=new d.Kj0(i,o)).frustrumCulled=!1);let a=new d.cPb,l=new d.xsS;l.add(s),n||(n=r=new d.CP7({antialias:!1})),n.setSize(Math.min(e.image.width,t),Math.min(e.image.height,t)),n.clear(),n.render(l,a);let c=new d.xEZ(n.domElement);return c.minFilter=e.minFilter,c.magFilter=e.magFilter,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.name=e.name,r&&(r.dispose(),r=null),c}let x={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class T{constructor(){this.pluginCallbacks=[],this.register(function(e){return new N(e)}),this.register(function(e){return new L(e)}),this.register(function(e){return new F(e)}),this.register(function(e){return new U(e)}),this.register(function(e){return new D(e)}),this.register(function(e){return new G(e)}),this.register(function(e){return new B(e)}),this.register(function(e){return new H(e)}),this.register(function(e){return new z(e)}),this.register(function(e){return new K(e)}),this.register(function(e){return new V(e)})}register(e){return -1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return -1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i=new C,o=[];for(let e=0,t=this.pluginCallbacks.length;ee.toBlob(n,t)):("image/jpeg"===t?n=.92:"image/webp"===t&&(n=.8),e.convertToBlob({type:t,quality:n}))}class C{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"}},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.buffers,i=this.json;n=this.options;let o=this.extensionsUsed,s=this.extensionsRequired,a=new Blob(r,{type:"application/octet-stream"}),l=Object.keys(o),c=Object.keys(s);if(l.length>0&&(i.extensionsUsed=l),c.length>0&&(i.extensionsRequired=c),i.buffers&&i.buffers.length>0&&(i.buffers[0].byteLength=a.size),!0===n.binary){let e=new FileReader;e.readAsArrayBuffer(a),e.onloadend=function(){var n;let r=_(e.result),o=new DataView(new ArrayBuffer(8));o.setUint32(0,r.byteLength,!0),o.setUint32(4,5130562,!0);let s=_((n=JSON.stringify(i),new TextEncoder().encode(n).buffer),32),a=new DataView(new ArrayBuffer(8));a.setUint32(0,s.byteLength,!0),a.setUint32(4,1313821514,!0);let l=new ArrayBuffer(12),c=new DataView(l);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0);let u=12+a.byteLength+s.byteLength+o.byteLength+r.byteLength;c.setUint32(8,u,!0);let h=new Blob([l,a,s,o,r],{type:"application/octet-stream"}),f=new FileReader;f.readAsArrayBuffer(h),f.onloadend=function(){t(f.result)}}}else if(i.buffers&&i.buffers.length>0){let e=new FileReader;e.readAsDataURL(a),e.onloadend=function(){let n=e.result;i.buffers[0].uri=n,t(i)}}else t(i)}serializeUserData(e,t){if(0===Object.keys(e.userData).length)return;let n=this.options,r=this.extensionsUsed;try{let i=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&i.gltfExtensions){for(let e in void 0===t.extensions&&(t.extensions={}),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(!1===this.uids.has(e)){let t=new Map;t.set(!0,this.uid++),t.set(!1,this.uid++),this.uids.set(e,t)}let n=this.uids.get(e);return n.get(t)}isNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return!1;let n=new d.Pa4;for(let t=0,r=e.count;t5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);let n=e.clone(),r=new d.Pa4;for(let e=0,t=n.count;e4?r=e.array[i*e.itemSize+n]:(0===n?r=e.getX(i):1===n?r=e.getY(i):2===n?r=e.getZ(i):3===n&&(r=e.getW(i)),!0===e.normalized&&(r=d.M8C.normalize(r,e.array))),t===R.FLOAT?l.setFloat32(c,r,!0):t===R.INT?l.setInt32(c,r,!0):t===R.UNSIGNED_INT?l.setUint32(c,r,!0):t===R.SHORT?l.setInt16(c,r,!0):t===R.UNSIGNED_SHORT?l.setUint16(c,r,!0):t===R.BYTE?l.setInt8(c,r):t===R.UNSIGNED_BYTE&&l.setUint8(c,r),c+=o}let u={buffer:this.processBuffer(l.buffer),byteOffset:this.byteOffset,byteLength:a};void 0!==i&&(u.target=i),i===R.ARRAY_BUFFER&&(u.byteStride=e.itemSize*o),this.byteOffset+=a,s.bufferViews.push(u);let h={id:s.bufferViews.length-1,byteLength:0};return h}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||(n.bufferViews=[]),new Promise(function(r){let i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){let e=_(i.result),o={buffer:t.processBuffer(e),byteOffset:t.byteOffset,byteLength:e.byteLength};t.byteOffset+=e.byteLength,r(n.bufferViews.push(o)-1)}})}processAccessor(e,t,n,r){let i,o;let s=this.json;if(e.array.constructor===Float32Array)i=R.FLOAT;else if(e.array.constructor===Int32Array)i=R.INT;else if(e.array.constructor===Uint32Array)i=R.UNSIGNED_INT;else if(e.array.constructor===Int16Array)i=R.SHORT;else if(e.array.constructor===Uint16Array)i=R.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)i=R.BYTE;else if(e.array.constructor===Uint8Array)i=R.UNSIGNED_BYTE;else throw Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(void 0===n&&(n=0),void 0===r&&(r=e.count),0===r)return null;let a=function(e,t,n){let r={min:Array(e.itemSize).fill(Number.POSITIVE_INFINITY),max:Array(e.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let i=t;i4?n=e.array[i*e.itemSize+t]:(0===t?n=e.getX(i):1===t?n=e.getY(i):2===t?n=e.getZ(i):3===t&&(n=e.getW(i)),!0===e.normalized&&(n=d.M8C.normalize(n,e.array))),r.min[t]=Math.min(r.min[t],n),r.max[t]=Math.max(r.max[t],n)}return r}(e,n,r);void 0!==t&&(o=e===t.index?R.ELEMENT_ARRAY_BUFFER:R.ARRAY_BUFFER);let l=this.processBufferView(e,i,n,r,o),c={bufferView:l.id,byteOffset:l.byteOffset,componentType:i,count:r,max:a.max,min:a.min,type:{1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"}[e.itemSize]};return!0===e.normalized&&(c.normalized=!0),s.accessors||(s.accessors=[]),s.accessors.push(c)-1}processImage(e,t,n,r="image/png"){if(null!==e){let i=this,o=i.cache,s=i.json,a=i.options,l=i.pending;o.images.has(e)||o.images.set(e,{});let c=o.images.get(e),u=r+":flipY/"+n.toString();if(void 0!==c[u])return c[u];s.images||(s.images=[]);let h={mimeType:r},f=I();f.width=Math.min(e.width,a.maxTextureSize),f.height=Math.min(e.height,a.maxTextureSize);let p=f.getContext("2d");if(!0===n&&(p.translate(0,f.height),p.scale(1,-1)),void 0!==e.data){t!==d.wk1&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>a.maxTextureSize||e.height>a.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=>{h.bufferView=e})):void 0!==f.toDataURL?h.uri=f.toDataURL(r):l.push(j(f,r).then(e=>new FileReader().readAsDataURL(e)).then(e=>{h.uri=e}));let v=s.images.push(h)-1;return c[u]=v,v}throw Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){let t=this.json;t.samplers||(t.samplers=[]);let n={magFilter:E[e.magFilter],minFilter:E[e.minFilter],wrapS:E[e.wrapS],wrapT:E[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);r.textures||(r.textures=[]),e instanceof d.EB7&&(e=k(e,t.maxTextureSize));let i=e.userData.mimeType;"image/webp"===i&&(i="image/png");let o={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,i)};e.name&&(o.name=e.name),this._invokeAll(function(t){t.writeTexture&&t.writeTexture(e,o)});let s=r.textures.push(o)-1;return n.textures.set(e,s),s}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||(n.materials=[]);let r={pbrMetallicRoughness:{}};!0!==e.isMeshStandardMaterial&&!0!==e.isMeshBasicMaterial&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");let i=e.color.toArray().concat([e.opacity]);if(O(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),e.metalnessMap||e.roughnessMap){let t=this.buildMetalRoughTexture(e.metalnessMap,e.roughnessMap),n={index:this.processTexture(t),channel:t.channel};this.applyTextureTransform(n,t),r.pbrMetallicRoughness.metallicRoughnessTexture=n}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,n=Math.max(t.r,t.g,t.b);if(n>0&&(r.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let t={index:this.processTexture(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(t,e.emissiveMap),r.emissiveTexture=t}}if(e.normalMap){let t={index:this.processTexture(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&1!==e.normalScale.x&&(t.scale=e.normalScale.x),this.applyTextureTransform(t,e.normalMap),r.normalTexture=t}if(e.aoMap){let t={index:this.processTexture(e.aoMap),texCoord:e.aoMap.channel};1!==e.aoMapIntensity&&(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===d.ehD&&(r.doubleSided=!0),""!==e.name&&(r.name=e.name),this.serializeUserData(e,r),this._invokeAll(function(t){t.writeMaterial&&t.writeMaterial(e,r)});let o=n.materials.push(r)-1;return t.materials.set(e,o),o}processMesh(e){let t;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(void 0!==e.morphTargetDictionary)for(let t in e.morphTargetDictionary)i[e.morphTargetDictionary[t]]=t;for(let o=0;o0&&(a.extras={},a.extras.targetNames=r)}let v=Array.isArray(e.material);if(v&&0===s.groups.length)return null;let m=v?e.material:[e.material],y=v?s.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let e=0,r=y.length;e0&&(r.targets=u),null!==s.index){let t=this.getUID(s.index);(void 0!==y[e].start||void 0!==y[e].count)&&(t+=":"+y[e].start+":"+y[e].count),n.attributes.has(t)?r.indices=n.attributes.get(t):(r.indices=this.processAccessor(s.index,s,y[e].start,y[e].count),n.attributes.set(t,r.indices)),null===r.indices&&delete r.indices}let i=this.processMaterial(m[y[e].materialIndex]);null!==i&&(r.material=i),c.push(r)}a.primitives=c,r.meshes||(r.meshes=[]),this._invokeAll(function(t){t.writeMesh&&t.writeMesh(e,a)});let b=r.meshes.push(a)-1;return n.meshes.set(o,b),b}detectMeshQuantization(e,t){let n;if(this.extensionsUsed[A])return;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];x[r]&&x[r].includes(n)&&(this.extensionsUsed[A]=!0,this.extensionsRequired[A]=!0)}processCamera(e){let t=this.json;t.cameras||(t.cameras=[]);let n=e.isOrthographicCamera,r={type:n?"orthographic":"perspective"};return n?r.orthographic={xmag:2*e.right,ymag:2*e.top,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:d.M8C.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,r=this.nodeMap;n.animations||(n.animations=[]),e=T.Utils.mergeMorphTargetTracks(e.clone(),t);let i=e.tracks,o=[],s=[];for(let e=0;e0){let t=[];for(let r=0,i=e.children.length;r0&&(i.children=t)}this._invokeAll(function(t){t.writeNode&&t.writeNode(e,i)});let o=t.nodes.push(i)-1;return r.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 d.xsS;t.name="AuxScene";for(let n=0;n0&&this.processObjects(n);for(let e=0;e0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),void 0!==e.decay&&2!==e.decay&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||0!==e.target.position.x||0!==e.target.position.y||-1!==e.target.position.z)&&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 s=r.extensions[this.name].lights;s.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:s.length-1}}}class L{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}writeMaterial(e,t){if(!e.isMeshBasicMaterial)return;let n=this.writer,r=n.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},r[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}}class B{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.clearcoat)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};n.applyTextureTransform(t,e.clearcoatNormalMap),i.clearcoatNormalTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class H{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.iridescence)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}}class F{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)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}}class U{constructor(e){this.writer=e,this.name="KHR_materials_volume"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)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}i.attenuationDistance=e.attenuationDistance,i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class D{constructor(e){this.writer=e,this.name="KHR_materials_ior"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1.5===e.ior)return;let n=this.writer,r=n.extensionsUsed,i={};i.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class G{constructor(e){this.writer=e,this.name="KHR_materials_specular"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1===e.specularIntensity&&e.specularColor.equals(S)&&!e.specularIntensityMap&&!e.specularColorTexture)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}}class z{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.sheen)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}}class K{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.anisotropy)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}}class V{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}writeMaterial(e,t){if(!e.isMeshStandardMaterial||1===e.emissiveIntensity)return;let n=this.writer,r=n.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}function X(e,t){if(t===d.WwZ)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t!==d.z$h&&t!==d.UlW)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e;{let n=e.getIndex();if(null===n){let t=[],r=e.getAttribute("position");if(void 0===r)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;eMath.abs(e.times[0]-t))return 0;i[0]=t,i.set(e.times,1),o.set(s.evaluate(t),0),o.set(e.values,r),n=0}else if(t>e.times[e.times.length-1]){if(.001>Math.abs(e.times[e.times.length-1]-t))return e.times.length-1;i[i.length-1]=t,i.set(e.times,0),o.set(e.values,0),o.set(s.evaluate(t),e.values.length),n=i.length-1}else for(let a=0;aMath.abs(e.times[a]-t))return a;if(e.times[a]t){i.set(e.times.slice(0,a+1),0),i[a+1]=t,i.set(e.times.slice(a+1),a+2),o.set(e.values.slice(0,(a+1)*r),0),o.set(s.evaluate(t),(a+1)*r),o.set(e.values.slice((a+1)*r),(a+2)*r),n=a+1;break}}return e.times=i,e.values=o,n},mergeMorphTargetTracks:function(e,t){let n=[],r={},i=e.tracks;for(let e=0;e=2.0 are supported."));return}let l=new eN(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});l.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e=0&&void 0===s[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}l.setExtensions(o),l.setPlugins(s),l.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}}function W(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}let Z={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class J{constructor(e){this.parser=e,this.name=Z.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n=0))return null;throw Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures")}return t.loadTextureImage(e,i.source,o)}}class el{constructor(e){this.parser=e,this.name=Z.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let o=i.extensions[t],s=r.images[o.source],a=n.textureLoader;if(s.uri){let e=n.options.manager.getHandler(s.uri);null!==e&&(a=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){let t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class ec{constructor(e){this.parser=e,this.name=Z.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let o=i.extensions[t],s=r.images[o.source],a=n.textureLoader;if(s.uri){let e=n.options.manager.getHandler(s.uri);null!==e&&(a=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){let t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class eu{constructor(e){this.name=Z.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(!n.extensions||!n.extensions[this.name])return null;{let e=n.extensions[this.name],r=this.parser.getDependency("buffer",e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(!(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0))return null;throw Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files")}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,o=e.count,s=e.byteStride,a=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(o,s,a,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(o*s);return i.decodeGltfBuffer(new Uint8Array(t),o,s,a,e.mode,e.filter),t})})}}}class eh{constructor(e){this.name=Z.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||void 0===n.mesh)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==ek.TRIANGLES&&e.mode!==ek.TRIANGLE_STRIP&&e.mode!==ek.TRIANGLE_FAN&&void 0!==e.mode)return null;let i=n.extensions[this.name],o=i.attributes,s=[],a={};for(let e in o)s.push(this.parser.getDependency("accessor",o[e]).then(t=>(a[e]=t,a[e])));return s.length<1?null:(s.push(this.parser.createNodeMesh(e)),Promise.all(s).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new d.yGw,n=new d.Pa4,o=new d._fP,s=new d.Pa4(1,1,1),l=new d.SPe(e.geometry,e.material,r);for(let e=0;e-1)?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),"undefined"==typeof createImageBitmap||n||r&&i<98?this.textureLoader=new d.dpR(this.options.manager):this.textureLoader=new d.QRU(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new d.hH6(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(t){let o={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return eM(i,o,r),e_(o,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(o)})).then(function(){e(o)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n{let n=this.associations.get(e);for(let[r,o]of(null!=n&&this.associations.set(t,n),e.children.entries()))i(o,t.children[r])};return i(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n=2&&o.setY(t,h[e*a+1]),a>=3&&o.setZ(t,h[e*a+2]),a>=4&&o.setW(t,h[e*a+3]),a>=5)throw Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return o})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e],i=r.source,o=t.images[i],s=this.textureLoader;if(o.uri){let e=n.manager.getHandler(o.uri);null!==e&&(s=e)}return this.loadTextureImage(e,i,s)}loadTextureImage(e,t,n){let r=this,i=this.json,o=i.textures[e],s=i.images[t],a=(s.uri||s.bufferView)+":"+o.sampler;if(this.textureCache[a])return this.textureCache[a];let l=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=o.name||s.name||"",""===t.name&&"string"==typeof s.uri&&!1===s.uri.startsWith("data:image/")&&(t.name=s.uri);let n=i.samplers||{},a=n[o.sampler]||{};return t.magFilter=eT[a.magFilter]||d.wem,t.minFilter=eT[a.minFilter]||d.D1R,t.wrapS=eR[a.wrapS]||d.rpg,t.wrapT=eR[a.wrapT]||d.rpg,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[a]=l,l}loadImageSource(e,t){let n=this.json,r=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());let i=n.images[e],o=self.URL||self.webkitURL,s=i.uri||"",a=!1;if(void 0!==i.bufferView)s=this.getDependency("bufferView",i.bufferView).then(function(e){a=!0;let t=new Blob([e],{type:i.mimeType});return s=o.createObjectURL(t)});else if(void 0===i.uri)throw Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");let l=Promise.resolve(s).then(function(e){return new Promise(function(n,i){let o=n;!0===t.isImageBitmapLoader&&(o=function(e){let t=new d.xEZ(e);t.needsUpdate=!0,n(t)}),t.load(d.Zp0.resolveURL(e,r.path),o,void 0,i)})}).then(function(e){var t;return!0===a&&o.revokeObjectURL(s),e.userData.mimeType=i.mimeType||((t=i.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){let i=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(void 0!==n.texCoord&&n.texCoord>0&&((o=o.clone()).channel=n.texCoord),i.extensions[Z.KHR_TEXTURE_TRANSFORM]){let e=void 0!==n.extensions?n.extensions[Z.KHR_TEXTURE_TRANSFORM]:void 0;if(e){let t=i.associations.get(o);o=i.extensions[Z.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),i.associations.set(o,t)}}return void 0!==r&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=void 0===t.attributes.tangent,i=void 0!==t.attributes.color,o=void 0===t.attributes.normal;if(e.isPoints){let e="PointsMaterial:"+n.uuid,t=this.cache.get(e);t||(t=new d.UY4,d.F5T.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e="LineBasicMaterial:"+n.uuid,t=this.cache.get(e);t||(t=new d.nls,d.F5T.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||o){let e="ClonedMaterial:"+n.uuid+":";r&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),o&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return d.Wid}loadMaterial(e){let t;let n=this,r=this.json,i=this.extensions,o=r.materials[e],s={},a=o.extensions||{},l=[];if(a[Z.KHR_MATERIALS_UNLIT]){let e=i[Z.KHR_MATERIALS_UNLIT];t=e.getMaterialType(),l.push(e.extendParams(s,o,n))}else{let r=o.pbrMetallicRoughness||{};if(s.color=new d.Ilk(1,1,1),s.opacity=1,Array.isArray(r.baseColorFactor)){let e=r.baseColorFactor;s.color.setRGB(e[0],e[1],e[2],d.GUF),s.opacity=e[3]}void 0!==r.baseColorTexture&&l.push(n.assignTexture(s,"map",r.baseColorTexture,d.KI_)),s.metalness=void 0!==r.metallicFactor?r.metallicFactor:1,s.roughness=void 0!==r.roughnessFactor?r.roughnessFactor:1,void 0!==r.metallicRoughnessTexture&&(l.push(n.assignTexture(s,"metalnessMap",r.metallicRoughnessTexture)),l.push(n.assignTexture(s,"roughnessMap",r.metallicRoughnessTexture))),t=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,s)})))}!0===o.doubleSided&&(s.side=d.ehD);let c=o.alphaMode||eO.OPAQUE;if(c===eO.BLEND?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,c===eO.MASK&&(s.alphaTest=void 0!==o.alphaCutoff?o.alphaCutoff:.5)),void 0!==o.normalTexture&&t!==d.vBJ&&(l.push(n.assignTexture(s,"normalMap",o.normalTexture)),s.normalScale=new d.FM8(1,1),void 0!==o.normalTexture.scale)){let e=o.normalTexture.scale;s.normalScale.set(e,e)}if(void 0!==o.occlusionTexture&&t!==d.vBJ&&(l.push(n.assignTexture(s,"aoMap",o.occlusionTexture)),void 0!==o.occlusionTexture.strength&&(s.aoMapIntensity=o.occlusionTexture.strength)),void 0!==o.emissiveFactor&&t!==d.vBJ){let e=o.emissiveFactor;s.emissive=new d.Ilk().setRGB(e[0],e[1],e[2],d.GUF)}return void 0!==o.emissiveTexture&&t!==d.vBJ&&l.push(n.assignTexture(s,"emissiveMap",o.emissiveTexture,d.KI_)),Promise.all(l).then(function(){let r=new t(s);return o.name&&(r.name=o.name),e_(r,o),n.associations.set(r,{materials:e}),o.extensions&&eM(i,r,o),r})}createUniqueName(e){let t=d.iUV.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache,i=[];for(let o=0,s=e.length;o0&&function(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let n=0,r=t.weights.length;n1?new d.ZAu:1===t.length?t[0]:new d.Tme)!==t[0])for(let e=0,n=t.length;e{let t=new Map;for(let[e,n]of r.associations)(e instanceof d.F5T||e instanceof d.xEZ)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);null!=n&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let o;let s=[],a=e.name?e.name:e.uuid,l=[];switch(eP[i.path]===eP.weights?e.traverse(function(e){e.morphTargetInfluences&&l.push(e.name?e.name:e.uuid)}):l.push(a),eP[i.path]){case eP.weights:o=d.dUE;break;case eP.rotation:o=d.iLg;break;case eP.position:case eP.scale:o=d.yC1;break;default:o=1===n.itemSize?d.dUE:d.yC1}let c=void 0!==r.interpolation?eS[r.interpolation]:d.NMF,u=this._getArrayFromAccessor(n);for(let e=0,n=l.length;e3&&void 0!==arguments[3]?arguments[3]:function(){};new Y().load(e,function(e){e.scene.scale.set(y.R/.5,y.R/.5,y.R/.5),e.scene.matrixAutoUpdate=!1,e.scene.visible=n,e.scene.updateMatrix(),t.add(e.scene),r()},function(e){return console.log(e.loaded+" bytes loaded")},eB)}var eF=n("./src/view/tablegeometry.ts");function eU(e,t){for(var n=0;nthis.radius-y.R){var r=this.pos.clone().sub(e.pos).normalize().setZ(0);n>-y.R/2&&e.vel.addScaledVector(r,7*y.R*t*y.g),0>e.vel.dot(r)&&(e.ballmesh.trace.forceTrace(e.pos),e.vel.x=r.x*e.vel.length()/2,e.vel.y=r.y*e.vel.length()/2)}var i=this.restingDepth(e);n2&&void 0!==arguments[2]?arguments[2]:this.cloth;this.cylinder(e.pos,e.radius,.75*y.R/.5,t,n).position.setZ(-(.25*y.R)/.5/2)}},{key:"cylinder",value:function(e,t,n,r,i){var o=new d.fHI(t,t,n,16),s=new d.Kj0(o,i);return s.position.copy(e),s.geometry.applyMatrix4(new d.yGw().identity().makeRotationAxis(new d.Pa4(1,0,0),Math.PI/2)),r.add(s),s}},{key:"addCushions",value:function(e,t){var n=10*y.R/.5;this.plane(new d.Pa4(0,0,-y.R-n/2),2*eF.H.X,2*eF.H.Y,n,e,this.cloth);var r=1*y.R/.5,i=.75*y.R/.5,o=-(.25*y.R)/.5/2,s=eF.H.X,a=eF.H.Y,l=Math.abs(eJ.pockets.pocketNW.knuckleNE.pos.x-eJ.pockets.pocketN.knuckleNW.pos.x),c=Math.abs(eJ.pockets.pocketNW.knuckleSW.pos.y-eJ.pockets.pocketSW.knuckleNW.pos.y);t||(l=2*eF.H.Y,c=2*eF.H.Y+4*y.R),this.plane(new d.Pa4(s+r/2,0,o),r,c,i,e),this.plane(new d.Pa4(-s-r/2,0,o),r,c,i,e),this.plane(new d.Pa4(-s/2,a+r/2,o),l,r,i,e),this.plane(new d.Pa4(-s/2,-a-r/2,o),l,r,i,e),this.plane(new d.Pa4(s/2,a+r/2,o),l,r,i,e),this.plane(new d.Pa4(s/2,-a-r/2,o),l,r,i,e)}},{key:"plane",value:function(e,t,n,r,i){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:this.cushion,s=new d.DvJ(t,n,r),a=new d.Kj0(s,o);a.receiveShadow=!0,a.position.copy(e),i.add(a)}}],eq(n.prototype,e),t&&eq(n,t),n}(),e0=n("./src/events/watchevent.ts");function e1(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}!function(e){e.Pot="Pot",e.Cushion="Cushion",e.Collision="Collision",e.Hit="Hit"}(a||(a={}));var e2=function(){var e;function t(e,n,r,i){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),e1(this,"type",void 0),e1(this,"timestamp",void 0),e1(this,"ballA",null),e1(this,"ballB",null),e1(this,"incidentSpeed",void 0),this.type=e,this.ballA=n,this.ballB=r,this.incidentSpeed=i,this.timestamp=Date.now()}return e=[{key:"pot",value:function(e,n){return new t("Pot",e,e,n)}},{key:"cushion",value:function(e,n){return new t("Cushion",e,e,n)}},{key:"collision",value:function(e,n,r){return new t("Collision",e,n,r)}},{key:"hit",value:function(e,n){return new t("Hit",e,e,n)}},{key:"isCueBallPotted",value:function(e,t){return t.some(function(t){return"Pot"==t.type&&t.ballA===e})}},{key:"isBallPottedNoFoul",value:function(e,n){return n.some(function(e){return"Pot"==e.type&&null!==e.ballA})&&!t.isCueBallPotted(e,n)}},{key:"pots",value:function(e){return e.filter(function(e){return"Pot"==e.type}).map(function(e){return e.ballA})}},{key:"potCount",value:function(e){return this.pots(e).length}},{key:"onlyRedsPotted",value:function(e){return this.pots(e).every(function(e){return e.id>6})}},{key:"isThreeCushionPoint",value:function(e,n){n=t.cueBallFirst(e,n).filter(function(t){return t.ballA===e});var r=new Set,i=0,o=!0,s=!1,a=void 0;try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var u=l.value;if("Cushion"===u.type&&i++,"Collision"===u.type&&(r.add(u.ballB),2===r.size))return i>=3}}catch(e){s=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(s)throw a}}return!1}},{key:"cueBallFirst",value:function(e,t){return t.forEach(function(t){"Collision"===t.type&&t.ballB===e&&(t.ballB=t.ballA,t.ballA=e)}),t}}],function(e,t){for(var n=0;n-eF.H.tableX&&n.overlapsAny(r,t);)r.x-=y.R/8;t.pos.copy(r),t.state=eV.Z.Stationary}}],function(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1500;if(!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),tb(tm(r=i.call(this,e)),"delay",void 0),tb(tm(r),"shots",void 0),tb(tm(r),"firstShot",void 0),tb(tm(r),"timer",void 0),tb(tm(r),"init",void 0),r.init=t,r.shots=tk(n),r.firstShot=r.shots[0],r.delay=a,r.container.table.showTraces(!0),r.container.table.updateFromShortSerialised(r.init),s){var l=new tp.l(t,n);l.retry=!0,r.container.eventQueue.push(l)}else r.container.view.camera.forceMode(r.container.view.camera.topView),r.playNextShot(1.5*r.delay);return r}return n=[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===c.t.RERACK){td.K.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var r=e3.f.fromJson(n);this.container.table.cueball=this.container.table.balls[r.i],this.container.table.cueball.pos.copy(r.pos),this.container.table.cue.aim=r,this.container.table.cue.updateAimInput(),this.container.table.cue.t=1,clearTimeout(this.timer),this.timer=setTimeout(function(){t.container.eventQueue.push(new e8.O(t.container.table.cue.aim)),t.timer=void 0},e)}},{key:"handleHit",value:function(e){return this.hit(),this}},{key:"handleStationary",value:function(e){return this.shots.length>0&&void 0===this.timer&&this.playNextShot(this.delay),this}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}},{key:"handleBreak",value:function(e){return(this.container.table.updateFromShortSerialised(e.init),this.shots=tk(e.shots),this.container.table.showSpin(!0),e.retry)?this.retry():(this.playNextShot(this.delay),this)}},{key:"retry",value:function(){clearTimeout(this.timer),this.timer=void 0,this.container.table.updateFromShortSerialised(this.init);var e=e3.f.fromJson(this.firstShot);return this.container.table.cueball=this.container.table.balls[e.i],this.container.rules.cueball=this.container.table.cueball,this.container.table.cueball.pos.copy(e.pos),this.container.table.cue.aim=e,this.container.view.camera.forceMode(this.container.view.camera.aimView),new tE(this.container)}}],ty(o.prototype,n),r&&ty(o,r),o}(tl);function tT(e,t){for(var n=0;n2)||void 0===arguments[2]||arguments[2],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:tG.h_,o=e.futurePosition(n);if(t.willBounceLong(o,r)){var s=o.y>eF.H.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(s,e,i)}if(t.willBounceShort(o,r)){var a=o.x>eF.H.tableX?0:Math.PI;return t.bounceIn(a,e,i)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(eJ.pockets.pocketNW.knuckleSW.pos.y,eJ.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(eF.H.Y,-eF.H.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(eJ.pockets.pocketNW.knuckleNE.pos.x,eJ.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(eJ.pockets.pocketN.knuckleNE.pos.x,eJ.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-eF.H.X,eF.H.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xeF.H.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yeF.H.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,tG.ZI)(e,t.vel,t.rvel,n);return t.vel.add(r.v),t.rvel.add(r.w),r.v.length()}}],function(e,t){for(var n=0;n100)throw Error("Depth exceeded resolving collisions");this.balls.forEach(function(t){t.update(e)})}},{key:"prepareAdvanceAll",value:function(e){var t=this;return this.pairs.every(function(n){return t.prepareAdvancePair(n.a,n.b,e)})&&this.balls.every(function(n){return t.prepareAdvanceToCushions(n,e)})}},{key:"prepareAdvancePair",value:function(e,t,n){if(tK.willCollide(e,t,n)){var r=tK.collide(e,t);return this.outcome.push(e2.collision(e,t,r)),!1}return!0}},{key:"prepareAdvanceToCushions",value:function(e,t){if(!e.onTable())return!0;var n=e.futurePosition(t);if(Math.abs(n.y)1&&void 0!==arguments[1]?arguments[1]:this.cueball;return this.balls.filter(function(e){return e!==t}).some(function(t){return t.pos.distanceTo(e)<2*y.R})}}],t=[{key:"fromSerialised",value:function(e){var t=new n(e.balls.map(function(e){return eV.e.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&tX(n.prototype,e),t&&tX(n,t),n}();function tZ(e,t){for(var n=0;n0){if(this.previousPotRed)this.previousPotRed=!1,this.respot(e);else if(e2.onlyRedsPotted(e))this.previousPotRed=!0;else if(1===t){var n=e2.pots(e)[0].id;n>1&&this.container.table.balls.filter(function(e){return e.id0}).some(function(e){return e.onTable()})&&this.respot(e)}else this.respot(e)}return t1(t2(o.prototype),"update",this).call(this,e)}},{key:"respot",value:function(e){var t=this.respotAllPottedColours(e);if(t.length>0){var n={balls:t.map(function(e){return e.serialise()}),rerack:!0},r=new e0.g(n);this.container.sendEvent(r),this.container.recoder.record(r)}}},{key:"respotAllPottedColours",value:function(e){var t=this;return e2.pots(e).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(e){return e5.respot(e,t.container.table)})}}],t$(o.prototype,n),r&&t$(o,r),o}(tq);function t3(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],no(n.prototype,e),t&&no(n,t),n}();function nl(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:0;if(this.loadAssets){var r,i,o=d.Hmr.getContext();if((null==o?void 0:o.state)==="suspended"){(null===(i=navigator)||void 0===i?void 0:null===(r=i.userActivation)||void 0===r?void 0:r.hasBeenActive)&&o.resume();return}e.setVolume(t),e.isPlaying&&e.stop(),e.play(d.M8C.randFloat(0,.01)),e.setDetune(n)}}},{key:"outcomeToSound",value:function(e){"Collision"===e.type&&this.play(this.ballcollision,e.incidentSpeed/80,5*e.incidentSpeed),"Pot"===e.type&&this.play(this.pot,e.incidentSpeed/10,-1e3+10*e.incidentSpeed),"Cushion"===e.type&&this.play(this.cushion,e.incidentSpeed/70),"Hit"===e.type&&this.play(this.cue,e.incidentSpeed/30)}},{key:"processOutcomes",value:function(e){var t=this;e.every(function(e){return!(e.timestamp>t.lastOutcomeTime)||(t.lastOutcomeTime=e.timestamp,t.outcomeToSound(e),!1)})}},{key:"playNotify",value:function(){this.play(this.pot,1)}},{key:"playSuccess",value:function(e){this.play(this.success,.1,100*e-2200)}}],nl(n.prototype,e),t&&nl(n,t),n}();function nh(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function nf(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==c.t.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}],nv(n.prototype,e),t&&nv(n,t),n}(),nb=n("./src/view/sliders.ts"),ng=n("./node_modules/jsoncrush/JSONCrush.js");function nw(e,t){for(var n=0;n0&&"RERACK"===this.shots[e].type&&e--,e}},{key:"lastShot",value:function(){var e=this.last();return this.state(this.states[e],[this.shots[e]])}},{key:"currentBreak",value:function(){if(void 0!==this.breakStart)return this.state(this.states[this.breakStart],this.shots.slice(this.breakStart))}},{key:"state",value:function(e,t){return{init:e,shots:t}}},{key:"updateBreak",value:function(e){var t=this.container.rules.isPartOfBreak(e),n=this.container.rules.isEndOfGame(e),r=e2.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r),n&&this.breakLink(n),!t){this.breakStart=void 0;return}void 0===this.breakStart&&(this.breakStart=this.last())}},{key:"lastShotLink",value:function(e,t){var n="⚈".repeat(t>1?t-1:0)+(e?"⚈":"⚆"),r=JSON.stringify(this.lastShot());this.generateLink(n,r)}},{key:"breakLink",value:function(e){var t=this.currentBreak();if(t&&(e||t.shots.pop(),1!==t.shots.length)){var n="break(".concat(t.shots.length,")"),r=JSON.stringify(t),i=ng.Z.crush(r);this.generateLink(n,i)}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(e.shots.length,")"),n=JSON.stringify(e),r=ng.Z.crush(n);this.generateLink(t,r)}},{key:"generateLink",value:function(e,t){var n="".concat(this.replayUrl).concat(encodeURIComponent(t)),r='').concat(e,"");this.container.eventQueue.push(new tU.s(null,"".concat(r)))}}],nw(n.prototype,e),t&&nw(n,t),n}();function nT(e,t){for(var n=0;n').concat(e,"")));r.push(new tU.s(null,s))})},this.redo.onclick=function(e){var r=new tp.l(t.init,t.shots);r.retry=!0,n.interuptEventQueue(r)},this.replay.onclick=function(e){n.interuptEventQueue(t)}}},{key:"interuptEventQueue",value:function(e){this.container.table.halt();var t=this.container.eventQueue;t.length=0,t.push(new p),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],nI(n.prototype,e),t&&nI(n,t),n}();function nN(e,t){for(var n=0;n2)||void 0===arguments[2]||arguments[2],i=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,s=arguments.length>5?arguments[5]:void 0,a=arguments.length>6?arguments[6]:void 0,l=this;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,n),nL(this,"table",void 0),nL(this,"view",void 0),nL(this,"controller",void 0),nL(this,"inputQueue",[]),nL(this,"eventQueue",[]),nL(this,"keyboard",void 0),nL(this,"sound",void 0),nL(this,"chat",void 0),nL(this,"sliders",void 0),nL(this,"recoder",void 0),nL(this,"id",""),nL(this,"isSinglePlayer",!0),nL(this,"rules",void 0),nL(this,"menu",void 0),nL(this,"last",performance.now()),nL(this,"step",.001953125),nL(this,"broadcast",void 0),nL(this,"log",void 0),nL(this,"sendChat",function(e){l.sendEvent(new tU.s(l.id,e))}),nL(this,"throttle",new ny(200,function(e){l.broadcast(e)})),nL(this,"lastEventTime",performance.now()),this.log=t,this.rules=n_.create(i,this),this.table=this.rules.table(),this.view=new t6(e,s,this.table,r,this.rules.asset()),this.table.cue.aimInputs=new na(this),this.keyboard=o,this.sound=new nu(this.view.camera.camera,r),this.chat=new nd(this.sendChat),this.sliders=new nb.E,this.recoder=new nx(this),this.id=a,this.menu=new nC(this),this.table.addToScene(this.view.scene),this.updateController(new nt(this))}return e=[{key:"sendEvent",value:function(e){this.throttle.send(e)}},{key:"advance",value:function(e){for(var t=Math.floor(e/this.step),n=t*this.step,r=this.table.allStationary(),i=0;i0;){this.lastEventTime=this.last;var t=this.inputQueue.shift();t&&this.updateController(this.controller.handleInput(t))}if(this.table.allStationary()){var n=this.eventQueue.shift();n&&(this.lastEventTime=performance.now(),this.updateController(n.applyToController(this.controller)))}}},{key:"animate",value:function(e){var t=this;this.advance((e-this.last)/1e3),this.last=e,this.processEvents(),(e{var r,i,o,s,a,l,c,u,h,f=n("./src/model/physics/physics.ts"),p=n("./node_modules/three/build/three.module.js");function d(e,t){for(var n=0;n4&&void 0!==arguments[4]?arguments[4]:.9,o={dx:n-e,dy:r-t},s={x:o.dx*i+e,y:o.dy*i+t},a={dx:n-s.x,dy:r-s.y};this.context.beginPath(),this.context.moveTo(e,t),this.context.lineTo(s.x,s.y),this.context.moveTo(s.x+.5*a.dy,s.y-.5*a.dx),this.context.lineTo(s.x-.5*a.dy,s.y+.5*a.dx),this.context.lineTo(n,r),this.context.closePath(),this.context.stroke()}}],d(n.prototype,e),t&&d(n,t),n}();function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n{n.d(t,{Y:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{f:()=>f});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts"),s=n("./node_modules/three/build/three.module.js");function a(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){for(var n=0;n{n.d(t,{Z:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{l:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{s:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r;n.d(t,{t:()=>r}),function(e){e.BEGIN="BEGIN",e.BREAK="BREAK",e.WATCHAIM="WATCHAIM",e.AIM="AIM",e.HIT="HIT",e.STATIONARY="STATIONARY",e.CHAT="CHAT",e.ABORT="ABORT",e.PLACEBALL="PLACEBALL",e.REJOIN="REJOIN",e.RERACK="RERACK"}(r||(r={}))},"./src/events/gameevent.ts":(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{Z:()=>i});var i=function e(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"type",void 0),r(this,"sequence",void 0)}},"./src/events/hitevent.ts":(e,t,n)=>{n.d(t,{O:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{I:()=>i});var i=function e(t,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"t",void 0),r(this,"key",void 0),this.t=t,this.key=n}},"./src/events/keyboard.ts":(e,t,n)=>{n.d(t,{N:()=>l});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t){for(var n=0;nMath.abs(i.movementY)&&(i.movementY=0)}),this.addHandlers(e),/Android|iPhone/i.test(navigator.userAgent)||(e.contentEditable="true")}return e=[{key:"getEvents",value:function(){var e=this,t=Object.keys(this.pressed).filter(function(e){return!/Shift/.test(e)}).filter(function(e){return!/Control/.test(e)}),n=Object.keys(this.pressed).some(function(e){return/Shift/.test(e)}),i=Object.keys(this.pressed).some(function(e){return/Control/.test(e)}),o=[];return t.forEach(function(t){var s=performance.now()-e.pressed[t];o.push(new r.I(i?s/3:s,n?"Shift"+t:t)),"Space"!=t&&(e.pressed[t]=performance.now())}),Object.keys(this.released).forEach(function(t){return o.push(new r.I(e.released[t],t+"Up"))}),this.released={},o}},{key:"addHandlers",value:function(e){var t=this;e.addEventListener("keydown",this.keydown),e.addEventListener("keyup",this.keyup),e.focus(),o()(e).draggable({listeners:{move:function(e){t.mousetouch(e)}}})}}],s(n.prototype,e),t&&s(n,t),n}()},"./src/events/placeballevent.ts":(e,t,n)=>{n.d(t,{I:()=>h});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts");function s(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){for(var n=0;n{n.d(t,{K:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{g:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{e:()=>m,Z:()=>r});var r,i=n("./src/utils/utils.ts"),o=n("./src/model/physics/physics.ts"),s=n("./node_modules/three/build/three.module.js"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;nMath.PI/32?.01*a.R:a.R,i=this.lastPos.distanceTo(e);this.addTraceGiven(e,t,i,r,n)}}},{key:"addTraceGiven",value:function(e,t,n,r,i){var o=this.geometry.drawRange.count;0!==o&&n1&&i<1e-4&&o--,this.lastPos.copy(e),this.lastVel.copy(t),this.addPoint(e,o))}},{key:"addPoint",value:function(e,t){var n=3*t;n>this.positions.length||(this.positions[n++]=e.x,this.positions[n++]=e.y,this.positions[n]=e.z,this.geometry.setDrawRange(0,t+1),this.line.geometry.attributes.position.needsUpdate=!0)}}],l(n.prototype,e),t&&l(n,t),n}();function h(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.bM),this.rvel.copy(i.bM),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.E9)(this.vel,this.rvel).length(){n.d(t,{Dt:()=>c,Ew:()=>v,G3:()=>w,Hz:()=>i,I:()=>o,Mz:()=>r,R:()=>f,Xm:()=>k,_5:()=>u,dE:()=>y,e:()=>p,f7:()=>g,fN:()=>m,g:()=>s,m:()=>h,mu:()=>a,zq:()=>b,zv:()=>l});var r,i,o,s=9.8,a=.00985,l=.105,c=.8,u=.024,h=.23,f=.03275,p=.86;function d(){r=a*h*s*2/3*u,i=7/(5*Math.sqrt(2))*f*a*h*s,o=.4*h*f*f}function v(e){f=e,d()}function m(e){h=e,d()}function y(e){a=e,d()}function b(e){u=e,d()}function g(e){l=e}function w(e){p=e}function k(e){c=e}d()},"./src/model/physics/physics.ts":(e,t,n)=>{n.d(t,{E9:()=>a,Fn:()=>R,IT:()=>h,NP:()=>g,QC:()=>u,Vp:()=>c,WL:()=>P,ZI:()=>f,al:()=>b,c0:()=>y,h_:()=>A,s0:()=>m,vZ:()=>w});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/utils/utils.ts"),o=n("./src/model/physics/constants.ts"),s=new r.Pa4;function a(e,t){return s.copy(e).addScaledVector((0,i.a1)(t),o.R)}var l={v:new r.Pa4,w:new r.Pa4};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.KO)(n).multiplyScalar(-o.zv*o.g)),l.w.copy((0,i.KO)((0,i.a1)(n)).multiplyScalar(2.5*o.zv*o.g/o.R)),l.w.setZ(-2.5*(o.Mz/(o.R*o.R))*Math.sign(t.z)),l}function u(e){var t=new r.Pa4(e.x,e.y,0).length(),n=5/7*o.Hz/(o.m*o.R)/t,i=5/7*o.Hz/(o.m*o.R*o.R)/t;return l.v.set(-n*e.y,n*e.x,0),l.w.set(-i*e.x,-i*e.y,-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(e.z)),l}function h(e,t){var n=t.z;t.copy((0,i.a1)(e).multiplyScalar(1/o.R)),t.setZ(n)}function f(e,t,n,r){var o=r(t.clone().applyAxisAngle(i.up,e),n.clone().applyAxisAngle(i.up,e));return o.v.applyAxisAngle(i.up,-e),o.w.applyAxisAngle(i.up,-e),o}Object.freeze(l);var p=Math.asin(.1*o.R/o.R),d=Math.sin(p),v=Math.cos(p);function m(e,t){return new r.Pa4(e.x*d-e.z*v+o.R*t.y,-e.y-o.R*t.z*v+o.R*t.x*d)}function y(e){return e.x*v}function b(e){var t=3.5/o.m;return e.length()/t}function g(e){var t,n=1/o.m,i=.39+.257*(t=new r.Pa4(e/v,0,0)).x-.044*t.x*t.x;return o.Dt*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(m(e,t))<=n}function k(e,t){return{c:y(e),s:m(e,t),A:3.5/o.m,B:1/o.m}}function x(e,t){var n=k(e,t),r=n.c,i=n.s,s=n.A,a=n.B,l=(1+o.e)*(r/a);return E(-i.x/s*d-l*v,i.y/s,i.x/s*v-l*d)}function T(e,t){var n=k(e,t),r=n.c,i=n.B,s=(1+o.e)*(r/i),a=.471-.241*Math.atan2(Math.abs(e.y),e.x),l=Math.atan2(e.y,e.x),c=Math.cos(l),u=-a*s*c*v-s*v,h=a*s*c*v-s*d;return E(u,a*s*Math.sin(l),h)}function R(e,t){return w(e,t)?x(e,t):T(e,t)}function A(e,t){var n=x(e,t),r=T(e,t),i=Math.sign(e.y)===Math.sign(t.z)?Math.cos(Math.atan2(e.y,e.x)):1;return{v:r.v.lerp(n.v,i),w:r.w.lerp(n.w,i)}}function E(e,t,n){return{v:new r.Pa4(e/o.m,t/o.m),w:new r.Pa4(-o.R/o.I*t*d,o.R/o.I*(e*d-n*v),o.R/o.I*t*v)}}function P(e,t){var n=Math.atan2(-e.x,e.y),r=2.5*t.length()*(e.length()*o.R)/(o.R*o.R),s=t.clone().normalize();return(0,i.a1)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/utils/utils.ts":(e,t,n)=>{n.d(t,{$2:()=>y,AA:()=>p,Bh:()=>s,KO:()=>u,Ls:()=>f,NM:()=>d,Xp:()=>v,a1:()=>l,bM:()=>i,up:()=>o,wK:()=>m});var r=n("./node_modules/three/build/three.module.js"),i=new r.Pa4(0,0,0),o=new r.Pa4(0,0,1);function s(e){return new r.Pa4(e.x,e.y,e.z)}var a=new r.Pa4;function l(e){return a.copy(o).cross(e)}var c=new r.Pa4;function u(e){return c.copy(e).normalize()}var h=new r.Pa4;function f(e,t){return 0>=h.copy(e).add(t).dot(e)}function p(e){return new r.Pa4(1,0,0).applyAxisAngle(o,e)}function d(e){return Math.sign(e)*Math.floor((Math.abs(e)+Number.EPSILON)*1e4)/1e4}function v(e){return Math.round((e+Number.EPSILON)*100)/100}function m(e){return e.x=d(e.x),e.y=d(e.y),e.z=d(e.z),e}function y(e){return e.x=v(e.x),e.y=v(e.y),e.z=v(e.z),e}},"./src/view/cameratop.ts":(e,t,n)=>{n.d(t,{c:()=>a});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/view/tablegeometry.ts"),o=n("./src/model/physics/constants.ts");function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"viewPoint",value:function(e,n){var s=t.zoomFactor/(2*Math.tan(n*Math.PI/360));if(e>this.portrait){var a=e>t.aspectLimit?2.75*i.H.tableY:2.4*i.H.tableX/e;return new r.Pa4(0,-.01*o.R,s*a)}var l=e>1/t.aspectLimit?4.9*i.H.tableY:1.35*i.H.tableX/e;return new r.Pa4(-.01*o.R,0,s*l)}}],function(e,t){for(var n=0;n{n.d(t,{N:()=>d});var r=n("./src/view/tablegeometry.ts"),i=n("./src/utils/utils.ts"),o=n("./src/events/aimevent.ts"),s=n("./src/model/ball.ts"),a=n("./src/model/physics/physics.ts"),l=n("./src/model/physics/constants.ts"),c=n("./node_modules/three/build/three.module.js");function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var h=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"createHelper",value:function(){var e=new c.fHI(l.R,l.R,30*l.R/.5,12,1,!0),t=new c.Kj0(e,this.helpermaterial);return t.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(i.up,-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(15*l.R/.5,0,-(.01*l.R)/.5)),t.visible=!1,t.renderOrder=-1,t.material.depthTest=!1,t}},{key:"createPlacer",value:function(){var e=new c.fHI(.01*l.R/.5,l.R,l.R,4),n=new c.Kj0(e,t.helpermaterial);return n.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(new c.Pa4(1,0,0),-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(0,0,.7*l.R/.5)),n.visible=!1,n}},{key:"createCue",value:function(e,n,r){var o=new c.fHI(e,n,r,11),s=new c.Kj0(o,t.material);return s.castShadow=!1,s.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(new c.Pa4(1,0,0),-.1)).applyMatrix4(new c.yGw().identity().makeRotationAxis(i.up,-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(-r/2-l.R,0,2*l.R)),s}}],function(e,t){for(var n=0;nthis.offCenterLimit&&e.normalize().multiplyScalar(this.offCenterLimit),this.aim.offset=(0,i.$2)(e),this.updateAimInput()}},{key:"updateAimInput",value:function(){var e,t;null===(e=this.aimInputs)||void 0===e||e.updateVisualState(this.aim.offset.x,this.aim.offset.y),null===(t=this.aimInputs)||void 0===t||t.updatePowerSlider(this.aim.power/this.maxPower)}},{key:"moveTo",value:function(e){this.aim.pos.copy(e),this.mesh.rotation.z=this.aim.angle,this.helperMesh.rotation.z=this.aim.angle;var t=(0,i.a1)((0,i.AA)(this.aim.angle)).multiplyScalar(2*this.aim.offset.x*l.R).setZ(2*this.aim.offset.y*l.R),n=(Math.sin(this.t+Math.PI/2)-1)*3*l.R*(this.aim.power/this.maxPower),r=(0,i.AA)(this.aim.angle).clone().multiplyScalar(n);this.mesh.position.copy(e.clone().add(t).add(r)),this.helperMesh.position.copy(e),this.placerMesh.position.copy(e),this.placerMesh.rotation.z=this.t}},{key:"update",value:function(e){this.t+=e,this.moveTo(this.aim.pos)}},{key:"placeBallMode",value:function(){this.mesh.visible=!1,this.placerMesh.visible=!0,this.aim.angle=0}},{key:"aimMode",value:function(){this.mesh.visible=!0,this.placerMesh.visible=!1}},{key:"intersectsAnything",value:function(e){var t=e.cueball.pos.clone().addScaledVector((0,i.AA)(this.aim.angle),-this.length/2);t.z=this.aim.offset.y;var n=(0,i.AA)(this.aim.angle);return new c.iMs(t,n,0,this.length/2-.6).intersectObjects(e.balls.map(function(e){return e.ballmesh.mesh})).length>0}},{key:"showHelper",value:function(e){this.helperMesh.visible=e}},{key:"toggleHelper",value:function(){this.showHelper(!this.helperMesh.visible)}}],f(n.prototype,e),t&&f(n,t),n}()},"./src/view/sliders.ts":(e,t,n)=>{n.d(t,{E:()=>s});var r=n("./src/model/physics/constants.ts");function i(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:1,i=this,o=this.getInputElement(e);o.step="0.001",o.min="0.01",o.max="".concat(r),o.value=t,this.showValue(e,t),o.oninput=function(t){var r=parseFloat(t.target.value);n(r),i.showValue(e,r),i.notify()}}},{key:"showValue",value:function(e,t){var n=document.querySelector("label[for=".concat(e,"]"));n&&(n.innerHTML="".concat(e,"=").concat(t))}}],i(n.prototype,e),t&&i(n,t),n}()},"./src/view/tablegeometry.ts":(e,t,n)=>{n.d(t,{H:()=>o});var r=n("./src/model/physics/constants.ts");function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"scaleToRadius",value:function(e){t.tableX=43*e,t.tableY=21*e,t.X=t.tableX+e,t.Y=t.tableY+e}}],function(e,t){for(var n=0;n{e(e.s="./src/diagrams.ts")}]); \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 0a807ce4..7ed19c6b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -15,4 +15,4 @@ #else gl_FragColor = texture2D( blitTexture, vUv); #endif - }`})),o.uniforms.blitTexture.value=e,o.defines.IS_SRGB=e.colorSpace==d.KI_,o.needsUpdate=!0,s||((s=new d.Kj0(i,o)).frustrumCulled=!1);let a=new d.cPb,l=new d.xsS;l.add(s),n||(n=r=new d.CP7({antialias:!1})),n.setSize(Math.min(e.image.width,t),Math.min(e.image.height,t)),n.clear(),n.render(l,a);let c=new d.xEZ(n.domElement);return c.minFilter=e.minFilter,c.magFilter=e.magFilter,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.name=e.name,r&&(r.dispose(),r=null),c}let T={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class R{constructor(){this.pluginCallbacks=[],this.register(function(e){return new N(e)}),this.register(function(e){return new L(e)}),this.register(function(e){return new F(e)}),this.register(function(e){return new U(e)}),this.register(function(e){return new D(e)}),this.register(function(e){return new G(e)}),this.register(function(e){return new B(e)}),this.register(function(e){return new H(e)}),this.register(function(e){return new z(e)}),this.register(function(e){return new K(e)}),this.register(function(e){return new V(e)})}register(e){return -1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return -1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i=new C,o=[];for(let e=0,t=this.pluginCallbacks.length;ee.toBlob(n,t)):("image/jpeg"===t?n=.92:"image/webp"===t&&(n=.8),e.convertToBlob({type:t,quality:n}))}class C{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"}},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.buffers,i=this.json;n=this.options;let o=this.extensionsUsed,s=this.extensionsRequired,a=new Blob(r,{type:"application/octet-stream"}),l=Object.keys(o),c=Object.keys(s);if(l.length>0&&(i.extensionsUsed=l),c.length>0&&(i.extensionsRequired=c),i.buffers&&i.buffers.length>0&&(i.buffers[0].byteLength=a.size),!0===n.binary){let e=new FileReader;e.readAsArrayBuffer(a),e.onloadend=function(){var n;let r=_(e.result),o=new DataView(new ArrayBuffer(8));o.setUint32(0,r.byteLength,!0),o.setUint32(4,5130562,!0);let s=_((n=JSON.stringify(i),new TextEncoder().encode(n).buffer),32),a=new DataView(new ArrayBuffer(8));a.setUint32(0,s.byteLength,!0),a.setUint32(4,1313821514,!0);let l=new ArrayBuffer(12),c=new DataView(l);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0);let u=12+a.byteLength+s.byteLength+o.byteLength+r.byteLength;c.setUint32(8,u,!0);let h=new Blob([l,a,s,o,r],{type:"application/octet-stream"}),f=new FileReader;f.readAsArrayBuffer(h),f.onloadend=function(){t(f.result)}}}else if(i.buffers&&i.buffers.length>0){let e=new FileReader;e.readAsDataURL(a),e.onloadend=function(){let n=e.result;i.buffers[0].uri=n,t(i)}}else t(i)}serializeUserData(e,t){if(0===Object.keys(e.userData).length)return;let n=this.options,r=this.extensionsUsed;try{let i=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&i.gltfExtensions){for(let e in void 0===t.extensions&&(t.extensions={}),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(!1===this.uids.has(e)){let t=new Map;t.set(!0,this.uid++),t.set(!1,this.uid++),this.uids.set(e,t)}let n=this.uids.get(e);return n.get(t)}isNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return!1;let n=new d.Pa4;for(let t=0,r=e.count;t5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);let n=e.clone(),r=new d.Pa4;for(let e=0,t=n.count;e4?r=e.array[i*e.itemSize+n]:(0===n?r=e.getX(i):1===n?r=e.getY(i):2===n?r=e.getZ(i):3===n&&(r=e.getW(i)),!0===e.normalized&&(r=d.M8C.normalize(r,e.array))),t===A.FLOAT?l.setFloat32(c,r,!0):t===A.INT?l.setInt32(c,r,!0):t===A.UNSIGNED_INT?l.setUint32(c,r,!0):t===A.SHORT?l.setInt16(c,r,!0):t===A.UNSIGNED_SHORT?l.setUint16(c,r,!0):t===A.BYTE?l.setInt8(c,r):t===A.UNSIGNED_BYTE&&l.setUint8(c,r),c+=o}let u={buffer:this.processBuffer(l.buffer),byteOffset:this.byteOffset,byteLength:a};void 0!==i&&(u.target=i),i===A.ARRAY_BUFFER&&(u.byteStride=e.itemSize*o),this.byteOffset+=a,s.bufferViews.push(u);let h={id:s.bufferViews.length-1,byteLength:0};return h}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||(n.bufferViews=[]),new Promise(function(r){let i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){let e=_(i.result),o={buffer:t.processBuffer(e),byteOffset:t.byteOffset,byteLength:e.byteLength};t.byteOffset+=e.byteLength,r(n.bufferViews.push(o)-1)}})}processAccessor(e,t,n,r){let i,o;let s=this.json;if(e.array.constructor===Float32Array)i=A.FLOAT;else if(e.array.constructor===Int32Array)i=A.INT;else if(e.array.constructor===Uint32Array)i=A.UNSIGNED_INT;else if(e.array.constructor===Int16Array)i=A.SHORT;else if(e.array.constructor===Uint16Array)i=A.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)i=A.BYTE;else if(e.array.constructor===Uint8Array)i=A.UNSIGNED_BYTE;else throw Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(void 0===n&&(n=0),void 0===r&&(r=e.count),0===r)return null;let a=function(e,t,n){let r={min:Array(e.itemSize).fill(Number.POSITIVE_INFINITY),max:Array(e.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let i=t;i4?n=e.array[i*e.itemSize+t]:(0===t?n=e.getX(i):1===t?n=e.getY(i):2===t?n=e.getZ(i):3===t&&(n=e.getW(i)),!0===e.normalized&&(n=d.M8C.normalize(n,e.array))),r.min[t]=Math.min(r.min[t],n),r.max[t]=Math.max(r.max[t],n)}return r}(e,n,r);void 0!==t&&(o=e===t.index?A.ELEMENT_ARRAY_BUFFER:A.ARRAY_BUFFER);let l=this.processBufferView(e,i,n,r,o),c={bufferView:l.id,byteOffset:l.byteOffset,componentType:i,count:r,max:a.max,min:a.min,type:{1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"}[e.itemSize]};return!0===e.normalized&&(c.normalized=!0),s.accessors||(s.accessors=[]),s.accessors.push(c)-1}processImage(e,t,n,r="image/png"){if(null!==e){let i=this,o=i.cache,s=i.json,a=i.options,l=i.pending;o.images.has(e)||o.images.set(e,{});let c=o.images.get(e),u=r+":flipY/"+n.toString();if(void 0!==c[u])return c[u];s.images||(s.images=[]);let h={mimeType:r},f=I();f.width=Math.min(e.width,a.maxTextureSize),f.height=Math.min(e.height,a.maxTextureSize);let p=f.getContext("2d");if(!0===n&&(p.translate(0,f.height),p.scale(1,-1)),void 0!==e.data){t!==d.wk1&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>a.maxTextureSize||e.height>a.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=>{h.bufferView=e})):void 0!==f.toDataURL?h.uri=f.toDataURL(r):l.push(j(f,r).then(e=>new FileReader().readAsDataURL(e)).then(e=>{h.uri=e}));let v=s.images.push(h)-1;return c[u]=v,v}throw Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){let t=this.json;t.samplers||(t.samplers=[]);let n={magFilter:E[e.magFilter],minFilter:E[e.minFilter],wrapS:E[e.wrapS],wrapT:E[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);r.textures||(r.textures=[]),e instanceof d.EB7&&(e=k(e,t.maxTextureSize));let i=e.userData.mimeType;"image/webp"===i&&(i="image/png");let o={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,i)};e.name&&(o.name=e.name),this._invokeAll(function(t){t.writeTexture&&t.writeTexture(e,o)});let s=r.textures.push(o)-1;return n.textures.set(e,s),s}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||(n.materials=[]);let r={pbrMetallicRoughness:{}};!0!==e.isMeshStandardMaterial&&!0!==e.isMeshBasicMaterial&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");let i=e.color.toArray().concat([e.opacity]);if(O(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),e.metalnessMap||e.roughnessMap){let t=this.buildMetalRoughTexture(e.metalnessMap,e.roughnessMap),n={index:this.processTexture(t),channel:t.channel};this.applyTextureTransform(n,t),r.pbrMetallicRoughness.metallicRoughnessTexture=n}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,n=Math.max(t.r,t.g,t.b);if(n>0&&(r.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let t={index:this.processTexture(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(t,e.emissiveMap),r.emissiveTexture=t}}if(e.normalMap){let t={index:this.processTexture(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&1!==e.normalScale.x&&(t.scale=e.normalScale.x),this.applyTextureTransform(t,e.normalMap),r.normalTexture=t}if(e.aoMap){let t={index:this.processTexture(e.aoMap),texCoord:e.aoMap.channel};1!==e.aoMapIntensity&&(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===d.ehD&&(r.doubleSided=!0),""!==e.name&&(r.name=e.name),this.serializeUserData(e,r),this._invokeAll(function(t){t.writeMaterial&&t.writeMaterial(e,r)});let o=n.materials.push(r)-1;return t.materials.set(e,o),o}processMesh(e){let t;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(void 0!==e.morphTargetDictionary)for(let t in e.morphTargetDictionary)i[e.morphTargetDictionary[t]]=t;for(let o=0;o0&&(a.extras={},a.extras.targetNames=r)}let v=Array.isArray(e.material);if(v&&0===s.groups.length)return null;let m=v?e.material:[e.material],y=v?s.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let e=0,r=y.length;e0&&(r.targets=u),null!==s.index){let t=this.getUID(s.index);(void 0!==y[e].start||void 0!==y[e].count)&&(t+=":"+y[e].start+":"+y[e].count),n.attributes.has(t)?r.indices=n.attributes.get(t):(r.indices=this.processAccessor(s.index,s,y[e].start,y[e].count),n.attributes.set(t,r.indices)),null===r.indices&&delete r.indices}let i=this.processMaterial(m[y[e].materialIndex]);null!==i&&(r.material=i),c.push(r)}a.primitives=c,r.meshes||(r.meshes=[]),this._invokeAll(function(t){t.writeMesh&&t.writeMesh(e,a)});let b=r.meshes.push(a)-1;return n.meshes.set(o,b),b}detectMeshQuantization(e,t){let n;if(this.extensionsUsed[x])return;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];T[r]&&T[r].includes(n)&&(this.extensionsUsed[x]=!0,this.extensionsRequired[x]=!0)}processCamera(e){let t=this.json;t.cameras||(t.cameras=[]);let n=e.isOrthographicCamera,r={type:n?"orthographic":"perspective"};return n?r.orthographic={xmag:2*e.right,ymag:2*e.top,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:d.M8C.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,r=this.nodeMap;n.animations||(n.animations=[]),e=R.Utils.mergeMorphTargetTracks(e.clone(),t);let i=e.tracks,o=[],s=[];for(let e=0;e0){let t=[];for(let r=0,i=e.children.length;r0&&(i.children=t)}this._invokeAll(function(t){t.writeNode&&t.writeNode(e,i)});let o=t.nodes.push(i)-1;return r.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 d.xsS;t.name="AuxScene";for(let n=0;n0&&this.processObjects(n);for(let e=0;e0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),void 0!==e.decay&&2!==e.decay&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||0!==e.target.position.x||0!==e.target.position.y||-1!==e.target.position.z)&&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 s=r.extensions[this.name].lights;s.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:s.length-1}}}class L{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}writeMaterial(e,t){if(!e.isMeshBasicMaterial)return;let n=this.writer,r=n.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},r[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}}class B{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.clearcoat)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};n.applyTextureTransform(t,e.clearcoatNormalMap),i.clearcoatNormalTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class H{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.iridescence)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}}class F{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)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}}class U{constructor(e){this.writer=e,this.name="KHR_materials_volume"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)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}i.attenuationDistance=e.attenuationDistance,i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class D{constructor(e){this.writer=e,this.name="KHR_materials_ior"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1.5===e.ior)return;let n=this.writer,r=n.extensionsUsed,i={};i.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class G{constructor(e){this.writer=e,this.name="KHR_materials_specular"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1===e.specularIntensity&&e.specularColor.equals(P)&&!e.specularIntensityMap&&!e.specularColorTexture)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}}class z{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.sheen)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}}class K{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.anisotropy)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}}class V{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}writeMaterial(e,t){if(!e.isMeshStandardMaterial||1===e.emissiveIntensity)return;let n=this.writer,r=n.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}function X(e,t){if(t===d.WwZ)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t!==d.z$h&&t!==d.UlW)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e;{let n=e.getIndex();if(null===n){let t=[],r=e.getAttribute("position");if(void 0===r)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;eMath.abs(e.times[0]-t))return 0;i[0]=t,i.set(e.times,1),o.set(s.evaluate(t),0),o.set(e.values,r),n=0}else if(t>e.times[e.times.length-1]){if(.001>Math.abs(e.times[e.times.length-1]-t))return e.times.length-1;i[i.length-1]=t,i.set(e.times,0),o.set(e.values,0),o.set(s.evaluate(t),e.values.length),n=i.length-1}else for(let a=0;aMath.abs(e.times[a]-t))return a;if(e.times[a]t){i.set(e.times.slice(0,a+1),0),i[a+1]=t,i.set(e.times.slice(a+1),a+2),o.set(e.values.slice(0,(a+1)*r),0),o.set(s.evaluate(t),(a+1)*r),o.set(e.values.slice((a+1)*r),(a+2)*r),n=a+1;break}}return e.times=i,e.values=o,n},mergeMorphTargetTracks:function(e,t){let n=[],r={},i=e.tracks;for(let e=0;e=2.0 are supported."));return}let l=new eN(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});l.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e=0&&void 0===s[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}l.setExtensions(o),l.setPlugins(s),l.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}}function Y(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}let J={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class Z{constructor(e){this.parser=e,this.name=J.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n=0))return null;throw Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures")}return t.loadTextureImage(e,i.source,o)}}class el{constructor(e){this.parser=e,this.name=J.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let o=i.extensions[t],s=r.images[o.source],a=n.textureLoader;if(s.uri){let e=n.options.manager.getHandler(s.uri);null!==e&&(a=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){let t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class ec{constructor(e){this.parser=e,this.name=J.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let o=i.extensions[t],s=r.images[o.source],a=n.textureLoader;if(s.uri){let e=n.options.manager.getHandler(s.uri);null!==e&&(a=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){let t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class eu{constructor(e){this.name=J.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(!n.extensions||!n.extensions[this.name])return null;{let e=n.extensions[this.name],r=this.parser.getDependency("buffer",e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(!(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0))return null;throw Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files")}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,o=e.count,s=e.byteStride,a=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(o,s,a,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(o*s);return i.decodeGltfBuffer(new Uint8Array(t),o,s,a,e.mode,e.filter),t})})}}}class eh{constructor(e){this.name=J.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||void 0===n.mesh)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==ek.TRIANGLES&&e.mode!==ek.TRIANGLE_STRIP&&e.mode!==ek.TRIANGLE_FAN&&void 0!==e.mode)return null;let i=n.extensions[this.name],o=i.attributes,s=[],a={};for(let e in o)s.push(this.parser.getDependency("accessor",o[e]).then(t=>(a[e]=t,a[e])));return s.length<1?null:(s.push(this.parser.createNodeMesh(e)),Promise.all(s).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new d.yGw,n=new d.Pa4,o=new d._fP,s=new d.Pa4(1,1,1),l=new d.SPe(e.geometry,e.material,r);for(let e=0;e-1)?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),"undefined"==typeof createImageBitmap||n||r&&i<98?this.textureLoader=new d.dpR(this.options.manager):this.textureLoader=new d.QRU(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new d.hH6(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(t){let o={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return eM(i,o,r),e_(o,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(o)})).then(function(){e(o)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n{let n=this.associations.get(e);for(let[r,o]of(null!=n&&this.associations.set(t,n),e.children.entries()))i(o,t.children[r])};return i(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n=2&&o.setY(t,h[e*a+1]),a>=3&&o.setZ(t,h[e*a+2]),a>=4&&o.setW(t,h[e*a+3]),a>=5)throw Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return o})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e],i=r.source,o=t.images[i],s=this.textureLoader;if(o.uri){let e=n.manager.getHandler(o.uri);null!==e&&(s=e)}return this.loadTextureImage(e,i,s)}loadTextureImage(e,t,n){let r=this,i=this.json,o=i.textures[e],s=i.images[t],a=(s.uri||s.bufferView)+":"+o.sampler;if(this.textureCache[a])return this.textureCache[a];let l=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=o.name||s.name||"",""===t.name&&"string"==typeof s.uri&&!1===s.uri.startsWith("data:image/")&&(t.name=s.uri);let n=i.samplers||{},a=n[o.sampler]||{};return t.magFilter=eR[a.magFilter]||d.wem,t.minFilter=eR[a.minFilter]||d.D1R,t.wrapS=eA[a.wrapS]||d.rpg,t.wrapT=eA[a.wrapT]||d.rpg,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[a]=l,l}loadImageSource(e,t){let n=this.json,r=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());let i=n.images[e],o=self.URL||self.webkitURL,s=i.uri||"",a=!1;if(void 0!==i.bufferView)s=this.getDependency("bufferView",i.bufferView).then(function(e){a=!0;let t=new Blob([e],{type:i.mimeType});return s=o.createObjectURL(t)});else if(void 0===i.uri)throw Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");let l=Promise.resolve(s).then(function(e){return new Promise(function(n,i){let o=n;!0===t.isImageBitmapLoader&&(o=function(e){let t=new d.xEZ(e);t.needsUpdate=!0,n(t)}),t.load(d.Zp0.resolveURL(e,r.path),o,void 0,i)})}).then(function(e){var t;return!0===a&&o.revokeObjectURL(s),e.userData.mimeType=i.mimeType||((t=i.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){let i=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(void 0!==n.texCoord&&n.texCoord>0&&((o=o.clone()).channel=n.texCoord),i.extensions[J.KHR_TEXTURE_TRANSFORM]){let e=void 0!==n.extensions?n.extensions[J.KHR_TEXTURE_TRANSFORM]:void 0;if(e){let t=i.associations.get(o);o=i.extensions[J.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),i.associations.set(o,t)}}return void 0!==r&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=void 0===t.attributes.tangent,i=void 0!==t.attributes.color,o=void 0===t.attributes.normal;if(e.isPoints){let e="PointsMaterial:"+n.uuid,t=this.cache.get(e);t||(t=new d.UY4,d.F5T.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e="LineBasicMaterial:"+n.uuid,t=this.cache.get(e);t||(t=new d.nls,d.F5T.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||o){let e="ClonedMaterial:"+n.uuid+":";r&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),o&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return d.Wid}loadMaterial(e){let t;let n=this,r=this.json,i=this.extensions,o=r.materials[e],s={},a=o.extensions||{},l=[];if(a[J.KHR_MATERIALS_UNLIT]){let e=i[J.KHR_MATERIALS_UNLIT];t=e.getMaterialType(),l.push(e.extendParams(s,o,n))}else{let r=o.pbrMetallicRoughness||{};if(s.color=new d.Ilk(1,1,1),s.opacity=1,Array.isArray(r.baseColorFactor)){let e=r.baseColorFactor;s.color.setRGB(e[0],e[1],e[2],d.GUF),s.opacity=e[3]}void 0!==r.baseColorTexture&&l.push(n.assignTexture(s,"map",r.baseColorTexture,d.KI_)),s.metalness=void 0!==r.metallicFactor?r.metallicFactor:1,s.roughness=void 0!==r.roughnessFactor?r.roughnessFactor:1,void 0!==r.metallicRoughnessTexture&&(l.push(n.assignTexture(s,"metalnessMap",r.metallicRoughnessTexture)),l.push(n.assignTexture(s,"roughnessMap",r.metallicRoughnessTexture))),t=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,s)})))}!0===o.doubleSided&&(s.side=d.ehD);let c=o.alphaMode||eO.OPAQUE;if(c===eO.BLEND?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,c===eO.MASK&&(s.alphaTest=void 0!==o.alphaCutoff?o.alphaCutoff:.5)),void 0!==o.normalTexture&&t!==d.vBJ&&(l.push(n.assignTexture(s,"normalMap",o.normalTexture)),s.normalScale=new d.FM8(1,1),void 0!==o.normalTexture.scale)){let e=o.normalTexture.scale;s.normalScale.set(e,e)}if(void 0!==o.occlusionTexture&&t!==d.vBJ&&(l.push(n.assignTexture(s,"aoMap",o.occlusionTexture)),void 0!==o.occlusionTexture.strength&&(s.aoMapIntensity=o.occlusionTexture.strength)),void 0!==o.emissiveFactor&&t!==d.vBJ){let e=o.emissiveFactor;s.emissive=new d.Ilk().setRGB(e[0],e[1],e[2],d.GUF)}return void 0!==o.emissiveTexture&&t!==d.vBJ&&l.push(n.assignTexture(s,"emissiveMap",o.emissiveTexture,d.KI_)),Promise.all(l).then(function(){let r=new t(s);return o.name&&(r.name=o.name),e_(r,o),n.associations.set(r,{materials:e}),o.extensions&&eM(i,r,o),r})}createUniqueName(e){let t=d.iUV.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache,i=[];for(let o=0,s=e.length;o0&&function(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let n=0,r=t.weights.length;n1?new d.ZAu:1===t.length?t[0]:new d.Tme)!==t[0])for(let e=0,n=t.length;e{let t=new Map;for(let[e,n]of r.associations)(e instanceof d.F5T||e instanceof d.xEZ)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);null!=n&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let o;let s=[],a=e.name?e.name:e.uuid,l=[];switch(eS[i.path]===eS.weights?e.traverse(function(e){e.morphTargetInfluences&&l.push(e.name?e.name:e.uuid)}):l.push(a),eS[i.path]){case eS.weights:o=d.dUE;break;case eS.rotation:o=d.iLg;break;case eS.position:case eS.scale:o=d.yC1;break;default:o=1===n.itemSize?d.dUE:d.yC1}let c=void 0!==r.interpolation?eP[r.interpolation]:d.NMF,u=this._getArrayFromAccessor(n);for(let e=0,n=l.length;e3&&void 0!==arguments[3]?arguments[3]:function(){};new W().load(e,function(e){e.scene.scale.set(y.R/.5,y.R/.5,y.R/.5),e.scene.matrixAutoUpdate=!1,e.scene.visible=n,e.scene.updateMatrix(),t.add(e.scene),r()},function(e){return console.log(e.loaded+" bytes loaded")},eB)}var eF=n("./src/view/tablegeometry.ts");function eU(e,t){for(var n=0;nthis.radius-y.R){var r=this.pos.clone().sub(e.pos).normalize().setZ(0);n>-y.R/2&&e.vel.addScaledVector(r,7*y.R*t*y.g),0>e.vel.dot(r)&&(e.ballmesh.trace.forceTrace(e.pos),e.vel.x=r.x*e.vel.length()/2,e.vel.y=r.y*e.vel.length()/2)}var i=this.restingDepth(e);n2&&void 0!==arguments[2]?arguments[2]:this.cloth;this.cylinder(e.pos,e.radius,.75*y.R/.5,t,n).position.setZ(-(.25*y.R)/.5/2)}},{key:"cylinder",value:function(e,t,n,r,i){var o=new d.fHI(t,t,n,16),s=new d.Kj0(o,i);return s.position.copy(e),s.geometry.applyMatrix4(new d.yGw().identity().makeRotationAxis(new d.Pa4(1,0,0),Math.PI/2)),r.add(s),s}},{key:"addCushions",value:function(e,t){var n=10*y.R/.5;this.plane(new d.Pa4(0,0,-y.R-n/2),2*eF.H.X,2*eF.H.Y,n,e,this.cloth);var r=1*y.R/.5,i=.75*y.R/.5,o=-(.25*y.R)/.5/2,s=eF.H.X,a=eF.H.Y,l=Math.abs(eZ.pockets.pocketNW.knuckleNE.pos.x-eZ.pockets.pocketN.knuckleNW.pos.x),c=Math.abs(eZ.pockets.pocketNW.knuckleSW.pos.y-eZ.pockets.pocketSW.knuckleNW.pos.y);t||(l=2*eF.H.Y,c=2*eF.H.Y+4*y.R),this.plane(new d.Pa4(s+r/2,0,o),r,c,i,e),this.plane(new d.Pa4(-s-r/2,0,o),r,c,i,e),this.plane(new d.Pa4(-s/2,a+r/2,o),l,r,i,e),this.plane(new d.Pa4(-s/2,-a-r/2,o),l,r,i,e),this.plane(new d.Pa4(s/2,a+r/2,o),l,r,i,e),this.plane(new d.Pa4(s/2,-a-r/2,o),l,r,i,e)}},{key:"plane",value:function(e,t,n,r,i){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:this.cushion,s=new d.DvJ(t,n,r),a=new d.Kj0(s,o);a.receiveShadow=!0,a.position.copy(e),i.add(a)}}],eq(n.prototype,e),t&&eq(n,t),n}(),e0=n("./src/events/watchevent.ts");function e1(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}!function(e){e.Pot="Pot",e.Cushion="Cushion",e.Collision="Collision",e.Hit="Hit"}(a||(a={}));var e2=function(){var e;function t(e,n,r,i){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),e1(this,"type",void 0),e1(this,"timestamp",void 0),e1(this,"ballA",null),e1(this,"ballB",null),e1(this,"incidentSpeed",void 0),this.type=e,this.ballA=n,this.ballB=r,this.incidentSpeed=i,this.timestamp=Date.now()}return e=[{key:"pot",value:function(e,n){return new t("Pot",e,e,n)}},{key:"cushion",value:function(e,n){return new t("Cushion",e,e,n)}},{key:"collision",value:function(e,n,r){return new t("Collision",e,n,r)}},{key:"hit",value:function(e,n){return new t("Hit",e,e,n)}},{key:"isCueBallPotted",value:function(e,t){return t.some(function(t){return"Pot"==t.type&&t.ballA===e})}},{key:"isBallPottedNoFoul",value:function(e,n){return n.some(function(e){return"Pot"==e.type&&null!==e.ballA})&&!t.isCueBallPotted(e,n)}},{key:"pots",value:function(e){return e.filter(function(e){return"Pot"==e.type}).map(function(e){return e.ballA})}},{key:"potCount",value:function(e){return this.pots(e).length}},{key:"onlyRedsPotted",value:function(e){return this.pots(e).every(function(e){return e.id>6})}},{key:"isThreeCushionPoint",value:function(e,n){n=t.cueBallFirst(e,n).filter(function(t){return t.ballA===e});var r=new Set,i=0,o=!0,s=!1,a=void 0;try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var u=l.value;if("Cushion"===u.type&&i++,"Collision"===u.type&&(r.add(u.ballB),2===r.size))return i>=3}}catch(e){s=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(s)throw a}}return!1}},{key:"cueBallFirst",value:function(e,t){return t.forEach(function(t){"Collision"===t.type&&t.ballB===e&&(t.ballB=t.ballA,t.ballA=e)}),t}}],function(e,t){for(var n=0;n-eF.H.tableX&&n.overlapsAny(r,t);)r.x-=y.R/8;t.pos.copy(r),t.state=eV.Z.Stationary}}],function(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1500;if(!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),tb(tm(r=i.call(this,e)),"delay",void 0),tb(tm(r),"shots",void 0),tb(tm(r),"firstShot",void 0),tb(tm(r),"timer",void 0),tb(tm(r),"init",void 0),r.init=t,r.shots=tk(n),r.firstShot=r.shots[0],r.delay=a,r.container.table.showTraces(!0),r.container.table.updateFromShortSerialised(r.init),s){var l=new tp.l(t,n);l.retry=!0,r.container.eventQueue.push(l)}else r.container.view.camera.forceMode(r.container.view.camera.topView),r.playNextShot(1.5*r.delay);return r}return n=[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===c.t.RERACK){td.K.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var r=e5.f.fromJson(n);this.container.table.cueball=this.container.table.balls[r.i],this.container.table.cueball.pos.copy(r.pos),this.container.table.cue.aim=r,this.container.table.cue.updateAimInput(),this.container.table.cue.t=1,clearTimeout(this.timer),this.timer=setTimeout(function(){t.container.eventQueue.push(new e8.O(t.container.table.cue.aim)),t.timer=void 0},e)}},{key:"handleHit",value:function(e){return this.hit(),this}},{key:"handleStationary",value:function(e){return this.shots.length>0&&void 0===this.timer&&this.playNextShot(this.delay),this}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}},{key:"handleBreak",value:function(e){return(this.container.table.updateFromShortSerialised(e.init),this.shots=tk(e.shots),this.container.table.showSpin(!0),e.retry)?this.retry():(this.playNextShot(this.delay),this)}},{key:"retry",value:function(){clearTimeout(this.timer),this.timer=void 0,this.container.table.updateFromShortSerialised(this.init);var e=e5.f.fromJson(this.firstShot);return this.container.table.cueball=this.container.table.balls[e.i],this.container.rules.cueball=this.container.table.cueball,this.container.table.cueball.pos.copy(e.pos),this.container.table.cue.aim=e,this.container.view.camera.forceMode(this.container.view.camera.aimView),new tE(this.container)}}],ty(o.prototype,n),r&&ty(o,r),o}(tl);function tR(e,t){for(var n=0;n2)||void 0===arguments[2]||arguments[2],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:tG.h_,o=e.futurePosition(n);if(t.willBounceLong(o,r)){var s=o.y>eF.H.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(s,e,i)}if(t.willBounceShort(o,r)){var a=o.x>eF.H.tableX?0:Math.PI;return t.bounceIn(a,e,i)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(eZ.pockets.pocketNW.knuckleSW.pos.y,eZ.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(eF.H.Y,-eF.H.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(eZ.pockets.pocketNW.knuckleNE.pos.x,eZ.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(eZ.pockets.pocketN.knuckleNE.pos.x,eZ.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-eF.H.X,eF.H.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xeF.H.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yeF.H.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,tG.ZI)(e,t.vel,t.rvel,n);return t.vel.add(r.v),t.rvel.add(r.w),r.v.length()}}],function(e,t){for(var n=0;n100)throw Error("Depth exceeded resolving collisions");this.balls.forEach(function(t){t.update(e)})}},{key:"prepareAdvanceAll",value:function(e){var t=this;return this.pairs.every(function(n){return t.prepareAdvancePair(n.a,n.b,e)})&&this.balls.every(function(n){return t.prepareAdvanceToCushions(n,e)})}},{key:"prepareAdvancePair",value:function(e,t,n){if(tK.willCollide(e,t,n)){var r=tK.collide(e,t);return this.outcome.push(e2.collision(e,t,r)),!1}return!0}},{key:"prepareAdvanceToCushions",value:function(e,t){if(!e.onTable())return!0;var n=e.futurePosition(t);if(Math.abs(n.y)1&&void 0!==arguments[1]?arguments[1]:this.cueball;return this.balls.filter(function(e){return e!==t}).some(function(t){return t.pos.distanceTo(e)<2*y.R})}}],t=[{key:"fromSerialised",value:function(e){var t=new n(e.balls.map(function(e){return eV.e.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&tX(n.prototype,e),t&&tX(n,t),n}();function tJ(e,t){for(var n=0;n0){if(this.previousPotRed)this.previousPotRed=!1,this.respot(e);else if(e2.onlyRedsPotted(e))this.previousPotRed=!0;else if(1===t){var n=e2.pots(e)[0].id;n>1&&this.container.table.balls.filter(function(e){return e.id0}).some(function(e){return e.onTable()})&&this.respot(e)}else this.respot(e)}return t1(t2(o.prototype),"update",this).call(this,e)}},{key:"respot",value:function(e){var t=this.respotAllPottedColours(e);if(t.length>0){var n={balls:t.map(function(e){return e.serialise()}),rerack:!0},r=new e0.g(n);this.container.sendEvent(r),this.container.recoder.record(r)}}},{key:"respotAllPottedColours",value:function(e){var t=this;return e2.pots(e).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(e){return e3.respot(e,t.container.table)})}}],t$(o.prototype,n),r&&t$(o,r),o}(tq);function t5(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],no(n.prototype,e),t&&no(n,t),n}();function nl(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:0;if(this.loadAssets){var r,i,o=d.Hmr.getContext();if((null==o?void 0:o.state)==="suspended"){(null===(i=navigator)||void 0===i?void 0:null===(r=i.userActivation)||void 0===r?void 0:r.hasBeenActive)&&o.resume();return}e.setVolume(t),e.isPlaying&&e.stop(),e.play(d.M8C.randFloat(0,.01)),e.setDetune(n)}}},{key:"outcomeToSound",value:function(e){"Collision"===e.type&&this.play(this.ballcollision,e.incidentSpeed/80,5*e.incidentSpeed),"Pot"===e.type&&this.play(this.pot,e.incidentSpeed/10,-1e3+10*e.incidentSpeed),"Cushion"===e.type&&this.play(this.cushion,e.incidentSpeed/70),"Hit"===e.type&&this.play(this.cue,e.incidentSpeed/30)}},{key:"processOutcomes",value:function(e){var t=this;e.every(function(e){return!(e.timestamp>t.lastOutcomeTime)||(t.lastOutcomeTime=e.timestamp,t.outcomeToSound(e),!1)})}},{key:"playNotify",value:function(){this.play(this.pot,1)}},{key:"playSuccess",value:function(e){this.play(this.success,.1,100*e-2200)}}],nl(n.prototype,e),t&&nl(n,t),n}();function nh(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function nf(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==c.t.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}],nv(n.prototype,e),t&&nv(n,t),n}(),nb=n("./src/view/sliders.ts"),ng=n("./node_modules/jsoncrush/JSONCrush.js");function nw(e,t){for(var n=0;n0&&"RERACK"===this.shots[e].type&&e--,e}},{key:"lastShot",value:function(){var e=this.last();return this.state(this.states[e],[this.shots[e]])}},{key:"currentBreak",value:function(){if(void 0!==this.breakStart)return this.state(this.states[this.breakStart],this.shots.slice(this.breakStart))}},{key:"state",value:function(e,t){return{init:e,shots:t}}},{key:"updateBreak",value:function(e){var t=this.container.rules.isPartOfBreak(e),n=this.container.rules.isEndOfGame(e),r=e2.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r),n&&this.breakLink(n),!t){this.breakStart=void 0;return}void 0===this.breakStart&&(this.breakStart=this.last())}},{key:"lastShotLink",value:function(e,t){var n="⚈".repeat(t>1?t-1:0)+(e?"⚈":"⚆"),r=JSON.stringify(this.lastShot());this.generateLink(n,r)}},{key:"breakLink",value:function(e){var t=this.currentBreak();if(t&&(e||t.shots.pop(),1!==t.shots.length)){var n="break(".concat(t.shots.length,")"),r=JSON.stringify(t),i=ng.Z.crush(r);this.generateLink(n,i)}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(e.shots.length,")"),n=JSON.stringify(e),r=ng.Z.crush(n);this.generateLink(t,r)}},{key:"generateLink",value:function(e,t){var n="".concat(this.replayUrl).concat(encodeURIComponent(t)),r='').concat(e,"");this.container.eventQueue.push(new tU.s(null,"".concat(r)))}}],nw(n.prototype,e),t&&nw(n,t),n}();function nR(e,t){for(var n=0;n').concat(e,"")));r.push(new tU.s(null,s))})},this.redo.onclick=function(e){var r=new tp.l(t.init,t.shots);r.retry=!0,n.interuptEventQueue(r)},this.replay.onclick=function(e){n.interuptEventQueue(t)}}},{key:"interuptEventQueue",value:function(e){this.container.table.halt();var t=this.container.eventQueue;t.length=0,t.push(new p),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],nI(n.prototype,e),t&&nI(n,t),n}();function nN(e,t){for(var n=0;n2)||void 0===arguments[2]||arguments[2],i=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,s=arguments.length>5?arguments[5]:void 0,a=arguments.length>6?arguments[6]:void 0,l=this;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,n),nL(this,"table",void 0),nL(this,"view",void 0),nL(this,"controller",void 0),nL(this,"inputQueue",[]),nL(this,"eventQueue",[]),nL(this,"keyboard",void 0),nL(this,"sound",void 0),nL(this,"chat",void 0),nL(this,"sliders",void 0),nL(this,"recoder",void 0),nL(this,"id",""),nL(this,"isSinglePlayer",!0),nL(this,"rules",void 0),nL(this,"menu",void 0),nL(this,"last",performance.now()),nL(this,"step",.001953125),nL(this,"broadcast",void 0),nL(this,"log",void 0),nL(this,"sendChat",function(e){l.sendEvent(new tU.s(l.id,e))}),nL(this,"throttle",new ny(200,function(e){l.broadcast(e)})),nL(this,"lastEventTime",performance.now()),this.log=t,this.rules=n_.create(i,this),this.table=this.rules.table(),this.view=new t6(e,s,this.table,r,this.rules.asset()),this.table.cue.aimInputs=new na(this),this.keyboard=o,this.sound=new nu(this.view.camera.camera,r),this.chat=new nd(this.sendChat),this.sliders=new nb.E,this.recoder=new nT(this),this.id=a,this.menu=new nC(this),this.table.addToScene(this.view.scene),this.updateController(new nt(this))}return e=[{key:"sendEvent",value:function(e){this.throttle.send(e)}},{key:"advance",value:function(e){for(var t=Math.floor(e/this.step),n=t*this.step,r=this.table.allStationary(),i=0;i0;){this.lastEventTime=this.last;var t=this.inputQueue.shift();t&&this.updateController(this.controller.handleInput(t))}if(this.table.allStationary()){var n=this.eventQueue.shift();n&&(this.lastEventTime=performance.now(),this.updateController(n.applyToController(this.controller)))}}},{key:"animate",value:function(e){var t=this;this.advance((e-this.last)/1e3),this.last=e,this.processEvents(),(e{n.d(t,{Y:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{f:()=>f});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts"),s=n("./node_modules/three/build/three.module.js");function a(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){for(var n=0;n{n.d(t,{Z:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{l:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{s:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r;n.d(t,{t:()=>r}),function(e){e.BEGIN="BEGIN",e.BREAK="BREAK",e.WATCHAIM="WATCHAIM",e.AIM="AIM",e.HIT="HIT",e.STATIONARY="STATIONARY",e.CHAT="CHAT",e.ABORT="ABORT",e.PLACEBALL="PLACEBALL",e.REJOIN="REJOIN",e.RERACK="RERACK"}(r||(r={}))},"./src/events/gameevent.ts":(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{Z:()=>i});var i=function e(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"type",void 0),r(this,"sequence",void 0)}},"./src/events/hitevent.ts":(e,t,n)=>{n.d(t,{O:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{I:()=>i});var i=function e(t,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"t",void 0),r(this,"key",void 0),this.t=t,this.key=n}},"./src/events/keyboard.ts":(e,t,n)=>{n.d(t,{N:()=>l});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t){for(var n=0;n3*Math.abs(i)){var s,a=null!==(s=t.released.movementY)&&void 0!==s?s:0;t.released.movementY=a+o;return}var l=null!==(n=t.released.movementX)&&void 0!==n?n:0;t.released.movementX=l+i}),this.addHandlers(e),/Android|iPhone/i.test(navigator.userAgent)||(e.contentEditable="true")}return e=[{key:"getEvents",value:function(){var e=this,t=Object.keys(this.pressed).filter(function(e){return!/Shift/.test(e)}).filter(function(e){return!/Control/.test(e)}),n=Object.keys(this.pressed).some(function(e){return/Shift/.test(e)}),i=Object.keys(this.pressed).some(function(e){return/Control/.test(e)}),o=[];return t.forEach(function(t){var s=performance.now()-e.pressed[t];o.push(new r.I(i?s/3:s,n?"Shift"+t:t)),"Space"!=t&&(e.pressed[t]=performance.now())}),Object.keys(this.released).forEach(function(t){return o.push(new r.I(e.released[t],t+"Up"))}),this.released={},o}},{key:"addHandlers",value:function(e){var t=this;e.addEventListener("keydown",this.keydown),e.addEventListener("keyup",this.keyup),e.focus(),o()(e).draggable({listeners:{move:function(e){t.mousetouch(e)}}})}}],s(n.prototype,e),t&&s(n,t),n}()},"./src/events/placeballevent.ts":(e,t,n)=>{n.d(t,{I:()=>h});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts");function s(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){for(var n=0;n{n.d(t,{K:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{g:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r=n("./src/container/container.ts"),i=n("./src/events/keyboard.ts"),o=n("./src/events/eventtype.ts"),s=n("./src/events/aimevent.ts"),a=n("./src/events/watchevent.ts"),l=n("./src/events/hitevent.ts"),c=n("./src/events/abortevent.ts"),u=n("./src/events/breakevent.ts"),h=n("./src/events/beginevent.ts"),f=n("./src/events/chatevent.ts");function p(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),v(p(e=i.call(this)),"clientResendFrom",void 0),v(p(e),"serverResendFrom",void 0),e.type=o.t.REJOIN,e.clientResendFrom=t,e.serverResendFrom=n,e}return n=[{key:"applyToController",value:function(e){return e.handleRejoin(this)}}],r=[{key:"fromJson",value:function(e){return new s(e.clientResendFrom,e.serverResendFrom)}}],n&&d(s.prototype,n),r&&d(s,r),s}(n("./src/events/gameevent.ts").Z),g=n("./src/events/placeballevent.ts"),w=n("./src/events/rerackevent.ts"),k=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"serialise",value:function(e){return JSON.stringify(e)}},{key:"fromJson",value:function(e){switch(e.type){case o.t.BEGIN:return new h.Z;case o.t.AIM:return s.f.fromJson(e);case o.t.BREAK:return u.l.fromJson(e);case o.t.WATCHAIM:return a.g.fromJson(e.json);case o.t.HIT:return l.O.fromJson(e);case o.t.CHAT:return f.s.fromJson(e);case o.t.REJOIN:return b.fromJson(e);case o.t.ABORT:return new c.Y;case o.t.PLACEBALL:return g.I.fromJson(e);case o.t.RERACK:return w.K.fromJson(e);default:throw Error("Unknown GameEvent :"+e)}}},{key:"fromSerialised",value:function(e){var n=JSON.parse(e),r=t.fromJson(n);return"sequence"in n&&(r.sequence=n.sequence),r}}],function(e,t){for(var n=0;n{n.d(t,{e:()=>m,Z:()=>r});var r,i=n("./src/utils/utils.ts"),o=n("./src/model/physics/physics.ts"),s=n("./node_modules/three/build/three.module.js"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;nMath.PI/32?.01*a.R:a.R,i=this.lastPos.distanceTo(e);this.addTraceGiven(e,t,i,r,n)}}},{key:"addTraceGiven",value:function(e,t,n,r,i){var o=this.geometry.drawRange.count;0!==o&&n1&&i<1e-4&&o--,this.lastPos.copy(e),this.lastVel.copy(t),this.addPoint(e,o))}},{key:"addPoint",value:function(e,t){var n=3*t;n>this.positions.length||(this.positions[n++]=e.x,this.positions[n++]=e.y,this.positions[n]=e.z,this.geometry.setDrawRange(0,t+1),this.line.geometry.attributes.position.needsUpdate=!0)}}],l(n.prototype,e),t&&l(n,t),n}();function h(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.bM),this.rvel.copy(i.bM),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.E9)(this.vel,this.rvel).length(){n.d(t,{Dt:()=>c,Ew:()=>v,G3:()=>w,Hz:()=>i,I:()=>o,Mz:()=>r,R:()=>f,Xm:()=>k,_5:()=>u,dE:()=>y,e:()=>p,f7:()=>g,fN:()=>m,g:()=>s,m:()=>h,mu:()=>a,zq:()=>b,zv:()=>l});var r,i,o,s=9.8,a=.00985,l=.105,c=.8,u=.024,h=.23,f=.03275,p=.86;function d(){r=a*h*s*2/3*u,i=7/(5*Math.sqrt(2))*f*a*h*s,o=.4*h*f*f}function v(e){f=e,d()}function m(e){h=e,d()}function y(e){a=e,d()}function b(e){u=e,d()}function g(e){l=e}function w(e){p=e}function k(e){c=e}d()},"./src/model/physics/physics.ts":(e,t,n)=>{n.d(t,{E9:()=>a,Fn:()=>A,IT:()=>h,NP:()=>g,QC:()=>u,Vp:()=>c,WL:()=>S,ZI:()=>f,al:()=>b,c0:()=>y,h_:()=>x,s0:()=>m,vZ:()=>w});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/utils/utils.ts"),o=n("./src/model/physics/constants.ts"),s=new r.Pa4;function a(e,t){return s.copy(e).addScaledVector((0,i.a1)(t),o.R)}var l={v:new r.Pa4,w:new r.Pa4};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.KO)(n).multiplyScalar(-o.zv*o.g)),l.w.copy((0,i.KO)((0,i.a1)(n)).multiplyScalar(2.5*o.zv*o.g/o.R)),l.w.setZ(-2.5*(o.Mz/(o.R*o.R))*Math.sign(t.z)),l}function u(e){var t=new r.Pa4(e.x,e.y,0).length(),n=5/7*o.Hz/(o.m*o.R)/t,i=5/7*o.Hz/(o.m*o.R*o.R)/t;return l.v.set(-n*e.y,n*e.x,0),l.w.set(-i*e.x,-i*e.y,-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(e.z)),l}function h(e,t){var n=t.z;t.copy((0,i.a1)(e).multiplyScalar(1/o.R)),t.setZ(n)}function f(e,t,n,r){var o=r(t.clone().applyAxisAngle(i.up,e),n.clone().applyAxisAngle(i.up,e));return o.v.applyAxisAngle(i.up,-e),o.w.applyAxisAngle(i.up,-e),o}Object.freeze(l);var p=Math.asin(.1*o.R/o.R),d=Math.sin(p),v=Math.cos(p);function m(e,t){return new r.Pa4(e.x*d-e.z*v+o.R*t.y,-e.y-o.R*t.z*v+o.R*t.x*d)}function y(e){return e.x*v}function b(e){var t=3.5/o.m;return e.length()/t}function g(e){var t,n=1/o.m,i=.39+.257*(t=new r.Pa4(e/v,0,0)).x-.044*t.x*t.x;return o.Dt*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(m(e,t))<=n}function k(e,t){return{c:y(e),s:m(e,t),A:3.5/o.m,B:1/o.m}}function T(e,t){var n=k(e,t),r=n.c,i=n.s,s=n.A,a=n.B,l=(1+o.e)*(r/a);return E(-i.x/s*d-l*v,i.y/s,i.x/s*v-l*d)}function R(e,t){var n=k(e,t),r=n.c,i=n.B,s=(1+o.e)*(r/i),a=.471-.241*Math.atan2(Math.abs(e.y),e.x),l=Math.atan2(e.y,e.x),c=Math.cos(l),u=-a*s*c*v-s*v,h=a*s*c*v-s*d;return E(u,a*s*Math.sin(l),h)}function A(e,t){return w(e,t)?T(e,t):R(e,t)}function x(e,t){var n=T(e,t),r=R(e,t),i=Math.sign(e.y)===Math.sign(t.z)?Math.cos(Math.atan2(e.y,e.x)):1;return{v:r.v.lerp(n.v,i),w:r.w.lerp(n.w,i)}}function E(e,t,n){return{v:new r.Pa4(e/o.m,t/o.m),w:new r.Pa4(-o.R/o.I*t*d,o.R/o.I*(e*d-n*v),o.R/o.I*t*v)}}function S(e,t){var n=Math.atan2(-e.x,e.y),r=2.5*t.length()*(e.length()*o.R)/(o.R*o.R),s=t.clone().normalize();return(0,i.a1)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/utils/utils.ts":(e,t,n)=>{n.d(t,{$2:()=>y,AA:()=>p,Bh:()=>s,KO:()=>u,Ls:()=>f,NM:()=>d,Xp:()=>v,a1:()=>l,bM:()=>i,up:()=>o,wK:()=>m});var r=n("./node_modules/three/build/three.module.js"),i=new r.Pa4(0,0,0),o=new r.Pa4(0,0,1);function s(e){return new r.Pa4(e.x,e.y,e.z)}var a=new r.Pa4;function l(e){return a.copy(o).cross(e)}var c=new r.Pa4;function u(e){return c.copy(e).normalize()}var h=new r.Pa4;function f(e,t){return 0>=h.copy(e).add(t).dot(e)}function p(e){return new r.Pa4(1,0,0).applyAxisAngle(o,e)}function d(e){return Math.sign(e)*Math.floor((Math.abs(e)+Number.EPSILON)*1e4)/1e4}function v(e){return Math.round((e+Number.EPSILON)*100)/100}function m(e){return e.x=d(e.x),e.y=d(e.y),e.z=d(e.z),e}function y(e){return e.x=v(e.x),e.y=v(e.y),e.z=v(e.z),e}},"./src/view/cameratop.ts":(e,t,n)=>{n.d(t,{c:()=>a});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/view/tablegeometry.ts"),o=n("./src/model/physics/constants.ts");function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"viewPoint",value:function(e,n){var s=t.zoomFactor/(2*Math.tan(n*Math.PI/360));if(e>this.portrait){var a=e>t.aspectLimit?2.75*i.H.tableY:2.4*i.H.tableX/e;return new r.Pa4(0,-.01*o.R,s*a)}var l=e>1/t.aspectLimit?4.9*i.H.tableY:1.35*i.H.tableX/e;return new r.Pa4(-.01*o.R,0,s*l)}}],function(e,t){for(var n=0;n{n.d(t,{N:()=>d});var r=n("./src/view/tablegeometry.ts"),i=n("./src/utils/utils.ts"),o=n("./src/events/aimevent.ts"),s=n("./src/model/ball.ts"),a=n("./src/model/physics/physics.ts"),l=n("./src/model/physics/constants.ts"),c=n("./node_modules/three/build/three.module.js");function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var h=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"createHelper",value:function(){var e=new c.fHI(l.R,l.R,30*l.R/.5,12,1,!0),t=new c.Kj0(e,this.helpermaterial);return t.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(i.up,-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(15*l.R/.5,0,-(.01*l.R)/.5)),t.visible=!1,t.renderOrder=-1,t.material.depthTest=!1,t}},{key:"createPlacer",value:function(){var e=new c.fHI(.01*l.R/.5,l.R,l.R,4),n=new c.Kj0(e,t.helpermaterial);return n.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(new c.Pa4(1,0,0),-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(0,0,.7*l.R/.5)),n.visible=!1,n}},{key:"createCue",value:function(e,n,r){var o=new c.fHI(e,n,r,11),s=new c.Kj0(o,t.material);return s.castShadow=!1,s.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(new c.Pa4(1,0,0),-.1)).applyMatrix4(new c.yGw().identity().makeRotationAxis(i.up,-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(-r/2-l.R,0,2*l.R)),s}}],function(e,t){for(var n=0;nthis.offCenterLimit&&e.normalize().multiplyScalar(this.offCenterLimit),this.aim.offset=(0,i.$2)(e),this.updateAimInput()}},{key:"updateAimInput",value:function(){var e,t;null===(e=this.aimInputs)||void 0===e||e.updateVisualState(this.aim.offset.x,this.aim.offset.y),null===(t=this.aimInputs)||void 0===t||t.updatePowerSlider(this.aim.power/this.maxPower)}},{key:"moveTo",value:function(e){this.aim.pos.copy(e),this.mesh.rotation.z=this.aim.angle,this.helperMesh.rotation.z=this.aim.angle;var t=(0,i.a1)((0,i.AA)(this.aim.angle)).multiplyScalar(2*this.aim.offset.x*l.R).setZ(2*this.aim.offset.y*l.R),n=(Math.sin(this.t+Math.PI/2)-1)*3*l.R*(this.aim.power/this.maxPower),r=(0,i.AA)(this.aim.angle).clone().multiplyScalar(n);this.mesh.position.copy(e.clone().add(t).add(r)),this.helperMesh.position.copy(e),this.placerMesh.position.copy(e),this.placerMesh.rotation.z=this.t}},{key:"update",value:function(e){this.t+=e,this.moveTo(this.aim.pos)}},{key:"placeBallMode",value:function(){this.mesh.visible=!1,this.placerMesh.visible=!0,this.aim.angle=0}},{key:"aimMode",value:function(){this.mesh.visible=!0,this.placerMesh.visible=!1}},{key:"intersectsAnything",value:function(e){var t=e.cueball.pos.clone().addScaledVector((0,i.AA)(this.aim.angle),-this.length/2);t.z=this.aim.offset.y;var n=(0,i.AA)(this.aim.angle);return new c.iMs(t,n,0,this.length/2-.6).intersectObjects(e.balls.map(function(e){return e.ballmesh.mesh})).length>0}},{key:"showHelper",value:function(e){this.helperMesh.visible=e}},{key:"toggleHelper",value:function(){this.showHelper(!this.helperMesh.visible)}}],f(n.prototype,e),t&&f(n,t),n}()},"./src/view/sliders.ts":(e,t,n)=>{n.d(t,{E:()=>s});var r=n("./src/model/physics/constants.ts");function i(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:1,i=this,o=this.getInputElement(e);o.step="0.001",o.min="0.01",o.max="".concat(r),o.value=t,this.showValue(e,t),o.oninput=function(t){var r=parseFloat(t.target.value);n(r),i.showValue(e,r),i.notify()}}},{key:"showValue",value:function(e,t){var n=document.querySelector("label[for=".concat(e,"]"));n&&(n.innerHTML="".concat(e,"=").concat(t))}}],i(n.prototype,e),t&&i(n,t),n}()},"./src/view/tablegeometry.ts":(e,t,n)=>{n.d(t,{H:()=>o});var r=n("./src/model/physics/constants.ts");function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"scaleToRadius",value:function(e){t.tableX=43*e,t.tableY=21*e,t.X=t.tableX+e,t.Y=t.tableY+e}}],function(e,t){for(var n=0;n{e(e.s="./src/index.ts")}]); \ No newline at end of file + }`})),o.uniforms.blitTexture.value=e,o.defines.IS_SRGB=e.colorSpace==d.KI_,o.needsUpdate=!0,s||((s=new d.Kj0(i,o)).frustrumCulled=!1);let a=new d.cPb,l=new d.xsS;l.add(s),n||(n=r=new d.CP7({antialias:!1})),n.setSize(Math.min(e.image.width,t),Math.min(e.image.height,t)),n.clear(),n.render(l,a);let c=new d.xEZ(n.domElement);return c.minFilter=e.minFilter,c.magFilter=e.magFilter,c.wrapS=e.wrapS,c.wrapT=e.wrapT,c.name=e.name,r&&(r.dispose(),r=null),c}let T={POSITION:["byte","byte normalized","unsigned byte","unsigned byte normalized","short","short normalized","unsigned short","unsigned short normalized"],NORMAL:["byte normalized","short normalized"],TANGENT:["byte normalized","short normalized"],TEXCOORD:["byte","byte normalized","unsigned byte","short","short normalized","unsigned short"]};class R{constructor(){this.pluginCallbacks=[],this.register(function(e){return new N(e)}),this.register(function(e){return new L(e)}),this.register(function(e){return new F(e)}),this.register(function(e){return new U(e)}),this.register(function(e){return new D(e)}),this.register(function(e){return new G(e)}),this.register(function(e){return new B(e)}),this.register(function(e){return new H(e)}),this.register(function(e){return new z(e)}),this.register(function(e){return new K(e)}),this.register(function(e){return new V(e)})}register(e){return -1===this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.push(e),this}unregister(e){return -1!==this.pluginCallbacks.indexOf(e)&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i=new C,o=[];for(let e=0,t=this.pluginCallbacks.length;ee.toBlob(n,t)):("image/jpeg"===t?n=.92:"image/webp"===t&&(n=.8),e.convertToBlob({type:t,quality:n}))}class C{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"}},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.buffers,i=this.json;n=this.options;let o=this.extensionsUsed,s=this.extensionsRequired,a=new Blob(r,{type:"application/octet-stream"}),l=Object.keys(o),c=Object.keys(s);if(l.length>0&&(i.extensionsUsed=l),c.length>0&&(i.extensionsRequired=c),i.buffers&&i.buffers.length>0&&(i.buffers[0].byteLength=a.size),!0===n.binary){let e=new FileReader;e.readAsArrayBuffer(a),e.onloadend=function(){var n;let r=_(e.result),o=new DataView(new ArrayBuffer(8));o.setUint32(0,r.byteLength,!0),o.setUint32(4,5130562,!0);let s=_((n=JSON.stringify(i),new TextEncoder().encode(n).buffer),32),a=new DataView(new ArrayBuffer(8));a.setUint32(0,s.byteLength,!0),a.setUint32(4,1313821514,!0);let l=new ArrayBuffer(12),c=new DataView(l);c.setUint32(0,1179937895,!0),c.setUint32(4,2,!0);let u=12+a.byteLength+s.byteLength+o.byteLength+r.byteLength;c.setUint32(8,u,!0);let h=new Blob([l,a,s,o,r],{type:"application/octet-stream"}),f=new FileReader;f.readAsArrayBuffer(h),f.onloadend=function(){t(f.result)}}}else if(i.buffers&&i.buffers.length>0){let e=new FileReader;e.readAsDataURL(a),e.onloadend=function(){let n=e.result;i.buffers[0].uri=n,t(i)}}else t(i)}serializeUserData(e,t){if(0===Object.keys(e.userData).length)return;let n=this.options,r=this.extensionsUsed;try{let i=JSON.parse(JSON.stringify(e.userData));if(n.includeCustomExtensions&&i.gltfExtensions){for(let e in void 0===t.extensions&&(t.extensions={}),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(!1===this.uids.has(e)){let t=new Map;t.set(!0,this.uid++),t.set(!1,this.uid++),this.uids.set(e,t)}let n=this.uids.get(e);return n.get(t)}isNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return!1;let n=new d.Pa4;for(let t=0,r=e.count;t5e-4)return!1;return!0}createNormalizedNormalAttribute(e){let t=this.cache;if(t.attributesNormalized.has(e))return t.attributesNormalized.get(e);let n=e.clone(),r=new d.Pa4;for(let e=0,t=n.count;e4?r=e.array[i*e.itemSize+n]:(0===n?r=e.getX(i):1===n?r=e.getY(i):2===n?r=e.getZ(i):3===n&&(r=e.getW(i)),!0===e.normalized&&(r=d.M8C.normalize(r,e.array))),t===A.FLOAT?l.setFloat32(c,r,!0):t===A.INT?l.setInt32(c,r,!0):t===A.UNSIGNED_INT?l.setUint32(c,r,!0):t===A.SHORT?l.setInt16(c,r,!0):t===A.UNSIGNED_SHORT?l.setUint16(c,r,!0):t===A.BYTE?l.setInt8(c,r):t===A.UNSIGNED_BYTE&&l.setUint8(c,r),c+=o}let u={buffer:this.processBuffer(l.buffer),byteOffset:this.byteOffset,byteLength:a};void 0!==i&&(u.target=i),i===A.ARRAY_BUFFER&&(u.byteStride=e.itemSize*o),this.byteOffset+=a,s.bufferViews.push(u);let h={id:s.bufferViews.length-1,byteLength:0};return h}processBufferViewImage(e){let t=this,n=t.json;return n.bufferViews||(n.bufferViews=[]),new Promise(function(r){let i=new FileReader;i.readAsArrayBuffer(e),i.onloadend=function(){let e=_(i.result),o={buffer:t.processBuffer(e),byteOffset:t.byteOffset,byteLength:e.byteLength};t.byteOffset+=e.byteLength,r(n.bufferViews.push(o)-1)}})}processAccessor(e,t,n,r){let i,o;let s=this.json;if(e.array.constructor===Float32Array)i=A.FLOAT;else if(e.array.constructor===Int32Array)i=A.INT;else if(e.array.constructor===Uint32Array)i=A.UNSIGNED_INT;else if(e.array.constructor===Int16Array)i=A.SHORT;else if(e.array.constructor===Uint16Array)i=A.UNSIGNED_SHORT;else if(e.array.constructor===Int8Array)i=A.BYTE;else if(e.array.constructor===Uint8Array)i=A.UNSIGNED_BYTE;else throw Error("THREE.GLTFExporter: Unsupported bufferAttribute component type: "+e.array.constructor.name);if(void 0===n&&(n=0),void 0===r&&(r=e.count),0===r)return null;let a=function(e,t,n){let r={min:Array(e.itemSize).fill(Number.POSITIVE_INFINITY),max:Array(e.itemSize).fill(Number.NEGATIVE_INFINITY)};for(let i=t;i4?n=e.array[i*e.itemSize+t]:(0===t?n=e.getX(i):1===t?n=e.getY(i):2===t?n=e.getZ(i):3===t&&(n=e.getW(i)),!0===e.normalized&&(n=d.M8C.normalize(n,e.array))),r.min[t]=Math.min(r.min[t],n),r.max[t]=Math.max(r.max[t],n)}return r}(e,n,r);void 0!==t&&(o=e===t.index?A.ELEMENT_ARRAY_BUFFER:A.ARRAY_BUFFER);let l=this.processBufferView(e,i,n,r,o),c={bufferView:l.id,byteOffset:l.byteOffset,componentType:i,count:r,max:a.max,min:a.min,type:{1:"SCALAR",2:"VEC2",3:"VEC3",4:"VEC4",9:"MAT3",16:"MAT4"}[e.itemSize]};return!0===e.normalized&&(c.normalized=!0),s.accessors||(s.accessors=[]),s.accessors.push(c)-1}processImage(e,t,n,r="image/png"){if(null!==e){let i=this,o=i.cache,s=i.json,a=i.options,l=i.pending;o.images.has(e)||o.images.set(e,{});let c=o.images.get(e),u=r+":flipY/"+n.toString();if(void 0!==c[u])return c[u];s.images||(s.images=[]);let h={mimeType:r},f=I();f.width=Math.min(e.width,a.maxTextureSize),f.height=Math.min(e.height,a.maxTextureSize);let p=f.getContext("2d");if(!0===n&&(p.translate(0,f.height),p.scale(1,-1)),void 0!==e.data){t!==d.wk1&&console.error("GLTFExporter: Only RGBAFormat is supported.",t),(e.width>a.maxTextureSize||e.height>a.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=>{h.bufferView=e})):void 0!==f.toDataURL?h.uri=f.toDataURL(r):l.push(j(f,r).then(e=>new FileReader().readAsDataURL(e)).then(e=>{h.uri=e}));let v=s.images.push(h)-1;return c[u]=v,v}throw Error("THREE.GLTFExporter: No valid image data found. Unable to process texture.")}processSampler(e){let t=this.json;t.samplers||(t.samplers=[]);let n={magFilter:E[e.magFilter],minFilter:E[e.minFilter],wrapS:E[e.wrapS],wrapT:E[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);r.textures||(r.textures=[]),e instanceof d.EB7&&(e=k(e,t.maxTextureSize));let i=e.userData.mimeType;"image/webp"===i&&(i="image/png");let o={sampler:this.processSampler(e),source:this.processImage(e.image,e.format,e.flipY,i)};e.name&&(o.name=e.name),this._invokeAll(function(t){t.writeTexture&&t.writeTexture(e,o)});let s=r.textures.push(o)-1;return n.textures.set(e,s),s}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||(n.materials=[]);let r={pbrMetallicRoughness:{}};!0!==e.isMeshStandardMaterial&&!0!==e.isMeshBasicMaterial&&console.warn("GLTFExporter: Use MeshStandardMaterial or MeshBasicMaterial for best results.");let i=e.color.toArray().concat([e.opacity]);if(O(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),e.metalnessMap||e.roughnessMap){let t=this.buildMetalRoughTexture(e.metalnessMap,e.roughnessMap),n={index:this.processTexture(t),channel:t.channel};this.applyTextureTransform(n,t),r.pbrMetallicRoughness.metallicRoughnessTexture=n}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,n=Math.max(t.r,t.g,t.b);if(n>0&&(r.emissiveFactor=e.emissive.toArray()),e.emissiveMap){let t={index:this.processTexture(e.emissiveMap),texCoord:e.emissiveMap.channel};this.applyTextureTransform(t,e.emissiveMap),r.emissiveTexture=t}}if(e.normalMap){let t={index:this.processTexture(e.normalMap),texCoord:e.normalMap.channel};e.normalScale&&1!==e.normalScale.x&&(t.scale=e.normalScale.x),this.applyTextureTransform(t,e.normalMap),r.normalTexture=t}if(e.aoMap){let t={index:this.processTexture(e.aoMap),texCoord:e.aoMap.channel};1!==e.aoMapIntensity&&(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===d.ehD&&(r.doubleSided=!0),""!==e.name&&(r.name=e.name),this.serializeUserData(e,r),this._invokeAll(function(t){t.writeMaterial&&t.writeMaterial(e,r)});let o=n.materials.push(r)-1;return t.materials.set(e,o),o}processMesh(e){let t;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(void 0!==e.morphTargetDictionary)for(let t in e.morphTargetDictionary)i[e.morphTargetDictionary[t]]=t;for(let o=0;o0&&(a.extras={},a.extras.targetNames=r)}let v=Array.isArray(e.material);if(v&&0===s.groups.length)return null;let m=v?e.material:[e.material],y=v?s.groups:[{materialIndex:0,start:void 0,count:void 0}];for(let e=0,r=y.length;e0&&(r.targets=u),null!==s.index){let t=this.getUID(s.index);(void 0!==y[e].start||void 0!==y[e].count)&&(t+=":"+y[e].start+":"+y[e].count),n.attributes.has(t)?r.indices=n.attributes.get(t):(r.indices=this.processAccessor(s.index,s,y[e].start,y[e].count),n.attributes.set(t,r.indices)),null===r.indices&&delete r.indices}let i=this.processMaterial(m[y[e].materialIndex]);null!==i&&(r.material=i),c.push(r)}a.primitives=c,r.meshes||(r.meshes=[]),this._invokeAll(function(t){t.writeMesh&&t.writeMesh(e,a)});let b=r.meshes.push(a)-1;return n.meshes.set(o,b),b}detectMeshQuantization(e,t){let n;if(this.extensionsUsed[x])return;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];T[r]&&T[r].includes(n)&&(this.extensionsUsed[x]=!0,this.extensionsRequired[x]=!0)}processCamera(e){let t=this.json;t.cameras||(t.cameras=[]);let n=e.isOrthographicCamera,r={type:n?"orthographic":"perspective"};return n?r.orthographic={xmag:2*e.right,ymag:2*e.top,zfar:e.far<=0?.001:e.far,znear:e.near<0?0:e.near}:r.perspective={aspectRatio:e.aspect,yfov:d.M8C.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,r=this.nodeMap;n.animations||(n.animations=[]),e=R.Utils.mergeMorphTargetTracks(e.clone(),t);let i=e.tracks,o=[],s=[];for(let e=0;e0){let t=[];for(let r=0,i=e.children.length;r0&&(i.children=t)}this._invokeAll(function(t){t.writeNode&&t.writeNode(e,i)});let o=t.nodes.push(i)-1;return r.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 d.xsS;t.name="AuxScene";for(let n=0;n0&&this.processObjects(n);for(let e=0;e0&&(o.range=e.distance)):e.isSpotLight&&(o.type="spot",e.distance>0&&(o.range=e.distance),o.spot={},o.spot.innerConeAngle=(1-e.penumbra)*e.angle,o.spot.outerConeAngle=e.angle),void 0!==e.decay&&2!==e.decay&&console.warn("THREE.GLTFExporter: Light decay may be lost. glTF is physically-based, and expects light.decay=2."),e.target&&(e.target.parent!==e||0!==e.target.position.x||0!==e.target.position.y||-1!==e.target.position.z)&&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 s=r.extensions[this.name].lights;s.push(o),t.extensions=t.extensions||{},t.extensions[this.name]={light:s.length-1}}}class L{constructor(e){this.writer=e,this.name="KHR_materials_unlit"}writeMaterial(e,t){if(!e.isMeshBasicMaterial)return;let n=this.writer,r=n.extensionsUsed;t.extensions=t.extensions||{},t.extensions[this.name]={},r[this.name]=!0,t.pbrMetallicRoughness.metallicFactor=0,t.pbrMetallicRoughness.roughnessFactor=.9}}class B{constructor(e){this.writer=e,this.name="KHR_materials_clearcoat"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.clearcoat)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};n.applyTextureTransform(t,e.clearcoatNormalMap),i.clearcoatNormalTexture=t}t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class H{constructor(e){this.writer=e,this.name="KHR_materials_iridescence"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.iridescence)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}}class F{constructor(e){this.writer=e,this.name="KHR_materials_transmission"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)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}}class U{constructor(e){this.writer=e,this.name="KHR_materials_volume"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0===e.transmission)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}i.attenuationDistance=e.attenuationDistance,i.attenuationColor=e.attenuationColor.toArray(),t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class D{constructor(e){this.writer=e,this.name="KHR_materials_ior"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1.5===e.ior)return;let n=this.writer,r=n.extensionsUsed,i={};i.ior=e.ior,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}class G{constructor(e){this.writer=e,this.name="KHR_materials_specular"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||1===e.specularIntensity&&e.specularColor.equals(P)&&!e.specularIntensityMap&&!e.specularColorTexture)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}}class z{constructor(e){this.writer=e,this.name="KHR_materials_sheen"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.sheen)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}}class K{constructor(e){this.writer=e,this.name="KHR_materials_anisotropy"}writeMaterial(e,t){if(!e.isMeshPhysicalMaterial||0==e.anisotropy)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}}class V{constructor(e){this.writer=e,this.name="KHR_materials_emissive_strength"}writeMaterial(e,t){if(!e.isMeshStandardMaterial||1===e.emissiveIntensity)return;let n=this.writer,r=n.extensionsUsed,i={};i.emissiveStrength=e.emissiveIntensity,t.extensions=t.extensions||{},t.extensions[this.name]=i,r[this.name]=!0}}function X(e,t){if(t===d.WwZ)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),e;if(t!==d.z$h&&t!==d.UlW)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",t),e;{let n=e.getIndex();if(null===n){let t=[],r=e.getAttribute("position");if(void 0===r)return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),e;for(let e=0;eMath.abs(e.times[0]-t))return 0;i[0]=t,i.set(e.times,1),o.set(s.evaluate(t),0),o.set(e.values,r),n=0}else if(t>e.times[e.times.length-1]){if(.001>Math.abs(e.times[e.times.length-1]-t))return e.times.length-1;i[i.length-1]=t,i.set(e.times,0),o.set(e.values,0),o.set(s.evaluate(t),e.values.length),n=i.length-1}else for(let a=0;aMath.abs(e.times[a]-t))return a;if(e.times[a]t){i.set(e.times.slice(0,a+1),0),i[a+1]=t,i.set(e.times.slice(a+1),a+2),o.set(e.values.slice(0,(a+1)*r),0),o.set(s.evaluate(t),(a+1)*r),o.set(e.values.slice((a+1)*r),(a+2)*r),n=a+1;break}}return e.times=i,e.values=o,n},mergeMorphTargetTracks:function(e,t){let n=[],r={},i=e.tracks;for(let e=0;e=2.0 are supported."));return}let l=new eN(i,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});l.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e=0&&void 0===s[t]&&console.warn('THREE.GLTFLoader: Unknown extension "'+t+'".')}}l.setExtensions(o),l.setPlugins(s),l.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}}function W(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}let J={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class Z{constructor(e){this.parser=e,this.name=J.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n=0))return null;throw Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures")}return t.loadTextureImage(e,i.source,o)}}class el{constructor(e){this.parser=e,this.name=J.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let o=i.extensions[t],s=r.images[o.source],a=n.textureLoader;if(s.uri){let e=n.options.manager.getHandler(s.uri);null!==e&&(a=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){let t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class ec{constructor(e){this.parser=e,this.name=J.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let o=i.extensions[t],s=r.images[o.source],a=n.textureLoader;if(s.uri){let e=n.options.manager.getHandler(s.uri);null!==e&&(a=e)}return this.detectSupport().then(function(i){if(i)return n.loadTextureImage(e,o.source,a);if(r.extensionsRequired&&r.extensionsRequired.indexOf(t)>=0)throw Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return n.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){let t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(1===t.height)}})),this.isSupported}}class eu{constructor(e){this.name=J.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(!n.extensions||!n.extensions[this.name])return null;{let e=n.extensions[this.name],r=this.parser.getDependency("buffer",e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(!(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0))return null;throw Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files")}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,o=e.count,s=e.byteStride,a=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(o,s,a,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(o*s);return i.decodeGltfBuffer(new Uint8Array(t),o,s,a,e.mode,e.filter),t})})}}}class eh{constructor(e){this.name=J.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||void 0===n.mesh)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==ek.TRIANGLES&&e.mode!==ek.TRIANGLE_STRIP&&e.mode!==ek.TRIANGLE_FAN&&void 0!==e.mode)return null;let i=n.extensions[this.name],o=i.attributes,s=[],a={};for(let e in o)s.push(this.parser.getDependency("accessor",o[e]).then(t=>(a[e]=t,a[e])));return s.length<1?null:(s.push(this.parser.createNodeMesh(e)),Promise.all(s).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new d.yGw,n=new d.Pa4,o=new d._fP,s=new d.Pa4(1,1,1),l=new d.SPe(e.geometry,e.material,r);for(let e=0;e-1)?navigator.userAgent.match(/Firefox\/([0-9]+)\./)[1]:-1),"undefined"==typeof createImageBitmap||n||r&&i<98?this.textureLoader=new d.dpR(this.options.manager):this.textureLoader=new d.QRU(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new d.hH6(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),"use-credentials"===this.options.crossOrigin&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(t){let o={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return eM(i,o,r),e_(o,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(o)})).then(function(){e(o)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n{let n=this.associations.get(e);for(let[r,o]of(null!=n&&this.associations.set(t,n),e.children.entries()))i(o,t.children[r])};return i(n,r),r.name+="_instance_"+e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n=2&&o.setY(t,h[e*a+1]),a>=3&&o.setZ(t,h[e*a+2]),a>=4&&o.setW(t,h[e*a+3]),a>=5)throw Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}}return o})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e],i=r.source,o=t.images[i],s=this.textureLoader;if(o.uri){let e=n.manager.getHandler(o.uri);null!==e&&(s=e)}return this.loadTextureImage(e,i,s)}loadTextureImage(e,t,n){let r=this,i=this.json,o=i.textures[e],s=i.images[t],a=(s.uri||s.bufferView)+":"+o.sampler;if(this.textureCache[a])return this.textureCache[a];let l=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=o.name||s.name||"",""===t.name&&"string"==typeof s.uri&&!1===s.uri.startsWith("data:image/")&&(t.name=s.uri);let n=i.samplers||{},a=n[o.sampler]||{};return t.magFilter=eR[a.magFilter]||d.wem,t.minFilter=eR[a.minFilter]||d.D1R,t.wrapS=eA[a.wrapS]||d.rpg,t.wrapT=eA[a.wrapT]||d.rpg,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[a]=l,l}loadImageSource(e,t){let n=this.json,r=this.options;if(void 0!==this.sourceCache[e])return this.sourceCache[e].then(e=>e.clone());let i=n.images[e],o=self.URL||self.webkitURL,s=i.uri||"",a=!1;if(void 0!==i.bufferView)s=this.getDependency("bufferView",i.bufferView).then(function(e){a=!0;let t=new Blob([e],{type:i.mimeType});return s=o.createObjectURL(t)});else if(void 0===i.uri)throw Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");let l=Promise.resolve(s).then(function(e){return new Promise(function(n,i){let o=n;!0===t.isImageBitmapLoader&&(o=function(e){let t=new d.xEZ(e);t.needsUpdate=!0,n(t)}),t.load(d.Zp0.resolveURL(e,r.path),o,void 0,i)})}).then(function(e){var t;return!0===a&&o.revokeObjectURL(s),e.userData.mimeType=i.mimeType||((t=i.uri).search(/\.jpe?g($|\?)/i)>0||0===t.search(/^data\:image\/jpeg/)?"image/jpeg":t.search(/\.webp($|\?)/i)>0||0===t.search(/^data\:image\/webp/)?"image/webp":"image/png"),e}).catch(function(e){throw console.error("THREE.GLTFLoader: Couldn't load texture",s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){let i=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(void 0!==n.texCoord&&n.texCoord>0&&((o=o.clone()).channel=n.texCoord),i.extensions[J.KHR_TEXTURE_TRANSFORM]){let e=void 0!==n.extensions?n.extensions[J.KHR_TEXTURE_TRANSFORM]:void 0;if(e){let t=i.associations.get(o);o=i.extensions[J.KHR_TEXTURE_TRANSFORM].extendTexture(o,e),i.associations.set(o,t)}}return void 0!==r&&(o.colorSpace=r),e[t]=o,o})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=void 0===t.attributes.tangent,i=void 0!==t.attributes.color,o=void 0===t.attributes.normal;if(e.isPoints){let e="PointsMaterial:"+n.uuid,t=this.cache.get(e);t||(t=new d.UY4,d.F5T.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e="LineBasicMaterial:"+n.uuid,t=this.cache.get(e);t||(t=new d.nls,d.F5T.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||o){let e="ClonedMaterial:"+n.uuid+":";r&&(e+="derivative-tangents:"),i&&(e+="vertex-colors:"),o&&(e+="flat-shading:");let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),o&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return d.Wid}loadMaterial(e){let t;let n=this,r=this.json,i=this.extensions,o=r.materials[e],s={},a=o.extensions||{},l=[];if(a[J.KHR_MATERIALS_UNLIT]){let e=i[J.KHR_MATERIALS_UNLIT];t=e.getMaterialType(),l.push(e.extendParams(s,o,n))}else{let r=o.pbrMetallicRoughness||{};if(s.color=new d.Ilk(1,1,1),s.opacity=1,Array.isArray(r.baseColorFactor)){let e=r.baseColorFactor;s.color.setRGB(e[0],e[1],e[2],d.GUF),s.opacity=e[3]}void 0!==r.baseColorTexture&&l.push(n.assignTexture(s,"map",r.baseColorTexture,d.KI_)),s.metalness=void 0!==r.metallicFactor?r.metallicFactor:1,s.roughness=void 0!==r.roughnessFactor?r.roughnessFactor:1,void 0!==r.metallicRoughnessTexture&&(l.push(n.assignTexture(s,"metalnessMap",r.metallicRoughnessTexture)),l.push(n.assignTexture(s,"roughnessMap",r.metallicRoughnessTexture))),t=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,s)})))}!0===o.doubleSided&&(s.side=d.ehD);let c=o.alphaMode||eO.OPAQUE;if(c===eO.BLEND?(s.transparent=!0,s.depthWrite=!1):(s.transparent=!1,c===eO.MASK&&(s.alphaTest=void 0!==o.alphaCutoff?o.alphaCutoff:.5)),void 0!==o.normalTexture&&t!==d.vBJ&&(l.push(n.assignTexture(s,"normalMap",o.normalTexture)),s.normalScale=new d.FM8(1,1),void 0!==o.normalTexture.scale)){let e=o.normalTexture.scale;s.normalScale.set(e,e)}if(void 0!==o.occlusionTexture&&t!==d.vBJ&&(l.push(n.assignTexture(s,"aoMap",o.occlusionTexture)),void 0!==o.occlusionTexture.strength&&(s.aoMapIntensity=o.occlusionTexture.strength)),void 0!==o.emissiveFactor&&t!==d.vBJ){let e=o.emissiveFactor;s.emissive=new d.Ilk().setRGB(e[0],e[1],e[2],d.GUF)}return void 0!==o.emissiveTexture&&t!==d.vBJ&&l.push(n.assignTexture(s,"emissiveMap",o.emissiveTexture,d.KI_)),Promise.all(l).then(function(){let r=new t(s);return o.name&&(r.name=o.name),e_(r,o),n.associations.set(r,{materials:e}),o.extensions&&eM(i,r,o),r})}createUniqueName(e){let t=d.iUV.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache,i=[];for(let o=0,s=e.length;o0&&function(e,t){if(e.updateMorphTargets(),void 0!==t.weights)for(let n=0,r=t.weights.length;n1?new d.ZAu:1===t.length?t[0]:new d.Tme)!==t[0])for(let e=0,n=t.length;e{let t=new Map;for(let[e,n]of r.associations)(e instanceof d.F5T||e instanceof d.xEZ)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);null!=n&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let o;let s=[],a=e.name?e.name:e.uuid,l=[];switch(eS[i.path]===eS.weights?e.traverse(function(e){e.morphTargetInfluences&&l.push(e.name?e.name:e.uuid)}):l.push(a),eS[i.path]){case eS.weights:o=d.dUE;break;case eS.rotation:o=d.iLg;break;case eS.position:case eS.scale:o=d.yC1;break;default:o=1===n.itemSize?d.dUE:d.yC1}let c=void 0!==r.interpolation?eP[r.interpolation]:d.NMF,u=this._getArrayFromAccessor(n);for(let e=0,n=l.length;e3&&void 0!==arguments[3]?arguments[3]:function(){};new Y().load(e,function(e){e.scene.scale.set(y.R/.5,y.R/.5,y.R/.5),e.scene.matrixAutoUpdate=!1,e.scene.visible=n,e.scene.updateMatrix(),t.add(e.scene),r()},function(e){return console.log(e.loaded+" bytes loaded")},eB)}var eF=n("./src/view/tablegeometry.ts");function eU(e,t){for(var n=0;nthis.radius-y.R){var r=this.pos.clone().sub(e.pos).normalize().setZ(0);n>-y.R/2&&e.vel.addScaledVector(r,7*y.R*t*y.g),0>e.vel.dot(r)&&(e.ballmesh.trace.forceTrace(e.pos),e.vel.x=r.x*e.vel.length()/2,e.vel.y=r.y*e.vel.length()/2)}var i=this.restingDepth(e);n2&&void 0!==arguments[2]?arguments[2]:this.cloth;this.cylinder(e.pos,e.radius,.75*y.R/.5,t,n).position.setZ(-(.25*y.R)/.5/2)}},{key:"cylinder",value:function(e,t,n,r,i){var o=new d.fHI(t,t,n,16),s=new d.Kj0(o,i);return s.position.copy(e),s.geometry.applyMatrix4(new d.yGw().identity().makeRotationAxis(new d.Pa4(1,0,0),Math.PI/2)),r.add(s),s}},{key:"addCushions",value:function(e,t){var n=10*y.R/.5;this.plane(new d.Pa4(0,0,-y.R-n/2),2*eF.H.X,2*eF.H.Y,n,e,this.cloth);var r=1*y.R/.5,i=.75*y.R/.5,o=-(.25*y.R)/.5/2,s=eF.H.X,a=eF.H.Y,l=Math.abs(eZ.pockets.pocketNW.knuckleNE.pos.x-eZ.pockets.pocketN.knuckleNW.pos.x),c=Math.abs(eZ.pockets.pocketNW.knuckleSW.pos.y-eZ.pockets.pocketSW.knuckleNW.pos.y);t||(l=2*eF.H.Y,c=2*eF.H.Y+4*y.R),this.plane(new d.Pa4(s+r/2,0,o),r,c,i,e),this.plane(new d.Pa4(-s-r/2,0,o),r,c,i,e),this.plane(new d.Pa4(-s/2,a+r/2,o),l,r,i,e),this.plane(new d.Pa4(-s/2,-a-r/2,o),l,r,i,e),this.plane(new d.Pa4(s/2,a+r/2,o),l,r,i,e),this.plane(new d.Pa4(s/2,-a-r/2,o),l,r,i,e)}},{key:"plane",value:function(e,t,n,r,i){var o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:this.cushion,s=new d.DvJ(t,n,r),a=new d.Kj0(s,o);a.receiveShadow=!0,a.position.copy(e),i.add(a)}}],eq(n.prototype,e),t&&eq(n,t),n}(),e0=n("./src/events/watchevent.ts");function e1(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}!function(e){e.Pot="Pot",e.Cushion="Cushion",e.Collision="Collision",e.Hit="Hit"}(a||(a={}));var e2=function(){var e;function t(e,n,r,i){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t),e1(this,"type",void 0),e1(this,"timestamp",void 0),e1(this,"ballA",null),e1(this,"ballB",null),e1(this,"incidentSpeed",void 0),this.type=e,this.ballA=n,this.ballB=r,this.incidentSpeed=i,this.timestamp=Date.now()}return e=[{key:"pot",value:function(e,n){return new t("Pot",e,e,n)}},{key:"cushion",value:function(e,n){return new t("Cushion",e,e,n)}},{key:"collision",value:function(e,n,r){return new t("Collision",e,n,r)}},{key:"hit",value:function(e,n){return new t("Hit",e,e,n)}},{key:"isCueBallPotted",value:function(e,t){return t.some(function(t){return"Pot"==t.type&&t.ballA===e})}},{key:"isBallPottedNoFoul",value:function(e,n){return n.some(function(e){return"Pot"==e.type&&null!==e.ballA})&&!t.isCueBallPotted(e,n)}},{key:"pots",value:function(e){return e.filter(function(e){return"Pot"==e.type}).map(function(e){return e.ballA})}},{key:"potCount",value:function(e){return this.pots(e).length}},{key:"onlyRedsPotted",value:function(e){return this.pots(e).every(function(e){return e.id>6})}},{key:"isThreeCushionPoint",value:function(e,n){n=t.cueBallFirst(e,n).filter(function(t){return t.ballA===e});var r=new Set,i=0,o=!0,s=!1,a=void 0;try{for(var l,c=n[Symbol.iterator]();!(o=(l=c.next()).done);o=!0){var u=l.value;if("Cushion"===u.type&&i++,"Collision"===u.type&&(r.add(u.ballB),2===r.size))return i>=3}}catch(e){s=!0,a=e}finally{try{o||null==c.return||c.return()}finally{if(s)throw a}}return!1}},{key:"cueBallFirst",value:function(e,t){return t.forEach(function(t){"Collision"===t.type&&t.ballB===e&&(t.ballB=t.ballA,t.ballA=e)}),t}}],function(e,t){for(var n=0;n-eF.H.tableX&&n.overlapsAny(r,t);)r.x-=y.R/8;t.pos.copy(r),t.state=eV.Z.Stationary}}],function(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=Array(t);n3&&void 0!==arguments[3]&&arguments[3],a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:1500;if(!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,o),tb(tm(r=i.call(this,e)),"delay",void 0),tb(tm(r),"shots",void 0),tb(tm(r),"firstShot",void 0),tb(tm(r),"timer",void 0),tb(tm(r),"init",void 0),r.init=t,r.shots=tk(n),r.firstShot=r.shots[0],r.delay=a,r.container.table.showTraces(!0),r.container.table.updateFromShortSerialised(r.init),s){var l=new tp.l(t,n);l.retry=!0,r.container.eventQueue.push(l)}else r.container.view.camera.forceMode(r.container.view.camera.topView),r.playNextShot(1.5*r.delay);return r}return n=[{key:"playNextShot",value:function(e){var t=this,n=this.shots.shift();if((null==n?void 0:n.type)===c.t.RERACK){td.K.fromJson(n.ballinfo).applyToController(this),this.shots.length>0&&this.playNextShot(e);return}var r=e5.f.fromJson(n);this.container.table.cueball=this.container.table.balls[r.i],this.container.table.cueball.pos.copy(r.pos),this.container.table.cue.aim=r,this.container.table.cue.updateAimInput(),this.container.table.cue.t=1,clearTimeout(this.timer),this.timer=setTimeout(function(){t.container.eventQueue.push(new e8.O(t.container.table.cue.aim)),t.timer=void 0},e)}},{key:"handleHit",value:function(e){return this.hit(),this}},{key:"handleStationary",value:function(e){return this.shots.length>0&&void 0===this.timer&&this.playNextShot(this.delay),this}},{key:"handleInput",value:function(e){return this.commonKeyHandler(e),this}},{key:"handleBreak",value:function(e){return(this.container.table.updateFromShortSerialised(e.init),this.shots=tk(e.shots),this.container.table.showSpin(!0),e.retry)?this.retry():(this.playNextShot(this.delay),this)}},{key:"retry",value:function(){clearTimeout(this.timer),this.timer=void 0,this.container.table.updateFromShortSerialised(this.init);var e=e5.f.fromJson(this.firstShot);return this.container.table.cueball=this.container.table.balls[e.i],this.container.rules.cueball=this.container.table.cueball,this.container.table.cueball.pos.copy(e.pos),this.container.table.cue.aim=e,this.container.view.camera.forceMode(this.container.view.camera.aimView),new tE(this.container)}}],ty(o.prototype,n),r&&ty(o,r),o}(tl);function tR(e,t){for(var n=0;n2)||void 0===arguments[2]||arguments[2],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:tG.h_,o=e.futurePosition(n);if(t.willBounceLong(o,r)){var s=o.y>eF.H.tableY?-Math.PI/2:Math.PI/2;return t.bounceIn(s,e,i)}if(t.willBounceShort(o,r)){var a=o.x>eF.H.tableX?0:Math.PI;return t.bounceIn(a,e,i)}}},{key:"willBounceShort",value:function(e,n){return n?t.willBounceShortSegment(eZ.pockets.pocketNW.knuckleSW.pos.y,eZ.pockets.pocketSW.knuckleNW.pos.y,e):t.willBounceShortSegment(eF.H.Y,-eF.H.Y,e)}},{key:"willBounceLong",value:function(e,n){return n?t.willBounceLongSegment(eZ.pockets.pocketNW.knuckleNE.pos.x,eZ.pockets.pocketN.knuckleNW.pos.x,e)||t.willBounceLongSegment(eZ.pockets.pocketN.knuckleNE.pos.x,eZ.pockets.pocketNE.knuckleNW.pos.x,e):t.willBounceLongSegment(-eF.H.X,eF.H.X,e)}},{key:"willBounceLongSegment",value:function(e,t,n){return n.x>e&&n.xeF.H.tableY}},{key:"willBounceShortSegment",value:function(e,t,n){return n.y>t&&n.yeF.H.tableX}},{key:"bounceIn",value:function(e,t,n){t.ballmesh.trace.forceTrace(t.futurePos);var r=(0,tG.ZI)(e,t.vel,t.rvel,n);return t.vel.add(r.v),t.rvel.add(r.w),r.v.length()}}],function(e,t){for(var n=0;n100)throw Error("Depth exceeded resolving collisions");this.balls.forEach(function(t){t.update(e)})}},{key:"prepareAdvanceAll",value:function(e){var t=this;return this.pairs.every(function(n){return t.prepareAdvancePair(n.a,n.b,e)})&&this.balls.every(function(n){return t.prepareAdvanceToCushions(n,e)})}},{key:"prepareAdvancePair",value:function(e,t,n){if(tK.willCollide(e,t,n)){var r=tK.collide(e,t);return this.outcome.push(e2.collision(e,t,r)),!1}return!0}},{key:"prepareAdvanceToCushions",value:function(e,t){if(!e.onTable())return!0;var n=e.futurePosition(t);if(Math.abs(n.y)1&&void 0!==arguments[1]?arguments[1]:this.cueball;return this.balls.filter(function(e){return e!==t}).some(function(t){return t.pos.distanceTo(e)<2*y.R})}}],t=[{key:"fromSerialised",value:function(e){var t=new n(e.balls.map(function(e){return eV.e.fromSerialised(e)}));return t.updateFromSerialised(e),t}}],e&&tX(n.prototype,e),t&&tX(n,t),n}();function tJ(e,t){for(var n=0;n0){if(this.previousPotRed)this.previousPotRed=!1,this.respot(e);else if(e2.onlyRedsPotted(e))this.previousPotRed=!0;else if(1===t){var n=e2.pots(e)[0].id;n>1&&this.container.table.balls.filter(function(e){return e.id0}).some(function(e){return e.onTable()})&&this.respot(e)}else this.respot(e)}return t1(t2(o.prototype),"update",this).call(this,e)}},{key:"respot",value:function(e){var t=this.respotAllPottedColours(e);if(t.length>0){var n={balls:t.map(function(e){return e.serialise()}),rerack:!0},r=new e0.g(n);this.container.sendEvent(r),this.container.recoder.record(r)}}},{key:"respotAllPottedColours",value:function(e){var t=this;return e2.pots(e).filter(function(e){return e.id<7}).filter(function(e){return 0!==e.id}).map(function(e){return e3.respot(e,t.container.table)})}}],t$(o.prototype,n),r&&t$(o,r),o}(tq);function t5(e,t){for(var n=0;n0&&(null===(t=this.cuePowerElement)||void 0===t?void 0:t.value)&&(this.cuePowerElement.value=e)}}],no(n.prototype,e),t&&no(n,t),n}();function nl(e,t){for(var n=0;n2&&void 0!==arguments[2]?arguments[2]:0;if(this.loadAssets){var r,i,o=d.Hmr.getContext();if((null==o?void 0:o.state)==="suspended"){(null===(i=navigator)||void 0===i?void 0:null===(r=i.userActivation)||void 0===r?void 0:r.hasBeenActive)&&o.resume();return}e.setVolume(t),e.isPlaying&&e.stop(),e.play(d.M8C.randFloat(0,.01)),e.setDetune(n)}}},{key:"outcomeToSound",value:function(e){"Collision"===e.type&&this.play(this.ballcollision,e.incidentSpeed/80,5*e.incidentSpeed),"Pot"===e.type&&this.play(this.pot,e.incidentSpeed/10,-1e3+10*e.incidentSpeed),"Cushion"===e.type&&this.play(this.cushion,e.incidentSpeed/70),"Hit"===e.type&&this.play(this.cue,e.incidentSpeed/30)}},{key:"processOutcomes",value:function(e){var t=this;e.every(function(e){return!(e.timestamp>t.lastOutcomeTime)||(t.lastOutcomeTime=e.timestamp,t.outcomeToSound(e),!1)})}},{key:"playNotify",value:function(){this.play(this.pot,1)}},{key:"playSuccess",value:function(e){this.play(this.success,.1,100*e-2200)}}],nl(n.prototype,e),t&&nl(n,t),n}();function nh(e,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function nf(e,t){for(var n=0;nthis.sentTime+this.period||e.type!==c.t.AIM){this.flush(),this.apply(e),this.sentTime=performance.now();return}this.pending=e}}],nv(n.prototype,e),t&&nv(n,t),n}(),nb=n("./src/view/sliders.ts"),ng=n("./node_modules/jsoncrush/JSONCrush.js");function nw(e,t){for(var n=0;n0&&"RERACK"===this.shots[e].type&&e--,e}},{key:"lastShot",value:function(){var e=this.last();return this.state(this.states[e],[this.shots[e]])}},{key:"currentBreak",value:function(){if(void 0!==this.breakStart)return this.state(this.states[this.breakStart],this.shots.slice(this.breakStart))}},{key:"state",value:function(e,t){return{init:e,shots:t}}},{key:"updateBreak",value:function(e){var t=this.container.rules.isPartOfBreak(e),n=this.container.rules.isEndOfGame(e),r=e2.potCount(e);if(t||this.breakLink(n),this.lastShotLink(t||n,r),n&&this.breakLink(n),!t){this.breakStart=void 0;return}void 0===this.breakStart&&(this.breakStart=this.last())}},{key:"lastShotLink",value:function(e,t){var n="⚈".repeat(t>1?t-1:0)+(e?"⚈":"⚆"),r=JSON.stringify(this.lastShot());this.generateLink(n,r)}},{key:"breakLink",value:function(e){var t=this.currentBreak();if(t&&(e||t.shots.pop(),1!==t.shots.length)){var n="break(".concat(t.shots.length,")"),r=JSON.stringify(t),i=ng.Z.crush(r);this.generateLink(n,i)}}},{key:"wholeGameLink",value:function(){var e=this.wholeGame(),t="frame(".concat(e.shots.length,")"),n=JSON.stringify(e),r=ng.Z.crush(n);this.generateLink(t,r)}},{key:"generateLink",value:function(e,t){var n="".concat(this.replayUrl).concat(encodeURIComponent(t)),r='').concat(e,"");this.container.eventQueue.push(new tU.s(null,"".concat(r)))}}],nw(n.prototype,e),t&&nw(n,t),n}();function nR(e,t){for(var n=0;n').concat(e,"")));r.push(new tU.s(null,s))})},this.redo.onclick=function(e){var r=new tp.l(t.init,t.shots);r.retry=!0,n.interuptEventQueue(r)},this.replay.onclick=function(e){n.interuptEventQueue(t)}}},{key:"interuptEventQueue",value:function(e){this.container.table.halt();var t=this.container.eventQueue;t.length=0,t.push(new p),t.push(e)}},{key:"getElement",value:function(e){return document.getElementById(e)}}],nI(n.prototype,e),t&&nI(n,t),n}();function nN(e,t){for(var n=0;n2)||void 0===arguments[2]||arguments[2],i=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0,s=arguments.length>5?arguments[5]:void 0,a=arguments.length>6?arguments[6]:void 0,l=this;!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,n),nL(this,"table",void 0),nL(this,"view",void 0),nL(this,"controller",void 0),nL(this,"inputQueue",[]),nL(this,"eventQueue",[]),nL(this,"keyboard",void 0),nL(this,"sound",void 0),nL(this,"chat",void 0),nL(this,"sliders",void 0),nL(this,"recoder",void 0),nL(this,"id",""),nL(this,"isSinglePlayer",!0),nL(this,"rules",void 0),nL(this,"menu",void 0),nL(this,"last",performance.now()),nL(this,"step",.001953125),nL(this,"broadcast",void 0),nL(this,"log",void 0),nL(this,"sendChat",function(e){l.sendEvent(new tU.s(l.id,e))}),nL(this,"throttle",new ny(200,function(e){l.broadcast(e)})),nL(this,"lastEventTime",performance.now()),this.log=t,this.rules=n_.create(i,this),this.table=this.rules.table(),this.view=new t6(e,s,this.table,r,this.rules.asset()),this.table.cue.aimInputs=new na(this),this.keyboard=o,this.sound=new nu(this.view.camera.camera,r),this.chat=new nd(this.sendChat),this.sliders=new nb.E,this.recoder=new nT(this),this.id=a,this.menu=new nC(this),this.table.addToScene(this.view.scene),this.updateController(new nt(this))}return e=[{key:"sendEvent",value:function(e){this.throttle.send(e)}},{key:"advance",value:function(e){for(var t=Math.floor(e/this.step),n=t*this.step,r=this.table.allStationary(),i=0;i0;){this.lastEventTime=this.last;var t=this.inputQueue.shift();t&&this.updateController(this.controller.handleInput(t))}if(this.table.allStationary()){var n=this.eventQueue.shift();n&&(this.lastEventTime=performance.now(),this.updateController(n.applyToController(this.controller)))}}},{key:"animate",value:function(e){var t=this;this.advance((e-this.last)/1e3),this.last=e,this.processEvents(),(e{n.d(t,{Y:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{f:()=>f});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts"),s=n("./node_modules/three/build/three.module.js");function a(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function l(e,t){for(var n=0;n{n.d(t,{Z:()=>l});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e,t){for(var n=0;n{n.d(t,{l:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{s:()=>u});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r;n.d(t,{t:()=>r}),function(e){e.BEGIN="BEGIN",e.BREAK="BREAK",e.WATCHAIM="WATCHAIM",e.AIM="AIM",e.HIT="HIT",e.STATIONARY="STATIONARY",e.CHAT="CHAT",e.ABORT="ABORT",e.PLACEBALL="PLACEBALL",e.REJOIN="REJOIN",e.RERACK="RERACK"}(r||(r={}))},"./src/events/gameevent.ts":(e,t,n)=>{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{Z:()=>i});var i=function e(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"type",void 0),r(this,"sequence",void 0)}},"./src/events/hitevent.ts":(e,t,n)=>{n.d(t,{O:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}n.d(t,{I:()=>i});var i=function e(t,n){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,e),r(this,"t",void 0),r(this,"key",void 0),this.t=t,this.key=n}},"./src/events/keyboard.ts":(e,t,n)=>{n.d(t,{N:()=>l});var r=n("./src/events/input.ts"),i=n("./node_modules/interactjs/dist/interact.min.js"),o=n.n(i);function s(e,t){for(var n=0;nMath.abs(i.movementY)&&(i.movementY=0)}),this.addHandlers(e),/Android|iPhone/i.test(navigator.userAgent)||(e.contentEditable="true")}return e=[{key:"getEvents",value:function(){var e=this,t=Object.keys(this.pressed).filter(function(e){return!/Shift/.test(e)}).filter(function(e){return!/Control/.test(e)}),n=Object.keys(this.pressed).some(function(e){return/Shift/.test(e)}),i=Object.keys(this.pressed).some(function(e){return/Control/.test(e)}),o=[];return t.forEach(function(t){var s=performance.now()-e.pressed[t];o.push(new r.I(i?s/3:s,n?"Shift"+t:t)),"Space"!=t&&(e.pressed[t]=performance.now())}),Object.keys(this.released).forEach(function(t){return o.push(new r.I(e.released[t],t+"Up"))}),this.released={},o}},{key:"addHandlers",value:function(e){var t=this;e.addEventListener("keydown",this.keydown),e.addEventListener("keyup",this.keyup),e.focus(),o()(e).draggable({listeners:{move:function(e){t.mousetouch(e)}}})}}],s(n.prototype,e),t&&s(n,t),n}()},"./src/events/placeballevent.ts":(e,t,n)=>{n.d(t,{I:()=>h});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts"),o=n("./src/utils/utils.ts");function s(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){for(var n=0;n{n.d(t,{K:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{n.d(t,{g:()=>c});var r=n("./src/events/gameevent.ts"),i=n("./src/events/eventtype.ts");function o(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function s(e,t){for(var n=0;n{var r=n("./src/container/container.ts"),i=n("./src/events/keyboard.ts"),o=n("./src/events/eventtype.ts"),s=n("./src/events/aimevent.ts"),a=n("./src/events/watchevent.ts"),l=n("./src/events/hitevent.ts"),c=n("./src/events/abortevent.ts"),u=n("./src/events/breakevent.ts"),h=n("./src/events/beginevent.ts"),f=n("./src/events/chatevent.ts");function p(e){if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,s),v(p(e=i.call(this)),"clientResendFrom",void 0),v(p(e),"serverResendFrom",void 0),e.type=o.t.REJOIN,e.clientResendFrom=t,e.serverResendFrom=n,e}return n=[{key:"applyToController",value:function(e){return e.handleRejoin(this)}}],r=[{key:"fromJson",value:function(e){return new s(e.clientResendFrom,e.serverResendFrom)}}],n&&d(s.prototype,n),r&&d(s,r),s}(n("./src/events/gameevent.ts").Z),g=n("./src/events/placeballevent.ts"),w=n("./src/events/rerackevent.ts"),k=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"serialise",value:function(e){return JSON.stringify(e)}},{key:"fromJson",value:function(e){switch(e.type){case o.t.BEGIN:return new h.Z;case o.t.AIM:return s.f.fromJson(e);case o.t.BREAK:return u.l.fromJson(e);case o.t.WATCHAIM:return a.g.fromJson(e.json);case o.t.HIT:return l.O.fromJson(e);case o.t.CHAT:return f.s.fromJson(e);case o.t.REJOIN:return b.fromJson(e);case o.t.ABORT:return new c.Y;case o.t.PLACEBALL:return g.I.fromJson(e);case o.t.RERACK:return w.K.fromJson(e);default:throw Error("Unknown GameEvent :"+e)}}},{key:"fromSerialised",value:function(e){var n=JSON.parse(e),r=t.fromJson(n);return"sequence"in n&&(r.sequence=n.sequence),r}}],function(e,t){for(var n=0;n{n.d(t,{e:()=>m,Z:()=>r});var r,i=n("./src/utils/utils.ts"),o=n("./src/model/physics/physics.ts"),s=n("./node_modules/three/build/three.module.js"),a=n("./src/model/physics/constants.ts");function l(e,t){for(var n=0;nMath.PI/32?.01*a.R:a.R,i=this.lastPos.distanceTo(e);this.addTraceGiven(e,t,i,r,n)}}},{key:"addTraceGiven",value:function(e,t,n,r,i){var o=this.geometry.drawRange.count;0!==o&&n1&&i<1e-4&&o--,this.lastPos.copy(e),this.lastVel.copy(t),this.addPoint(e,o))}},{key:"addPoint",value:function(e,t){var n=3*t;n>this.positions.length||(this.positions[n++]=e.x,this.positions[n++]=e.y,this.positions[n]=e.z,this.geometry.setDrawRange(0,t+1),this.line.geometry.attributes.position.needsUpdate=!0)}}],l(n.prototype,e),t&&l(n,t),n}();function h(e,t){for(var n=0;nMath.abs(this.rvel.z))&&(this.setStationary(),!0)}},{key:"setStationary",value:function(){this.vel.copy(i.bM),this.rvel.copy(i.bM),this.state="Stationary"}},{key:"isRolling",value:function(){return 0!==this.vel.lengthSq()&&0!==this.rvel.lengthSq()&&(0,o.E9)(this.vel,this.rvel).length(){n.d(t,{Dt:()=>c,Ew:()=>v,G3:()=>w,Hz:()=>i,I:()=>o,Mz:()=>r,R:()=>f,Xm:()=>k,_5:()=>u,dE:()=>y,e:()=>p,f7:()=>g,fN:()=>m,g:()=>s,m:()=>h,mu:()=>a,zq:()=>b,zv:()=>l});var r,i,o,s=9.8,a=.00985,l=.105,c=.8,u=.024,h=.23,f=.03275,p=.86;function d(){r=a*h*s*2/3*u,i=7/(5*Math.sqrt(2))*f*a*h*s,o=.4*h*f*f}function v(e){f=e,d()}function m(e){h=e,d()}function y(e){a=e,d()}function b(e){u=e,d()}function g(e){l=e}function w(e){p=e}function k(e){c=e}d()},"./src/model/physics/physics.ts":(e,t,n)=>{n.d(t,{E9:()=>a,Fn:()=>A,IT:()=>h,NP:()=>g,QC:()=>u,Vp:()=>c,WL:()=>S,ZI:()=>f,al:()=>b,c0:()=>y,h_:()=>x,s0:()=>m,vZ:()=>w});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/utils/utils.ts"),o=n("./src/model/physics/constants.ts"),s=new r.Pa4;function a(e,t){return s.copy(e).addScaledVector((0,i.a1)(t),o.R)}var l={v:new r.Pa4,w:new r.Pa4};function c(e,t){var n=a(e,t).setZ(0);return l.v.copy((0,i.KO)(n).multiplyScalar(-o.zv*o.g)),l.w.copy((0,i.KO)((0,i.a1)(n)).multiplyScalar(2.5*o.zv*o.g/o.R)),l.w.setZ(-2.5*(o.Mz/(o.R*o.R))*Math.sign(t.z)),l}function u(e){var t=new r.Pa4(e.x,e.y,0).length(),n=5/7*o.Hz/(o.m*o.R)/t,i=5/7*o.Hz/(o.m*o.R*o.R)/t;return l.v.set(-n*e.y,n*e.x,0),l.w.set(-i*e.x,-i*e.y,-2.5*(o.Mz/(o.m*o.R*o.R))*Math.sign(e.z)),l}function h(e,t){var n=t.z;t.copy((0,i.a1)(e).multiplyScalar(1/o.R)),t.setZ(n)}function f(e,t,n,r){var o=r(t.clone().applyAxisAngle(i.up,e),n.clone().applyAxisAngle(i.up,e));return o.v.applyAxisAngle(i.up,-e),o.w.applyAxisAngle(i.up,-e),o}Object.freeze(l);var p=Math.asin(.1*o.R/o.R),d=Math.sin(p),v=Math.cos(p);function m(e,t){return new r.Pa4(e.x*d-e.z*v+o.R*t.y,-e.y-o.R*t.z*v+o.R*t.x*d)}function y(e){return e.x*v}function b(e){var t=3.5/o.m;return e.length()/t}function g(e){var t,n=1/o.m,i=.39+.257*(t=new r.Pa4(e/v,0,0)).x-.044*t.x*t.x;return o.Dt*((1+i)*e)/n}function w(e,t){var n=g(y(e));return b(m(e,t))<=n}function k(e,t){return{c:y(e),s:m(e,t),A:3.5/o.m,B:1/o.m}}function T(e,t){var n=k(e,t),r=n.c,i=n.s,s=n.A,a=n.B,l=(1+o.e)*(r/a);return E(-i.x/s*d-l*v,i.y/s,i.x/s*v-l*d)}function R(e,t){var n=k(e,t),r=n.c,i=n.B,s=(1+o.e)*(r/i),a=.471-.241*Math.atan2(Math.abs(e.y),e.x),l=Math.atan2(e.y,e.x),c=Math.cos(l),u=-a*s*c*v-s*v,h=a*s*c*v-s*d;return E(u,a*s*Math.sin(l),h)}function A(e,t){return w(e,t)?T(e,t):R(e,t)}function x(e,t){var n=T(e,t),r=R(e,t),i=Math.sign(e.y)===Math.sign(t.z)?Math.cos(Math.atan2(e.y,e.x)):1;return{v:r.v.lerp(n.v,i),w:r.w.lerp(n.w,i)}}function E(e,t,n){return{v:new r.Pa4(e/o.m,t/o.m),w:new r.Pa4(-o.R/o.I*t*d,o.R/o.I*(e*d-n*v),o.R/o.I*t*v)}}function S(e,t){var n=Math.atan2(-e.x,e.y),r=2.5*t.length()*(e.length()*o.R)/(o.R*o.R),s=t.clone().normalize();return(0,i.a1)(s).applyAxisAngle(s,n).multiplyScalar(r)}},"./src/utils/utils.ts":(e,t,n)=>{n.d(t,{$2:()=>y,AA:()=>p,Bh:()=>s,KO:()=>u,Ls:()=>f,NM:()=>d,Xp:()=>v,a1:()=>l,bM:()=>i,up:()=>o,wK:()=>m});var r=n("./node_modules/three/build/three.module.js"),i=new r.Pa4(0,0,0),o=new r.Pa4(0,0,1);function s(e){return new r.Pa4(e.x,e.y,e.z)}var a=new r.Pa4;function l(e){return a.copy(o).cross(e)}var c=new r.Pa4;function u(e){return c.copy(e).normalize()}var h=new r.Pa4;function f(e,t){return 0>=h.copy(e).add(t).dot(e)}function p(e){return new r.Pa4(1,0,0).applyAxisAngle(o,e)}function d(e){return Math.sign(e)*Math.floor((Math.abs(e)+Number.EPSILON)*1e4)/1e4}function v(e){return Math.round((e+Number.EPSILON)*100)/100}function m(e){return e.x=d(e.x),e.y=d(e.y),e.z=d(e.z),e}function y(e){return e.x=v(e.x),e.y=v(e.y),e.z=v(e.z),e}},"./src/view/cameratop.ts":(e,t,n)=>{n.d(t,{c:()=>a});var r=n("./node_modules/three/build/three.module.js"),i=n("./src/view/tablegeometry.ts"),o=n("./src/model/physics/constants.ts");function s(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"viewPoint",value:function(e,n){var s=t.zoomFactor/(2*Math.tan(n*Math.PI/360));if(e>this.portrait){var a=e>t.aspectLimit?2.75*i.H.tableY:2.4*i.H.tableX/e;return new r.Pa4(0,-.01*o.R,s*a)}var l=e>1/t.aspectLimit?4.9*i.H.tableY:1.35*i.H.tableX/e;return new r.Pa4(-.01*o.R,0,s*l)}}],function(e,t){for(var n=0;n{n.d(t,{N:()=>d});var r=n("./src/view/tablegeometry.ts"),i=n("./src/utils/utils.ts"),o=n("./src/events/aimevent.ts"),s=n("./src/model/ball.ts"),a=n("./src/model/physics/physics.ts"),l=n("./src/model/physics/constants.ts"),c=n("./node_modules/three/build/three.module.js");function u(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var h=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"createHelper",value:function(){var e=new c.fHI(l.R,l.R,30*l.R/.5,12,1,!0),t=new c.Kj0(e,this.helpermaterial);return t.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(i.up,-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(15*l.R/.5,0,-(.01*l.R)/.5)),t.visible=!1,t.renderOrder=-1,t.material.depthTest=!1,t}},{key:"createPlacer",value:function(){var e=new c.fHI(.01*l.R/.5,l.R,l.R,4),n=new c.Kj0(e,t.helpermaterial);return n.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(new c.Pa4(1,0,0),-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(0,0,.7*l.R/.5)),n.visible=!1,n}},{key:"createCue",value:function(e,n,r){var o=new c.fHI(e,n,r,11),s=new c.Kj0(o,t.material);return s.castShadow=!1,s.geometry.applyMatrix4(new c.yGw().identity().makeRotationAxis(new c.Pa4(1,0,0),-.1)).applyMatrix4(new c.yGw().identity().makeRotationAxis(i.up,-Math.PI/2)).applyMatrix4(new c.yGw().identity().makeTranslation(-r/2-l.R,0,2*l.R)),s}}],function(e,t){for(var n=0;nthis.offCenterLimit&&e.normalize().multiplyScalar(this.offCenterLimit),this.aim.offset=(0,i.$2)(e),this.updateAimInput()}},{key:"updateAimInput",value:function(){var e,t;null===(e=this.aimInputs)||void 0===e||e.updateVisualState(this.aim.offset.x,this.aim.offset.y),null===(t=this.aimInputs)||void 0===t||t.updatePowerSlider(this.aim.power/this.maxPower)}},{key:"moveTo",value:function(e){this.aim.pos.copy(e),this.mesh.rotation.z=this.aim.angle,this.helperMesh.rotation.z=this.aim.angle;var t=(0,i.a1)((0,i.AA)(this.aim.angle)).multiplyScalar(2*this.aim.offset.x*l.R).setZ(2*this.aim.offset.y*l.R),n=(Math.sin(this.t+Math.PI/2)-1)*3*l.R*(this.aim.power/this.maxPower),r=(0,i.AA)(this.aim.angle).clone().multiplyScalar(n);this.mesh.position.copy(e.clone().add(t).add(r)),this.helperMesh.position.copy(e),this.placerMesh.position.copy(e),this.placerMesh.rotation.z=this.t}},{key:"update",value:function(e){this.t+=e,this.moveTo(this.aim.pos)}},{key:"placeBallMode",value:function(){this.mesh.visible=!1,this.placerMesh.visible=!0,this.aim.angle=0}},{key:"aimMode",value:function(){this.mesh.visible=!0,this.placerMesh.visible=!1}},{key:"intersectsAnything",value:function(e){var t=e.cueball.pos.clone().addScaledVector((0,i.AA)(this.aim.angle),-this.length/2);t.z=this.aim.offset.y;var n=(0,i.AA)(this.aim.angle);return new c.iMs(t,n,0,this.length/2-.6).intersectObjects(e.balls.map(function(e){return e.ballmesh.mesh})).length>0}},{key:"showHelper",value:function(e){this.helperMesh.visible=e}},{key:"toggleHelper",value:function(){this.showHelper(!this.helperMesh.visible)}}],f(n.prototype,e),t&&f(n,t),n}()},"./src/view/sliders.ts":(e,t,n)=>{n.d(t,{E:()=>s});var r=n("./src/model/physics/constants.ts");function i(e,t){for(var n=0;n3&&void 0!==arguments[3]?arguments[3]:1,i=this,o=this.getInputElement(e);o.step="0.001",o.min="0.01",o.max="".concat(r),o.value=t,this.showValue(e,t),o.oninput=function(t){var r=parseFloat(t.target.value);n(r),i.showValue(e,r),i.notify()}}},{key:"showValue",value:function(e,t){var n=document.querySelector("label[for=".concat(e,"]"));n&&(n.innerHTML="".concat(e,"=").concat(t))}}],i(n.prototype,e),t&&i(n,t),n}()},"./src/view/tablegeometry.ts":(e,t,n)=>{n.d(t,{H:()=>o});var r=n("./src/model/physics/constants.ts");function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=function(){var e;function t(){!function(e,t){if(!(e instanceof t))throw TypeError("Cannot call a class as a function")}(this,t)}return e=[{key:"scaleToRadius",value:function(e){t.tableX=43*e,t.tableY=21*e,t.X=t.tableX+e,t.Y=t.tableY+e}}],function(e,t){for(var n=0;n{e(e.s="./src/index.ts")}]); \ No newline at end of file diff --git a/src/events/keyboard.ts b/src/events/keyboard.ts index 1aab5910..f8ec506d 100644 --- a/src/events/keyboard.ts +++ b/src/events/keyboard.ts @@ -61,16 +61,15 @@ export class Keyboard { } mousetouch = (e) => { + const k = this.released const factor = e.ctrlKey ? 0.5 : 1 const dx = e.dx * factor - const dy = e.dy * factor - if (Math.abs(dy) > 3 * Math.abs(dx)) { - const cy = this.released["movementY"] ?? 0.0 - this.released["movementY"] = cy + dy - return + const dy = e.dy * 0.8 + k["movementY"] = (k["movementY"] ?? 0.0) + dy + k["movementX"] = (k["movementX"] ?? 0.0) + dx + if (Math.abs(k["movementX"]) > Math.abs(k["movementY"])) { + k["movementY"] = 0 } - const cx = this.released["movementX"] ?? 0.0 - this.released["movementX"] = cx + dx } private addHandlers(element: HTMLCanvasElement) {