gl-draw 0.9.0-beta.1 → 0.9.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/Control.d.ts +1 -1
- package/dist/core/Pencil.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/index.module.js +59 -59
- package/package.json +1 -1
package/dist/core/Control.d.ts
CHANGED
package/dist/core/Pencil.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var X=Object.defineProperty,Y=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var j=Object.getOwnPropertySymbols;var $=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var z=(n,e,t)=>e in n?X(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,P=(n,e)=>{for(var t in e||(e={}))$.call(e,t)&&z(n,t,e[t]);if(j)for(var t of j(e))J.call(e,t)&&z(n,t,e[t]);return n},M=(n,e)=>Y(n,Z(e));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Q=require("three"),ee=require("deepmerge"),te=require("three/examples/jsm/libs/stats.module"),ne=require("lil-gui"),se=require("./disposeMesh.js");require("idb-keyval");const A=require("three/examples/jsm/controls/OrbitControls"),re=require("three/examples/jsm/renderers/CSS3DRenderer"),ie=require("three/examples/jsm/renderers/CSS2DRenderer"),C=require("postprocessing"),oe=require("./isPlainObject.js"),ae=require("./BaseObject.js");require("./makePromiseCreator.js");function ce(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const d=ce(Q);var x={},le={get exports(){return x},set exports(n){x=n}},y=typeof Reflect=="object"?Reflect:null,D=y&&typeof y.apply=="function"?y.apply:function(e,t,s){return Function.prototype.apply.call(e,t,s)},L;y&&typeof y.ownKeys=="function"?L=y.ownKeys:Object.getOwnPropertySymbols?L=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:L=function(e){return Object.getOwnPropertyNames(e)};function de(n){console&&console.warn&&console.warn(n)}var I=Number.isNaN||function(e){return e!==e};function l(){l.init.call(this)}le.exports=l;x.once=me;l.EventEmitter=l;l.prototype._events=void 0;l.prototype._eventsCount=0;l.prototype._maxListeners=void 0;var T=10;function R(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(l,"defaultMaxListeners",{enumerable:!0,get:function(){return T},set:function(n){if(typeof n!="number"||n<0||I(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");T=n}});l.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};l.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||I(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function N(n){return n._maxListeners===void 0?l.defaultMaxListeners:n._maxListeners}l.prototype.getMaxListeners=function(){return N(this)};l.prototype.emit=function(e){for(var t=[],s=1;s<arguments.length;s++)t.push(arguments[s]);var r=e==="error",o=this._events;if(o!==void 0)r=r&&o.error===void 0;else if(!r)return!1;if(r){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var c=o[e];if(c===void 0)return!1;if(typeof c=="function")D(c,this,t);else for(var u=c.length,f=H(c,u),s=0;s<u;++s)D(f[s],this,t);return!0};function F(n,e,t,s){var r,o,i;if(R(t),o=n._events,o===void 0?(o=n._events=Object.create(null),n._eventsCount=0):(o.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),o=n._events),i=o[e]),i===void 0)i=o[e]=t,++n._eventsCount;else if(typeof i=="function"?i=o[e]=s?[t,i]:[i,t]:s?i.unshift(t):i.push(t),r=N(n),r>0&&i.length>r&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=i.length,de(a)}return n}l.prototype.addListener=function(e,t){return F(this,e,t,!1)};l.prototype.on=l.prototype.addListener;l.prototype.prependListener=function(e,t){return F(this,e,t,!0)};function fe(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function q(n,e,t){var s={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},r=fe.bind(s);return r.listener=t,s.wrapFn=r,r}l.prototype.once=function(e,t){return R(t),this.on(e,q(this,e,t)),this};l.prototype.prependOnceListener=function(e,t){return R(t),this.prependListener(e,q(this,e,t)),this};l.prototype.removeListener=function(e,t){var s,r,o,i,a;if(R(t),r=this._events,r===void 0)return this;if(s=r[e],s===void 0)return this;if(s===t||s.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,s.listener||t));else if(typeof s!="function"){for(o=-1,i=s.length-1;i>=0;i--)if(s[i]===t||s[i].listener===t){a=s[i].listener,o=i;break}if(o<0)return this;o===0?s.shift():ue(s,o),s.length===1&&(r[e]=s[0]),r.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};l.prototype.off=l.prototype.removeListener;l.prototype.removeAllListeners=function(e){var t,s,r;if(s=this._events,s===void 0)return this;if(s.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):s[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete s[e]),this;if(arguments.length===0){var o=Object.keys(s),i;for(r=0;r<o.length;++r)i=o[r],i!=="removeListener"&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=s[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function k(n,e,t){var s=n._events;if(s===void 0)return[];var r=s[e];return r===void 0?[]:typeof r=="function"?t?[r.listener||r]:[r]:t?he(r):H(r,r.length)}l.prototype.listeners=function(e){return k(this,e,!0)};l.prototype.rawListeners=function(e){return k(this,e,!1)};l.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):V.call(n,e)};l.prototype.listenerCount=V;function V(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}l.prototype.eventNames=function(){return this._eventsCount>0?L(this._events):[]};function H(n,e){for(var t=new Array(e),s=0;s<e;++s)t[s]=n[s];return t}function ue(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function he(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function me(n,e){return new Promise(function(t,s){function r(i){n.removeListener(e,o),s(i)}function o(){typeof n.removeListener=="function"&&n.removeListener("error",r),t([].slice.call(arguments))}W(n,e,o,{once:!0}),e!=="error"&&pe(n,r,{once:!0})})}function pe(n,e,t){typeof n.on=="function"&&W(n,"error",e,t)}function W(n,e,t,s){if(typeof n.on=="function")s.once?n.once(e,t):n.on(e,t);else if(typeof n.addEventListener=="function")n.addEventListener(e,function r(o){s.once&&n.removeEventListener(e,r),t(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}class S{constructor(e){this.guiParams={},e&&(this.guiParams=e)}showGui(e){e&&Object.keys(this.guiParams).forEach(t=>{const s=e.addFolder(t),r=this.guiParams[t];Object.keys(r).forEach(o=>{const{min:i,max:a,step:c,name:u,paramMap:f,items:m,value:p,target:g}=r[o],O=o.toLowerCase().indexOf("color")>-1;let h;const w=typeof p=="undefined"&&g,b=w?g():r[o],v=w?o:"value";m?h=s.add(b,v,m):O?h=s.addColor(b,v):h=s.add(b,v),h=h.name(u||o),typeof i!="undefined"&&(h=h.min(i)),typeof a!="undefined"&&(h=h.max(a)),typeof c!="undefined"&&(h=h.step(c)),h=h.onChange(()=>{this.setTargetValue(t,o,b[v],f)}),w&&h.listen()})})}setTargetValue(e,t,s,r){const{onChange:o,target:i,value:a}=this.guiParams[e][t],c=t.toLowerCase().indexOf("color")>-1;if(i&&!(typeof a=="undefined"&&i)){let f=i();Array.isArray(f)||(f=[f]),f.forEach(m=>{if(m)if(c)try{m[r||t].set(s)}catch(p){t!=="color"&&!r&&console.warn(`${t} is not a color,set paramMap`)}else m[r||t]=s})}o&&o(s)}setTargetValueByParams(){Object.keys(this.guiParams).forEach(e=>{Object.keys(this.guiParams[e]).forEach(t=>{const s=this.guiParams[e][t];typeof s.value!="undefined"&&this.setTargetValue(e,t,s.value,s.paramMap)})})}}const B={None:d.NoToneMapping,Linear:d.LinearToneMapping,Reinhard:d.ReinhardToneMapping,Cineon:d.CineonToneMapping,ACESFilmic:d.ACESFilmicToneMapping},ve={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMapping:"None",toneMappingExposure:1,alpha:!1,outputEncoding:d.LinearEncoding,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,context:null,stencil:!1,depth:!1,physicallyCorrectLights:!1};class ge{constructor(e){this.options=e;const{width:t,height:s,rendererParams:r}=e,{context:o,alpha:i,devicePixelRatio:a,antialias:c,powerPreference:u,toneMapping:f,toneMappingExposure:m,outputEncoding:p,logarithmicDepthBuffer:g,preserveDrawingBuffer:O,stencil:h,depth:w,physicallyCorrectLights:b}=r,v=new d.WebGLRenderer({context:o,alpha:i,antialias:c,powerPreference:u,logarithmicDepthBuffer:g,preserveDrawingBuffer:O,stencil:h,depth:w});v.setSize(t,s),v.setPixelRatio(a),v.toneMapping=B[f],v.toneMappingExposure=m,v.outputEncoding=p,v.physicallyCorrectLights=b,this.renderer=v}setSize(e,t){this.renderer.setSize(e,t)}render(){const{scene:e,camera:t}=this.options;this.renderer.render(e,t)}setGui(e){new S({renderer:{toneMapping:{value:this.options.rendererParams.toneMapping,items:B,target:()=>this.renderer},toneMappingExposure:{value:this.options.rendererParams.toneMappingExposure,min:0,max:16,target:()=>this.renderer}}}).showGui(e)}dispose(){var e,t,s;(e=this.renderer)==null||e.clear(),(t=this.renderer)==null||t.dispose(),(s=this.renderer)==null||s.renderLists.dispose()}}const Ce={fov:45,near:1,far:1e3};class be{constructor(e){this.oldCameraPosition=new d.Vector3,this.oldCameraRotation=new d.Euler,this.customCamera=!1,this.options=e;const{width:t,height:s,cameraParams:r}=e;if(r instanceof d.Camera)this.camera=r,this.customCamera=!0;else{const{fov:o,far:i,near:a}=r,c=new d.PerspectiveCamera(o,t/s,a,i);c.position.set(0,0,400),c.lookAt(0,0,0),this.camera=c}}checkCameraChange(){const e=this.camera,t=this.oldCameraPosition.equals(e.position)&&this.oldCameraRotation.equals(e.rotation);return this.oldCameraPosition=e.position.clone(),this.oldCameraRotation=e.rotation.clone(),!t}setSize(e,t){this.camera instanceof d.PerspectiveCamera&&(this.camera.aspect=e/t),this.camera.updateProjectionMatrix()}setGui(e){const t=new S({camera:{x:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},y:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},z:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},near:{min:0,max:1e3,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}},far:{min:0,max:2e4,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}}});this.camera instanceof d.PerspectiveCamera&&(t.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),t.showGui(e)}}const Pe={background:null};class ye{constructor(e){this.options=e;const{camera:t,sceneParams:s}=e,{background:r}=s,o=new d.Scene;r&&(o.background=r),o.add(t),this.scene=o}addAxesHelper(){var t;const e=new d.AxesHelper(100);(t=this.scene)==null||t.add(e)}dispose(){var e;(e=this.scene)==null||e.traverse(t=>{se.disposeMesh(t)})}}class we{constructor(e){this.options=e;const{camera:t,controlParams:s,mapControl:r}=e,{domElement:o}=s,i=r?new A.MapControls(t,o):new A.OrbitControls(t,o);i.minPolarAngle=Math.PI*.15,i.maxPolarAngle=Math.PI*.85,i.enableDamping=!0,i.dampingFactor=.063,i.autoRotate=!1,i.autoRotateSpeed=-60,i.enableZoom=!0,i.zoomSpeed=.2,this.control=i}limitPan({maxX:e=1/0,minX:t=-1/0,maxZ:s=1/0,minZ:r=-1/0,maxY:o=1/0,minY:i=-1/0}){const a=this.limitPanV||new d.Vector3,c=this.control,{camera:u}=this.options,f=new d.Vector3(t,i,r),m=new d.Vector3(e,o,s);this.limitPanV=a,a.copy(c.target),c.target.clamp(f,m),a.sub(c.target),u.position.sub(a)}update(){this.control.update()}dispose(){this.control.dispose()}}const G={zIndex:"auto"};class Ee{constructor(e){this.container=e}addRenderer(e,t){const{container:s}=this,r=s.offsetWidth,o=s.offsetHeight,i=e==="css2d"?new ie.CSS2DRenderer:new re.CSS3DRenderer;i.domElement.style.position="absolute",i.domElement.style.top="0",i.domElement.style.pointerEvents="none",i.domElement.style.zIndex=t.zIndex,i.setSize(r,o),s.appendChild(i.domElement),e==="css2d"?this.css2Drenderer=i:e==="css3d"&&(this.css3Drenderer=i)}setSize(e,t){var s,r;(s=this.css2Drenderer)==null||s.setSize(e,t),(r=this.css3Drenderer)==null||r.setSize(e,t)}render(e,t){var s,r;(s=this.css2Drenderer)==null||s.render(e,t),(r=this.css3Drenderer)==null||r.render(e,t)}dispose(){this.css2Drenderer=void 0,this.css3Drenderer=void 0}}const Le={luminanceThreshold:.1,luminanceSmoothing:.3,mipmapBlur:!0,intensity:4};class xe{constructor(e){this.active=!0,this.options=e;const{renderer:t,scene:s,camera:r,composerParams:o}=e,{multisampling:i}=o,{maxSamples:a}=t.capabilities,c=new C.EffectComposer(t,{multisampling:Math.min(i,a)});c.addPass(new C.RenderPass(s,r)),this.finalComposer=c,this.renderer=t,this.scene=s,this.camera=r}addCopyPass(){const e=new C.CopyPass;e.renderToScreen=!0,this.finalComposer.addPass(e),this.copyPass=e}addFXAAPass(){const{camera:e}=this,t=new C.FXAAEffect({blendFunction:C.BlendFunction.NORMAL}),s=new C.EffectPass(e,t);this.finalComposer.addPass(s),this.fxaaPass=s}addBloomPass(e){const{camera:t,scene:s}=this,r=new C.SelectiveBloomEffect(s,t,P({},e)),o=new C.EffectPass(t,r);o.enabled=!1,this.finalComposer.addPass(o),this.bloomPass=o,this.bloomEffect=r}addBloomGui(e){if(!this.bloomEffect)return;new S({bloom:{intensity:{min:0,max:10,step:.01,target:()=>this.bloomEffect}},bloomLuminanceFilter:{enabled:{value:this.bloomEffect.luminancePass.enabled,onChange:s=>{this.bloomEffect.luminancePass.enabled=s}},threshold:{min:0,max:1,step:.01,target:()=>this.bloomEffect.luminanceMaterial},smoothing:{min:0,max:1,step:.01,target:()=>this.bloomEffect.luminanceMaterial}}}).showGui(e)}toggleBloomSelection(e){if(!this.bloomEffect||!this.bloomPass){console.warn("err:pencil.options.bloom");return}this.bloomEffect.selection.toggle(e),this.bloomPass.enabled=!!this.bloomEffect.selection.size}getSize(){const{renderer:e}=this.options;return e.getSize(new d.Vector2)}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(e,t){this.finalComposer.setSize(e,t)}render(){this.active&&this.finalComposer.render()}dispose(){this.finalComposer.dispose()}}const Re=()=>{try{const n=document.createElement("canvas");return!!(window.WebGL2RenderingContext&&n.getContext("webgl2"))}catch(n){return!1}},E=!1,U=Re()!==!1,K=class{constructor(n){this.raycaster=new d.Raycaster,this.installPlugins=new Map,this.event=new x.EventEmitter,this.clock=new d.Clock,this.userData={},this.options=ee(K.options,n,{isMergeableObject:oe.isPlainObject});const{container:e,stats:t,gui:s,resizeObserver:r}=this.options;if(s){const o=new ne;o.open(!1),this.gui=o}if(t){const o=new te;o.showPanel(0),o.dom.style.position="absolute",e.appendChild(o.dom),this.stats=o}this.init(),this.initComposer(),this.initCSSRenderer(),this.initControl(),r&&this.initResizeObserver(),this.clock.getDelta(),this.clock.getElapsedTime()}get renderer(){return this.rendererController.renderer}get control(){var n;return(n=this.controlController)==null?void 0:n.control}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}use(n,...e){this.installPlugins.has(n)?console.log("plugin already installed"):typeof n.install=="function"&&(n.install(this,...e),this.installPlugins.set(n,!0))}init(){const{container:n,isdev:e,axesHelper:t,renderer:s,scene:r,camera:o}=this.options,{width:i,height:a}=this.getSize(),c=new be({isdev:e,width:i,height:a,cameraParams:o});this.gui&&c.setGui(this.gui);const u=c.camera,f=new ye({camera:u,sceneParams:r}),m=f.scene,p=new ge({width:i,height:a,scene:m,camera:u,isdev:e,rendererParams:M(P({},s),{antialias:!1})});this.gui&&p.setGui(this.gui);const g=p.renderer;t&&f.addAxesHelper(),this.sceneController=f,this.rendererController=p,this.cameraController=c,n.appendChild(g.domElement)}initComposer(){const{bloom:n,bloomParams:e,renderer:t,multisampling:s,passes:r}=this.options;let{antialias:o}=t;o==="msaa"&&!U&&(o=!1,console.warn("MSAA is not supported on this browser"));const i=new xe({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:{multisampling:o==="msaa"?s:0,type:d.UnsignedByteType,encoding:t.outputEncoding}});this.composerController=i,n&&(i.addBloomPass(e),this.gui&&i.addBloomGui(this.gui)),o==="fxaa"&&i.addFXAAPass(),r&&r.forEach(a=>{i.finalComposer.addPass(a)}),i.addCopyPass()}initCSSRenderer(){const{container:n,css2DRenderer:e,css3DRenderer:t,css2DRendererParams:s,css3DRendererParams:r}=this.options;if(e||t){const o=new Ee(n);e&&o.addRenderer("css2d",s),t&&o.addRenderer("css3d",r),this.cssRendererController=o}}initControl(){const{control:n,mapControl:e,controlParams:t}=this.options;if(n){const s=new we({camera:this.camera,controlParams:{domElement:(t==null?void 0:t.domElement)||this.renderer.domElement},mapControl:e});this.controlController=s}}getSize(){const{container:n}=this.options;return{width:n.offsetWidth,height:n.offsetHeight}}initResizeObserver(){const{container:n}=this.options;if(this.resizeObserver)return;const e=new ResizeObserver(t=>{for(const s of t){const r=s.contentRect;this.handeleResize(r.width,r.height),this.render()}});e.observe(n),this.resizeObserver=e}handeleResize(n,e){const{rendererController:t,cameraController:s,composerController:r,cssRendererController:o}=this;s==null||s.setSize(n,e),t==null||t.setSize(n,e),r==null||r.setSize(n,e),o==null||o.setSize(n,e),this.installPlugins.forEach((i,a)=>{var c;(c=a.setSize)==null||c.call(a,n,e)}),this.event.emit("resize",{width:n,height:e})}pick(n,e,t=!1){const{raycaster:s,options:r}=this,{container:o}=r,i=new d.Vector2,a=o.getBoundingClientRect();if(i.x=(n.clientX-a.left)/(a.right-a.left)*2-1,i.y=-((n.clientY-a.top)/(a.bottom-a.top))*2+1,this.camera&&this.scene){s.setFromCamera(i,this.camera);const c=s.intersectObjects(e||this.scene.children,t);if(c.length)return{object:c[0].object,intersects:c}}}render(){var i,a,c,u,f;const{renderer:n,scene:e,camera:t,clock:s}=this;if(!n||!e||!t||this.options.staticRender&&!this.cameraController.checkCameraChange())return;const r=s.getDelta(),o=s.getElapsedTime();(i=this.controlController)==null||i.update(),this.installPlugins.forEach((m,p)=>{var g;(g=p.update)==null||g.call(p,r,o)}),(a=this.composerController)!=null&&a.active?this.composerController.render():(c=this.rendererController)==null||c.render(),(u=this.cssRendererController)==null||u.render(e,t),(f=this.stats)==null||f.update(),this.event.emit("render",{delta:r,elapsed:o})}start(){this.renderer.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){this.renderer.setAnimationLoop(null),this.event.emit("stop")}dispose(){var n,e,t,s,r,o,i;this.stop(),this.handeleResize(0,0),(n=this.resizeObserver)==null||n.unobserve(this.options.container),this.installPlugins.forEach((a,c)=>{var u;(u=c.dispose)==null||u.call(c)}),(e=this.controlController)==null||e.dispose(),(t=this.cssRendererController)==null||t.dispose(),(s=this.sceneController)==null||s.dispose(),(r=this.composerController)==null||r.dispose(),(o=this.rendererController)==null||o.dispose(),this.controlController=void 0,this.cssRendererController=void 0,(i=this.gui)==null||i.destroy(),this.event.removeAllListeners(),this.installPlugins.clear()}};let _=K;_.options={isdev:E,stats:E,gui:E,axesHelper:E,control:E,resizeObserver:!0,renderer:M(P({},ve),{antialias:U?"msaa":"fxaa"}),staticRender:!1,multisampling:4,scene:Pe,camera:Ce,bloom:!1,bloomParams:Le,css2DRenderer:!1,css2DRendererParams:P({},G),css3DRenderer:!1,css3DRendererParams:P({},G)};exports.BaseObject=ae.BaseObject;exports.GUIObject=S;exports.Pencil=_;exports.default=_;
|
|
1
|
+
"use strict";var K=Object.defineProperty,X=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var j=Object.getOwnPropertySymbols;var Z=Object.prototype.hasOwnProperty,$=Object.prototype.propertyIsEnumerable;var z=(n,e,t)=>e in n?K(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,P=(n,e)=>{for(var t in e||(e={}))Z.call(e,t)&&z(n,t,e[t]);if(j)for(var t of j(e))$.call(e,t)&&z(n,t,e[t]);return n},M=(n,e)=>X(n,Y(e));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const J=require("three"),Q=require("deepmerge"),ee=require("three/examples/jsm/libs/stats.module"),te=require("lil-gui"),ne=require("./disposeMesh.js");require("idb-keyval");const se=require("three/examples/jsm/controls/OrbitControls"),re=require("three/examples/jsm/renderers/CSS3DRenderer"),ie=require("three/examples/jsm/renderers/CSS2DRenderer"),C=require("postprocessing"),oe=require("./isPlainObject.js"),ae=require("./BaseObject.js");require("./makePromiseCreator.js");function ce(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const d=ce(J);var x={},le={get exports(){return x},set exports(n){x=n}},y=typeof Reflect=="object"?Reflect:null,A=y&&typeof y.apply=="function"?y.apply:function(e,t,s){return Function.prototype.apply.call(e,t,s)},L;y&&typeof y.ownKeys=="function"?L=y.ownKeys:Object.getOwnPropertySymbols?L=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:L=function(e){return Object.getOwnPropertyNames(e)};function de(n){console&&console.warn&&console.warn(n)}var G=Number.isNaN||function(e){return e!==e};function l(){l.init.call(this)}le.exports=l;x.once=me;l.EventEmitter=l;l.prototype._events=void 0;l.prototype._eventsCount=0;l.prototype._maxListeners=void 0;var D=10;function R(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(l,"defaultMaxListeners",{enumerable:!0,get:function(){return D},set:function(n){if(typeof n!="number"||n<0||G(n))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+n+".");D=n}});l.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};l.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||G(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function I(n){return n._maxListeners===void 0?l.defaultMaxListeners:n._maxListeners}l.prototype.getMaxListeners=function(){return I(this)};l.prototype.emit=function(e){for(var t=[],s=1;s<arguments.length;s++)t.push(arguments[s]);var r=e==="error",o=this._events;if(o!==void 0)r=r&&o.error===void 0;else if(!r)return!1;if(r){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var c=o[e];if(c===void 0)return!1;if(typeof c=="function")A(c,this,t);else for(var u=c.length,f=V(c,u),s=0;s<u;++s)A(f[s],this,t);return!0};function N(n,e,t,s){var r,o,i;if(R(t),o=n._events,o===void 0?(o=n._events=Object.create(null),n._eventsCount=0):(o.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),o=n._events),i=o[e]),i===void 0)i=o[e]=t,++n._eventsCount;else if(typeof i=="function"?i=o[e]=s?[t,i]:[i,t]:s?i.unshift(t):i.push(t),r=I(n),r>0&&i.length>r&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=i.length,de(a)}return n}l.prototype.addListener=function(e,t){return N(this,e,t,!1)};l.prototype.on=l.prototype.addListener;l.prototype.prependListener=function(e,t){return N(this,e,t,!0)};function fe(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function F(n,e,t){var s={fired:!1,wrapFn:void 0,target:n,type:e,listener:t},r=fe.bind(s);return r.listener=t,s.wrapFn=r,r}l.prototype.once=function(e,t){return R(t),this.on(e,F(this,e,t)),this};l.prototype.prependOnceListener=function(e,t){return R(t),this.prependListener(e,F(this,e,t)),this};l.prototype.removeListener=function(e,t){var s,r,o,i,a;if(R(t),r=this._events,r===void 0)return this;if(s=r[e],s===void 0)return this;if(s===t||s.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,s.listener||t));else if(typeof s!="function"){for(o=-1,i=s.length-1;i>=0;i--)if(s[i]===t||s[i].listener===t){a=s[i].listener,o=i;break}if(o<0)return this;o===0?s.shift():ue(s,o),s.length===1&&(r[e]=s[0]),r.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};l.prototype.off=l.prototype.removeListener;l.prototype.removeAllListeners=function(e){var t,s,r;if(s=this._events,s===void 0)return this;if(s.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):s[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete s[e]),this;if(arguments.length===0){var o=Object.keys(s),i;for(r=0;r<o.length;++r)i=o[r],i!=="removeListener"&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=s[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function q(n,e,t){var s=n._events;if(s===void 0)return[];var r=s[e];return r===void 0?[]:typeof r=="function"?t?[r.listener||r]:[r]:t?he(r):V(r,r.length)}l.prototype.listeners=function(e){return q(this,e,!0)};l.prototype.rawListeners=function(e){return q(this,e,!1)};l.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):k.call(n,e)};l.prototype.listenerCount=k;function k(n){var e=this._events;if(e!==void 0){var t=e[n];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}l.prototype.eventNames=function(){return this._eventsCount>0?L(this._events):[]};function V(n,e){for(var t=new Array(e),s=0;s<e;++s)t[s]=n[s];return t}function ue(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function he(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function me(n,e){return new Promise(function(t,s){function r(i){n.removeListener(e,o),s(i)}function o(){typeof n.removeListener=="function"&&n.removeListener("error",r),t([].slice.call(arguments))}H(n,e,o,{once:!0}),e!=="error"&&pe(n,r,{once:!0})})}function pe(n,e,t){typeof n.on=="function"&&H(n,"error",e,t)}function H(n,e,t,s){if(typeof n.on=="function")s.once?n.once(e,t):n.on(e,t);else if(typeof n.addEventListener=="function")n.addEventListener(e,function r(o){s.once&&n.removeEventListener(e,r),t(o)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}class S{constructor(e){this.guiParams={},e&&(this.guiParams=e)}showGui(e){e&&Object.keys(this.guiParams).forEach(t=>{const s=e.addFolder(t),r=this.guiParams[t];Object.keys(r).forEach(o=>{const{min:i,max:a,step:c,name:u,paramMap:f,items:m,value:p,target:g}=r[o],O=o.toLowerCase().indexOf("color")>-1;let h;const w=typeof p=="undefined"&&g,b=w?g():r[o],v=w?o:"value";m?h=s.add(b,v,m):O?h=s.addColor(b,v):h=s.add(b,v),h=h.name(u||o),typeof i!="undefined"&&(h=h.min(i)),typeof a!="undefined"&&(h=h.max(a)),typeof c!="undefined"&&(h=h.step(c)),h=h.onChange(()=>{this.setTargetValue(t,o,b[v],f)}),w&&h.listen()})})}setTargetValue(e,t,s,r){const{onChange:o,target:i,value:a}=this.guiParams[e][t],c=t.toLowerCase().indexOf("color")>-1;if(i&&!(typeof a=="undefined"&&i)){let f=i();Array.isArray(f)||(f=[f]),f.forEach(m=>{if(m)if(c)try{m[r||t].set(s)}catch(p){t!=="color"&&!r&&console.warn(`${t} is not a color,set paramMap`)}else m[r||t]=s})}o&&o(s)}setTargetValueByParams(){Object.keys(this.guiParams).forEach(e=>{Object.keys(this.guiParams[e]).forEach(t=>{const s=this.guiParams[e][t];typeof s.value!="undefined"&&this.setTargetValue(e,t,s.value,s.paramMap)})})}}const T={None:d.NoToneMapping,Linear:d.LinearToneMapping,Reinhard:d.ReinhardToneMapping,Cineon:d.CineonToneMapping,ACESFilmic:d.ACESFilmicToneMapping},ve={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMapping:"None",toneMappingExposure:1,alpha:!1,outputEncoding:d.LinearEncoding,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,context:null,stencil:!1,depth:!1,physicallyCorrectLights:!1};class ge{constructor(e){this.options=e;const{width:t,height:s,rendererParams:r}=e,{context:o,alpha:i,devicePixelRatio:a,antialias:c,powerPreference:u,toneMapping:f,toneMappingExposure:m,outputEncoding:p,logarithmicDepthBuffer:g,preserveDrawingBuffer:O,stencil:h,depth:w,physicallyCorrectLights:b}=r,v=new d.WebGLRenderer({context:o,alpha:i,antialias:c,powerPreference:u,logarithmicDepthBuffer:g,preserveDrawingBuffer:O,stencil:h,depth:w});v.setSize(t,s),v.setPixelRatio(a),v.toneMapping=T[f],v.toneMappingExposure=m,v.outputEncoding=p,v.physicallyCorrectLights=b,this.renderer=v}setSize(e,t){this.renderer.setSize(e,t)}render(){const{scene:e,camera:t}=this.options;this.renderer.render(e,t)}setGui(e){new S({renderer:{toneMapping:{value:this.options.rendererParams.toneMapping,items:T,target:()=>this.renderer},toneMappingExposure:{value:this.options.rendererParams.toneMappingExposure,min:0,max:16,target:()=>this.renderer}}}).showGui(e)}dispose(){var e,t,s;(e=this.renderer)==null||e.clear(),(t=this.renderer)==null||t.dispose(),(s=this.renderer)==null||s.renderLists.dispose()}}const Ce={fov:45,near:1,far:1e3};class be{constructor(e){this.oldCameraPosition=new d.Vector3,this.oldCameraRotation=new d.Euler,this.customCamera=!1,this.options=e;const{width:t,height:s,cameraParams:r}=e;if(r instanceof d.Camera)this.camera=r,this.customCamera=!0;else{const{fov:o,far:i,near:a}=r,c=new d.PerspectiveCamera(o,t/s,a,i);c.position.set(0,0,400),c.lookAt(0,0,0),this.camera=c}}checkCameraChange(){const e=this.camera,t=this.oldCameraPosition.equals(e.position)&&this.oldCameraRotation.equals(e.rotation);return this.oldCameraPosition=e.position.clone(),this.oldCameraRotation=e.rotation.clone(),!t}setSize(e,t){this.camera instanceof d.PerspectiveCamera&&(this.camera.aspect=e/t),this.camera.updateProjectionMatrix()}setGui(e){const t=new S({camera:{x:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},y:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},z:{min:-1e4,max:1e4,step:1,target:()=>this.camera.position},near:{min:0,max:1e3,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}},far:{min:0,max:2e4,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}}});this.camera instanceof d.PerspectiveCamera&&(t.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),t.showGui(e)}}const Pe={background:null};class ye{constructor(e){this.options=e;const{camera:t,sceneParams:s}=e,{background:r}=s,o=new d.Scene;r&&(o.background=r),o.add(t),this.scene=o}addAxesHelper(){var t;const e=new d.AxesHelper(100);(t=this.scene)==null||t.add(e)}dispose(){var e;(e=this.scene)==null||e.traverse(t=>{ne.disposeMesh(t)})}}class we{constructor(e){this.options=e;const{camera:t,controlParams:s,customControl:r}=e,{domElement:o}=s,i=r?new r(t,o):new se.OrbitControls(t,o);i.minPolarAngle=Math.PI*.15,i.maxPolarAngle=Math.PI*.85,i.enableDamping=!0,i.dampingFactor=.063,i.autoRotate=!1,i.autoRotateSpeed=-60,i.enableZoom=!0,i.zoomSpeed=.2,this.control=i}limitPan({maxX:e=1/0,minX:t=-1/0,maxZ:s=1/0,minZ:r=-1/0,maxY:o=1/0,minY:i=-1/0}){const a=this.limitPanV||new d.Vector3,c=this.control,{camera:u}=this.options,f=new d.Vector3(t,i,r),m=new d.Vector3(e,o,s);this.limitPanV=a,a.copy(c.target),c.target.clamp(f,m),a.sub(c.target),u.position.sub(a)}update(){this.control.update()}dispose(){this.control.dispose()}}const B={zIndex:"auto"};class Ee{constructor(e){this.container=e}addRenderer(e,t){const{container:s}=this,r=s.offsetWidth,o=s.offsetHeight,i=e==="css2d"?new ie.CSS2DRenderer:new re.CSS3DRenderer;i.domElement.style.position="absolute",i.domElement.style.top="0",i.domElement.style.pointerEvents="none",i.domElement.style.zIndex=t.zIndex,i.setSize(r,o),s.appendChild(i.domElement),e==="css2d"?this.css2Drenderer=i:e==="css3d"&&(this.css3Drenderer=i)}setSize(e,t){var s,r;(s=this.css2Drenderer)==null||s.setSize(e,t),(r=this.css3Drenderer)==null||r.setSize(e,t)}render(e,t){var s,r;(s=this.css2Drenderer)==null||s.render(e,t),(r=this.css3Drenderer)==null||r.render(e,t)}dispose(){this.css2Drenderer=void 0,this.css3Drenderer=void 0}}const Le={luminanceThreshold:.1,luminanceSmoothing:.3,mipmapBlur:!0,intensity:4};class xe{constructor(e){this.active=!0,this.options=e;const{renderer:t,scene:s,camera:r,composerParams:o}=e,{multisampling:i}=o,{maxSamples:a}=t.capabilities,c=new C.EffectComposer(t,{multisampling:Math.min(i,a)});c.addPass(new C.RenderPass(s,r)),this.finalComposer=c,this.renderer=t,this.scene=s,this.camera=r}addCopyPass(){const e=new C.CopyPass;e.renderToScreen=!0,this.finalComposer.addPass(e),this.copyPass=e}addFXAAPass(){const{camera:e}=this,t=new C.FXAAEffect({blendFunction:C.BlendFunction.NORMAL}),s=new C.EffectPass(e,t);this.finalComposer.addPass(s),this.fxaaPass=s}addBloomPass(e){const{camera:t,scene:s}=this,r=new C.SelectiveBloomEffect(s,t,P({},e)),o=new C.EffectPass(t,r);o.enabled=!1,this.finalComposer.addPass(o),this.bloomPass=o,this.bloomEffect=r}addBloomGui(e){if(!this.bloomEffect)return;new S({bloom:{intensity:{min:0,max:10,step:.01,target:()=>this.bloomEffect}},bloomLuminanceFilter:{enabled:{value:this.bloomEffect.luminancePass.enabled,onChange:s=>{this.bloomEffect.luminancePass.enabled=s}},threshold:{min:0,max:1,step:.01,target:()=>this.bloomEffect.luminanceMaterial},smoothing:{min:0,max:1,step:.01,target:()=>this.bloomEffect.luminanceMaterial}}}).showGui(e)}toggleBloomSelection(e){if(!this.bloomEffect||!this.bloomPass){console.warn("err:pencil.options.bloom");return}this.bloomEffect.selection.toggle(e),this.bloomPass.enabled=!!this.bloomEffect.selection.size}getSize(){const{renderer:e}=this.options;return e.getSize(new d.Vector2)}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(e,t){this.finalComposer.setSize(e,t)}render(){this.active&&this.finalComposer.render()}dispose(){this.finalComposer.dispose()}}const Re=()=>{try{const n=document.createElement("canvas");return!!(window.WebGL2RenderingContext&&n.getContext("webgl2"))}catch(n){return!1}},E=!1,W=Re()!==!1,U=class{constructor(n){this.raycaster=new d.Raycaster,this.installPlugins=new Map,this.event=new x.EventEmitter,this.clock=new d.Clock,this.userData={},this.options=Q(U.options,n,{isMergeableObject:oe.isPlainObject});const{container:e,stats:t,gui:s,resizeObserver:r}=this.options;if(s){const o=new te;o.open(!1),this.gui=o}if(t){const o=new ee;o.showPanel(0),o.dom.style.position="absolute",e.appendChild(o.dom),this.stats=o}this.init(),this.initComposer(),this.initCSSRenderer(),this.initControl(),r&&this.initResizeObserver(),this.clock.getDelta(),this.clock.getElapsedTime()}get renderer(){return this.rendererController.renderer}get control(){var n;return(n=this.controlController)==null?void 0:n.control}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}use(n,...e){this.installPlugins.has(n)?console.log("plugin already installed"):typeof n.install=="function"&&(n.install(this,...e),this.installPlugins.set(n,!0))}init(){const{container:n,isdev:e,axesHelper:t,renderer:s,scene:r,camera:o}=this.options,{width:i,height:a}=this.getSize(),c=new be({isdev:e,width:i,height:a,cameraParams:o});this.gui&&c.setGui(this.gui);const u=c.camera,f=new ye({camera:u,sceneParams:r}),m=f.scene,p=new ge({width:i,height:a,scene:m,camera:u,isdev:e,rendererParams:M(P({},s),{antialias:!1})});this.gui&&p.setGui(this.gui);const g=p.renderer;t&&f.addAxesHelper(),this.sceneController=f,this.rendererController=p,this.cameraController=c,n.appendChild(g.domElement)}initComposer(){const{bloom:n,bloomParams:e,renderer:t,multisampling:s,passes:r}=this.options;let{antialias:o}=t;o==="msaa"&&!W&&(o=!1,console.warn("MSAA is not supported on this browser"));const i=new xe({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:{multisampling:o==="msaa"?s:0,type:d.UnsignedByteType,encoding:t.outputEncoding}});this.composerController=i,n&&(i.addBloomPass(e),this.gui&&i.addBloomGui(this.gui)),o==="fxaa"&&i.addFXAAPass(),r&&r.forEach(a=>{i.finalComposer.addPass(a)}),i.addCopyPass()}initCSSRenderer(){const{container:n,css2DRenderer:e,css3DRenderer:t,css2DRendererParams:s,css3DRendererParams:r}=this.options;if(e||t){const o=new Ee(n);e&&o.addRenderer("css2d",s),t&&o.addRenderer("css3d",r),this.cssRendererController=o}}initControl(){const{control:n,controlParams:e}=this.options;if(n){const t=new we({camera:this.camera,controlParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControl:typeof n=="boolean"?void 0:n});this.controlController=t}}getSize(){const{container:n}=this.options;return{width:n.offsetWidth,height:n.offsetHeight}}initResizeObserver(){const{container:n}=this.options;if(this.resizeObserver)return;const e=new ResizeObserver(t=>{for(const s of t){const r=s.contentRect;this.handeleResize(r.width,r.height),this.render()}});e.observe(n),this.resizeObserver=e}handeleResize(n,e){const{rendererController:t,cameraController:s,composerController:r,cssRendererController:o}=this;s==null||s.setSize(n,e),t==null||t.setSize(n,e),r==null||r.setSize(n,e),o==null||o.setSize(n,e),this.installPlugins.forEach((i,a)=>{var c;(c=a.setSize)==null||c.call(a,n,e)}),this.event.emit("resize",{width:n,height:e})}pick(n,e,t=!1){const{raycaster:s,options:r}=this,{container:o}=r,i=new d.Vector2,a=o.getBoundingClientRect();if(i.x=(n.clientX-a.left)/(a.right-a.left)*2-1,i.y=-((n.clientY-a.top)/(a.bottom-a.top))*2+1,this.camera&&this.scene){s.setFromCamera(i,this.camera);const c=s.intersectObjects(e||this.scene.children,t);if(c.length)return{object:c[0].object,intersects:c}}}render(){var i,a,c,u,f;const{renderer:n,scene:e,camera:t,clock:s}=this;if(!n||!e||!t||this.options.staticRender&&!this.cameraController.checkCameraChange())return;const r=s.getDelta(),o=s.getElapsedTime();(i=this.controlController)==null||i.update(),this.installPlugins.forEach((m,p)=>{var g;(g=p.update)==null||g.call(p,r,o)}),(a=this.composerController)!=null&&a.active?this.composerController.render():(c=this.rendererController)==null||c.render(),(u=this.cssRendererController)==null||u.render(e,t),(f=this.stats)==null||f.update(),this.event.emit("render",{delta:r,elapsed:o})}start(){this.renderer.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){this.renderer.setAnimationLoop(null),this.event.emit("stop")}dispose(){var n,e,t,s,r,o,i;this.stop(),this.handeleResize(0,0),(n=this.resizeObserver)==null||n.unobserve(this.options.container),this.installPlugins.forEach((a,c)=>{var u;(u=c.dispose)==null||u.call(c)}),(e=this.controlController)==null||e.dispose(),(t=this.cssRendererController)==null||t.dispose(),(s=this.sceneController)==null||s.dispose(),(r=this.composerController)==null||r.dispose(),(o=this.rendererController)==null||o.dispose(),this.controlController=void 0,this.cssRendererController=void 0,(i=this.gui)==null||i.destroy(),this.event.removeAllListeners(),this.installPlugins.clear()}};let _=U;_.options={isdev:E,stats:E,gui:E,axesHelper:E,control:E,resizeObserver:!0,renderer:M(P({},ve),{antialias:W?"msaa":"fxaa"}),staticRender:!1,multisampling:4,scene:Pe,camera:Ce,bloom:!1,bloomParams:Le,css2DRenderer:!1,css2DRendererParams:P({},B),css3DRenderer:!1,css3DRendererParams:P({},B)};exports.BaseObject=ae.BaseObject;exports.GUIObject=S;exports.Pencil=_;exports.default=_;
|
package/dist/index.module.js
CHANGED
|
@@ -16,14 +16,14 @@ import J from "three/examples/jsm/libs/stats.module";
|
|
|
16
16
|
import Q from "lil-gui";
|
|
17
17
|
import { d as ee } from "./disposeMesh.module.js";
|
|
18
18
|
import "idb-keyval";
|
|
19
|
-
import {
|
|
20
|
-
import { CSS3DRenderer as
|
|
21
|
-
import { CSS2DRenderer as
|
|
22
|
-
import { EffectComposer as
|
|
23
|
-
import { i as
|
|
24
|
-
import { B as
|
|
19
|
+
import { OrbitControls as te } from "three/examples/jsm/controls/OrbitControls";
|
|
20
|
+
import { CSS3DRenderer as ne } from "three/examples/jsm/renderers/CSS3DRenderer";
|
|
21
|
+
import { CSS2DRenderer as se } from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
22
|
+
import { EffectComposer as re, RenderPass as ie, CopyPass as oe, FXAAEffect as ae, BlendFunction as ce, EffectPass as z, SelectiveBloomEffect as le } from "postprocessing";
|
|
23
|
+
import { i as fe } from "./isPlainObject.module.js";
|
|
24
|
+
import { B as We } from "./BaseObject.module.js";
|
|
25
25
|
import "./makePromiseCreator.module.js";
|
|
26
|
-
var L = {},
|
|
26
|
+
var L = {}, de = {
|
|
27
27
|
get exports() {
|
|
28
28
|
return L;
|
|
29
29
|
},
|
|
@@ -38,7 +38,7 @@ P && typeof P.ownKeys == "function" ? E = P.ownKeys : Object.getOwnPropertySymbo
|
|
|
38
38
|
} : E = function(e) {
|
|
39
39
|
return Object.getOwnPropertyNames(e);
|
|
40
40
|
};
|
|
41
|
-
function
|
|
41
|
+
function he(n) {
|
|
42
42
|
console && console.warn && console.warn(n);
|
|
43
43
|
}
|
|
44
44
|
var B = Number.isNaN || function(e) {
|
|
@@ -47,8 +47,8 @@ var B = Number.isNaN || function(e) {
|
|
|
47
47
|
function l() {
|
|
48
48
|
l.init.call(this);
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
L.once =
|
|
50
|
+
de.exports = l;
|
|
51
|
+
L.once = ve;
|
|
52
52
|
l.EventEmitter = l;
|
|
53
53
|
l.prototype._events = void 0;
|
|
54
54
|
l.prototype._eventsCount = 0;
|
|
@@ -119,7 +119,7 @@ function I(n, e, t, s) {
|
|
|
119
119
|
else if (typeof i == "function" ? i = o[e] = s ? [t, i] : [i, t] : s ? i.unshift(t) : i.push(t), r = G(n), r > 0 && i.length > r && !i.warned) {
|
|
120
120
|
i.warned = !0;
|
|
121
121
|
var a = new Error("Possible EventEmitter memory leak detected. " + i.length + " " + String(e) + " listeners added. Use emitter.setMaxListeners() to increase limit");
|
|
122
|
-
a.name = "MaxListenersExceededWarning", a.emitter = n, a.type = e, a.count = i.length,
|
|
122
|
+
a.name = "MaxListenersExceededWarning", a.emitter = n, a.type = e, a.count = i.length, he(a);
|
|
123
123
|
}
|
|
124
124
|
return n;
|
|
125
125
|
}
|
|
@@ -130,12 +130,12 @@ l.prototype.on = l.prototype.addListener;
|
|
|
130
130
|
l.prototype.prependListener = function(e, t) {
|
|
131
131
|
return I(this, e, t, !0);
|
|
132
132
|
};
|
|
133
|
-
function
|
|
133
|
+
function ue() {
|
|
134
134
|
if (!this.fired)
|
|
135
135
|
return this.target.removeListener(this.type, this.wrapFn), this.fired = !0, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments);
|
|
136
136
|
}
|
|
137
137
|
function N(n, e, t) {
|
|
138
|
-
var s = { fired: !1, wrapFn: void 0, target: n, type: e, listener: t }, r =
|
|
138
|
+
var s = { fired: !1, wrapFn: void 0, target: n, type: e, listener: t }, r = ue.bind(s);
|
|
139
139
|
return r.listener = t, s.wrapFn = r, r;
|
|
140
140
|
}
|
|
141
141
|
l.prototype.once = function(e, t) {
|
|
@@ -160,7 +160,7 @@ l.prototype.removeListener = function(e, t) {
|
|
|
160
160
|
}
|
|
161
161
|
if (o < 0)
|
|
162
162
|
return this;
|
|
163
|
-
o === 0 ? s.shift() :
|
|
163
|
+
o === 0 ? s.shift() : me(s, o), s.length === 1 && (r[e] = s[0]), r.removeListener !== void 0 && this.emit("removeListener", e, a || t);
|
|
164
164
|
}
|
|
165
165
|
return this;
|
|
166
166
|
};
|
|
@@ -189,7 +189,7 @@ function F(n, e, t) {
|
|
|
189
189
|
if (s === void 0)
|
|
190
190
|
return [];
|
|
191
191
|
var r = s[e];
|
|
192
|
-
return r === void 0 ? [] : typeof r == "function" ? t ? [r.listener || r] : [r] : t ?
|
|
192
|
+
return r === void 0 ? [] : typeof r == "function" ? t ? [r.listener || r] : [r] : t ? pe(r) : k(r, r.length);
|
|
193
193
|
}
|
|
194
194
|
l.prototype.listeners = function(e) {
|
|
195
195
|
return F(this, e, !0);
|
|
@@ -220,17 +220,17 @@ function k(n, e) {
|
|
|
220
220
|
t[s] = n[s];
|
|
221
221
|
return t;
|
|
222
222
|
}
|
|
223
|
-
function
|
|
223
|
+
function me(n, e) {
|
|
224
224
|
for (; e + 1 < n.length; e++)
|
|
225
225
|
n[e] = n[e + 1];
|
|
226
226
|
n.pop();
|
|
227
227
|
}
|
|
228
|
-
function
|
|
228
|
+
function pe(n) {
|
|
229
229
|
for (var e = new Array(n.length), t = 0; t < e.length; ++t)
|
|
230
230
|
e[t] = n[t].listener || n[t];
|
|
231
231
|
return e;
|
|
232
232
|
}
|
|
233
|
-
function
|
|
233
|
+
function ve(n, e) {
|
|
234
234
|
return new Promise(function(t, s) {
|
|
235
235
|
function r(i) {
|
|
236
236
|
n.removeListener(e, o), s(i);
|
|
@@ -238,10 +238,10 @@ function ge(n, e) {
|
|
|
238
238
|
function o() {
|
|
239
239
|
typeof n.removeListener == "function" && n.removeListener("error", r), t([].slice.call(arguments));
|
|
240
240
|
}
|
|
241
|
-
H(n, e, o, { once: !0 }), e !== "error" &&
|
|
241
|
+
H(n, e, o, { once: !0 }), e !== "error" && ge(n, r, { once: !0 });
|
|
242
242
|
});
|
|
243
243
|
}
|
|
244
|
-
function
|
|
244
|
+
function ge(n, e, t) {
|
|
245
245
|
typeof n.on == "function" && H(n, "error", e, t);
|
|
246
246
|
}
|
|
247
247
|
function H(n, e, t, s) {
|
|
@@ -317,7 +317,7 @@ const D = {
|
|
|
317
317
|
Reinhard: f.ReinhardToneMapping,
|
|
318
318
|
Cineon: f.CineonToneMapping,
|
|
319
319
|
ACESFilmic: f.ACESFilmicToneMapping
|
|
320
|
-
},
|
|
320
|
+
}, Ce = {
|
|
321
321
|
antialias: !1,
|
|
322
322
|
devicePixelRatio: window.devicePixelRatio,
|
|
323
323
|
powerPreference: "high-performance",
|
|
@@ -332,7 +332,7 @@ const D = {
|
|
|
332
332
|
depth: !1,
|
|
333
333
|
physicallyCorrectLights: !1
|
|
334
334
|
};
|
|
335
|
-
class
|
|
335
|
+
class be {
|
|
336
336
|
constructor(e) {
|
|
337
337
|
this.options = e;
|
|
338
338
|
const { width: t, height: s, rendererParams: r } = e, {
|
|
@@ -390,12 +390,12 @@ class Pe {
|
|
|
390
390
|
(e = this.renderer) == null || e.clear(), (t = this.renderer) == null || t.dispose(), (s = this.renderer) == null || s.renderLists.dispose();
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
const
|
|
393
|
+
const Pe = {
|
|
394
394
|
fov: 45,
|
|
395
395
|
near: 1,
|
|
396
396
|
far: 1e3
|
|
397
397
|
};
|
|
398
|
-
class
|
|
398
|
+
class ye {
|
|
399
399
|
constructor(e) {
|
|
400
400
|
this.oldCameraPosition = new f.Vector3(), this.oldCameraRotation = new f.Euler(), this.customCamera = !1, this.options = e;
|
|
401
401
|
const { width: t, height: s, cameraParams: r } = e;
|
|
@@ -471,10 +471,10 @@ class we {
|
|
|
471
471
|
}), t.showGui(e);
|
|
472
472
|
}
|
|
473
473
|
}
|
|
474
|
-
const
|
|
474
|
+
const we = {
|
|
475
475
|
background: null
|
|
476
476
|
};
|
|
477
|
-
class
|
|
477
|
+
class Ee {
|
|
478
478
|
constructor(e) {
|
|
479
479
|
this.options = e;
|
|
480
480
|
const { camera: t, sceneParams: s } = e, { background: r } = s, o = new f.Scene();
|
|
@@ -492,10 +492,10 @@ class Le {
|
|
|
492
492
|
});
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
-
class
|
|
495
|
+
class Le {
|
|
496
496
|
constructor(e) {
|
|
497
497
|
this.options = e;
|
|
498
|
-
const { camera: t, controlParams: s,
|
|
498
|
+
const { camera: t, controlParams: s, customControl: r } = e, { domElement: o } = s, i = r ? new r(t, o) : new te(t, o);
|
|
499
499
|
i.minPolarAngle = Math.PI * 0.15, i.maxPolarAngle = Math.PI * 0.85, i.enableDamping = !0, i.dampingFactor = 0.063, i.autoRotate = !1, i.autoRotateSpeed = -60, i.enableZoom = !0, i.zoomSpeed = 0.2, this.control = i;
|
|
500
500
|
}
|
|
501
501
|
limitPan({
|
|
@@ -519,12 +519,12 @@ class xe {
|
|
|
519
519
|
const T = {
|
|
520
520
|
zIndex: "auto"
|
|
521
521
|
};
|
|
522
|
-
class
|
|
522
|
+
class xe {
|
|
523
523
|
constructor(e) {
|
|
524
524
|
this.container = e;
|
|
525
525
|
}
|
|
526
526
|
addRenderer(e, t) {
|
|
527
|
-
const { container: s } = this, r = s.offsetWidth, o = s.offsetHeight, i = e === "css2d" ? new
|
|
527
|
+
const { container: s } = this, r = s.offsetWidth, o = s.offsetHeight, i = e === "css2d" ? new se() : new ne();
|
|
528
528
|
i.domElement.style.position = "absolute", i.domElement.style.top = "0", i.domElement.style.pointerEvents = "none", i.domElement.style.zIndex = t.zIndex, i.setSize(r, o), s.appendChild(i.domElement), e === "css2d" ? this.css2Drenderer = i : e === "css3d" && (this.css3Drenderer = i);
|
|
529
529
|
}
|
|
530
530
|
setSize(e, t) {
|
|
@@ -539,30 +539,30 @@ class Re {
|
|
|
539
539
|
this.css2Drenderer = void 0, this.css3Drenderer = void 0;
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
|
-
const
|
|
542
|
+
const Re = {
|
|
543
543
|
luminanceThreshold: 0.1,
|
|
544
544
|
luminanceSmoothing: 0.3,
|
|
545
545
|
mipmapBlur: !0,
|
|
546
546
|
intensity: 4
|
|
547
547
|
};
|
|
548
|
-
class
|
|
548
|
+
class Se {
|
|
549
549
|
constructor(e) {
|
|
550
550
|
this.active = !0, this.options = e;
|
|
551
|
-
const { renderer: t, scene: s, camera: r, composerParams: o } = e, { multisampling: i } = o, { maxSamples: a } = t.capabilities, c = new
|
|
551
|
+
const { renderer: t, scene: s, camera: r, composerParams: o } = e, { multisampling: i } = o, { maxSamples: a } = t.capabilities, c = new re(t, {
|
|
552
552
|
multisampling: Math.min(i, a)
|
|
553
553
|
});
|
|
554
|
-
c.addPass(new
|
|
554
|
+
c.addPass(new ie(s, r)), this.finalComposer = c, this.renderer = t, this.scene = s, this.camera = r;
|
|
555
555
|
}
|
|
556
556
|
addCopyPass() {
|
|
557
|
-
const e = new
|
|
557
|
+
const e = new oe();
|
|
558
558
|
e.renderToScreen = !0, this.finalComposer.addPass(e), this.copyPass = e;
|
|
559
559
|
}
|
|
560
560
|
addFXAAPass() {
|
|
561
|
-
const { camera: e } = this, t = new
|
|
561
|
+
const { camera: e } = this, t = new ae({ blendFunction: ce.NORMAL }), s = new z(e, t);
|
|
562
562
|
this.finalComposer.addPass(s), this.fxaaPass = s;
|
|
563
563
|
}
|
|
564
564
|
addBloomPass(e) {
|
|
565
|
-
const { camera: t, scene: s } = this, r = new
|
|
565
|
+
const { camera: t, scene: s } = this, r = new le(s, t, b({}, e)), o = new z(t, r);
|
|
566
566
|
o.enabled = !1, this.finalComposer.addPass(o), this.bloomPass = o, this.bloomEffect = r;
|
|
567
567
|
}
|
|
568
568
|
addBloomGui(e) {
|
|
@@ -640,17 +640,17 @@ class Oe {
|
|
|
640
640
|
this.finalComposer.dispose();
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
|
-
const
|
|
643
|
+
const Oe = () => {
|
|
644
644
|
try {
|
|
645
645
|
const n = document.createElement("canvas");
|
|
646
646
|
return !!(window.WebGL2RenderingContext && n.getContext("webgl2"));
|
|
647
647
|
} catch (n) {
|
|
648
648
|
return !1;
|
|
649
649
|
}
|
|
650
|
-
}, w = !1, W =
|
|
650
|
+
}, w = !1, W = Oe() !== !1, K = class {
|
|
651
651
|
constructor(n) {
|
|
652
652
|
this.raycaster = new f.Raycaster(), this.installPlugins = /* @__PURE__ */ new Map(), this.event = new L.EventEmitter(), this.clock = new f.Clock(), this.userData = {}, this.options = $(K.options, n, {
|
|
653
|
-
isMergeableObject:
|
|
653
|
+
isMergeableObject: fe
|
|
654
654
|
});
|
|
655
655
|
const {
|
|
656
656
|
container: e,
|
|
@@ -692,17 +692,17 @@ const Me = () => {
|
|
|
692
692
|
renderer: s,
|
|
693
693
|
scene: r,
|
|
694
694
|
camera: o
|
|
695
|
-
} = this.options, { width: i, height: a } = this.getSize(), c = new
|
|
695
|
+
} = this.options, { width: i, height: a } = this.getSize(), c = new ye({
|
|
696
696
|
isdev: e,
|
|
697
697
|
width: i,
|
|
698
698
|
height: a,
|
|
699
699
|
cameraParams: o
|
|
700
700
|
});
|
|
701
701
|
this.gui && c.setGui(this.gui);
|
|
702
|
-
const h = c.camera, d = new
|
|
702
|
+
const h = c.camera, d = new Ee({
|
|
703
703
|
camera: h,
|
|
704
704
|
sceneParams: r
|
|
705
|
-
}), m = d.scene, p = new
|
|
705
|
+
}), m = d.scene, p = new be({
|
|
706
706
|
width: i,
|
|
707
707
|
height: a,
|
|
708
708
|
scene: m,
|
|
@@ -726,7 +726,7 @@ const Me = () => {
|
|
|
726
726
|
} = this.options;
|
|
727
727
|
let { antialias: o } = t;
|
|
728
728
|
o === "msaa" && !W && (o = !1, console.warn("MSAA is not supported on this browser"));
|
|
729
|
-
const i = new
|
|
729
|
+
const i = new Se({
|
|
730
730
|
renderer: this.renderer,
|
|
731
731
|
scene: this.scene,
|
|
732
732
|
camera: this.camera,
|
|
@@ -749,21 +749,21 @@ const Me = () => {
|
|
|
749
749
|
css3DRendererParams: r
|
|
750
750
|
} = this.options;
|
|
751
751
|
if (e || t) {
|
|
752
|
-
const o = new
|
|
752
|
+
const o = new xe(n);
|
|
753
753
|
e && o.addRenderer("css2d", s), t && o.addRenderer("css3d", r), this.cssRendererController = o;
|
|
754
754
|
}
|
|
755
755
|
}
|
|
756
756
|
initControl() {
|
|
757
|
-
const { control: n,
|
|
757
|
+
const { control: n, controlParams: e } = this.options;
|
|
758
758
|
if (n) {
|
|
759
|
-
const
|
|
759
|
+
const t = new Le({
|
|
760
760
|
camera: this.camera,
|
|
761
761
|
controlParams: {
|
|
762
|
-
domElement: (
|
|
762
|
+
domElement: (e == null ? void 0 : e.domElement) || this.renderer.domElement
|
|
763
763
|
},
|
|
764
|
-
|
|
764
|
+
customControl: typeof n == "boolean" ? void 0 : n
|
|
765
765
|
});
|
|
766
|
-
this.controlController =
|
|
766
|
+
this.controlController = t;
|
|
767
767
|
}
|
|
768
768
|
}
|
|
769
769
|
getSize() {
|
|
@@ -837,31 +837,31 @@ const Me = () => {
|
|
|
837
837
|
}), (e = this.controlController) == null || e.dispose(), (t = this.cssRendererController) == null || t.dispose(), (s = this.sceneController) == null || s.dispose(), (r = this.composerController) == null || r.dispose(), (o = this.rendererController) == null || o.dispose(), this.controlController = void 0, this.cssRendererController = void 0, (i = this.gui) == null || i.destroy(), this.event.removeAllListeners(), this.installPlugins.clear();
|
|
838
838
|
}
|
|
839
839
|
};
|
|
840
|
-
let
|
|
841
|
-
|
|
840
|
+
let Me = K;
|
|
841
|
+
Me.options = {
|
|
842
842
|
isdev: w,
|
|
843
843
|
stats: w,
|
|
844
844
|
gui: w,
|
|
845
845
|
axesHelper: w,
|
|
846
846
|
control: w,
|
|
847
847
|
resizeObserver: !0,
|
|
848
|
-
renderer: S(b({},
|
|
848
|
+
renderer: S(b({}, Ce), {
|
|
849
849
|
antialias: W ? "msaa" : "fxaa"
|
|
850
850
|
}),
|
|
851
851
|
staticRender: !1,
|
|
852
852
|
multisampling: 4,
|
|
853
|
-
scene:
|
|
854
|
-
camera:
|
|
853
|
+
scene: we,
|
|
854
|
+
camera: Pe,
|
|
855
855
|
bloom: !1,
|
|
856
|
-
bloomParams:
|
|
856
|
+
bloomParams: Re,
|
|
857
857
|
css2DRenderer: !1,
|
|
858
858
|
css2DRendererParams: b({}, T),
|
|
859
859
|
css3DRenderer: !1,
|
|
860
860
|
css3DRendererParams: b({}, T)
|
|
861
861
|
};
|
|
862
862
|
export {
|
|
863
|
-
|
|
863
|
+
We as BaseObject,
|
|
864
864
|
O as GUIObject,
|
|
865
|
-
|
|
866
|
-
|
|
865
|
+
Me as Pencil,
|
|
866
|
+
Me as default
|
|
867
867
|
};
|