gl-draw 0.9.0-beta.2 → 0.9.0-beta.20
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/BaseObject.js +1 -1
- package/dist/BaseObject.module.js +6 -3
- package/dist/core/BaseObject.d.ts +1 -0
- package/dist/core/Camera.d.ts +2 -0
- package/dist/core/Control.d.ts +5 -0
- package/dist/core/Pencil.d.ts +5 -2
- package/dist/core/Renderer.d.ts +2 -2
- package/dist/effect/index.js +3 -3
- package/dist/effect/index.module.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.module.js +228 -203
- package/dist/objects/extrudePolygon/ExtrudeGeometry.d.ts +11 -0
- package/dist/objects/extrudePolygon/coords2Vector.d.ts +1 -1
- package/dist/objects/extrudePolygon/createGeometry.d.ts +5 -1
- package/dist/objects/extrudePolygon/getSplitTexture.d.ts +12 -0
- package/dist/objects/extrudePolygon/getWorkerGeometry.d.ts +6 -2
- package/dist/objects/extrudePolygon/index.d.ts +8 -23
- package/dist/objects/fix.d.ts +2 -2
- package/dist/objects/index.d.ts +1 -0
- package/dist/objects/index.js +11 -11
- package/dist/objects/index.module.js +988 -570
- package/dist/objects/line/getWorkerGeometry.d.ts +1 -0
- package/dist/objects/line/index.d.ts +1 -1
- package/dist/plugins/CanvasStream.d.ts +15 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.module.js +96 -62
- package/dist/utils/BufferGeometryUtils.d.ts +53 -0
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.module.js +51 -96
- package/dist/worker/extrudePolygon.w.js +530 -397
- package/dist/worker/line.w.js +3 -3138
- package/package.json +8 -7
- package/dist/makePromiseCreator.js +0 -1
- package/dist/makePromiseCreator.module.js +0 -24
- package/dist/utils/exception.d.ts +0 -26
- package/dist/utils/makePromiseCreator.d.ts +0 -6
- package/dist/utils/timer.d.ts +0 -9
- package/dist/utils/to.d.ts +0 -8
package/dist/BaseObject.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const o=require("three"),
|
|
1
|
+
"use strict";const o=require("three"),h=require("esus-lite"),a=require("three/examples/jsm/renderers/CSS2DRenderer"),c=require("three/examples/jsm/renderers/CSS3DRenderer"),d=require("./disposeMesh.js");require("idb-keyval");function u(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(e,r,i.get?i:{enumerable:!0,get:()=>t[r]})}}return e.default=t,Object.freeze(e)}const s=u(o),n=t=>{t&&(d.disposeMesh(t),t.children.forEach(e=>{e.userData.BaseObject_||n(e)}))};class b{constructor(){this.objecttype__="BaseObject",this.userData={},this.pm=h.makePromiseCreator(),this.visible=!1}get parent(){const e=this.object3d.parent;return(e==null?void 0:e.userData.BaseObject_)||this.pencil.scene}get children(){return this.object3d.children.map(e=>e.userData.BaseObject_).filter(e=>!!e)}init(){}create(){}render(){}update(e,r){}resize(e,r){}show(){return this.object3d&&(this.object3d.visible=!0),this.visible=!0,this}hide(){return this.object3d&&(this.object3d.visible=!1),this.visible=!1,this}isVisible(){return this.visible}createMesh(...e){return this.object3d=new s.Mesh(...e),this}createGroup(){return this.object3d=new s.Group,this}createPoints(...e){return this.object3d=new s.Points(...e),this}createCSS2DObject(e){return this.object3d=new a.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new c.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new c.CSS3DSprite(e),this}createSprite(e){return this.object3d=new s.Sprite(e),this}add(...e){return this.object3d.add(...e),this}remove(...e){return this.object3d.remove(...e),this}attach(e){return this.object3d.attach(e.object3d),this}getSize(){const e=new s.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new s.Vector3)}}traverse(e){e(this),this.children.forEach(r=>{r.traverse(e)})}dispose(){n(this.object3d)}}exports.BaseObject=b;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from "three";
|
|
2
|
-
import {
|
|
2
|
+
import { makePromiseCreator as h } from "esus-lite";
|
|
3
3
|
import { CSS2DObject as c } from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
4
4
|
import { CSS3DObject as o, CSS3DSprite as a } from "three/examples/jsm/renderers/CSS3DRenderer";
|
|
5
5
|
import { d as n } from "./disposeMesh.module.js";
|
|
@@ -9,7 +9,7 @@ const r = (i) => {
|
|
|
9
9
|
e.userData.BaseObject_ || r(e);
|
|
10
10
|
}));
|
|
11
11
|
};
|
|
12
|
-
class
|
|
12
|
+
class m {
|
|
13
13
|
constructor() {
|
|
14
14
|
this.objecttype__ = "BaseObject", this.userData = {}, this.pm = h(), this.visible = !1;
|
|
15
15
|
}
|
|
@@ -66,6 +66,9 @@ class p {
|
|
|
66
66
|
remove(...e) {
|
|
67
67
|
return this.object3d.remove(...e), this;
|
|
68
68
|
}
|
|
69
|
+
attach(e) {
|
|
70
|
+
return this.object3d.attach(e.object3d), this;
|
|
71
|
+
}
|
|
69
72
|
getSize() {
|
|
70
73
|
const e = new t.Box3().setFromObject(this.object3d);
|
|
71
74
|
return {
|
|
@@ -84,5 +87,5 @@ class p {
|
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
export {
|
|
87
|
-
|
|
90
|
+
m as B
|
|
88
91
|
};
|
|
@@ -33,6 +33,7 @@ export default class BaseObject {
|
|
|
33
33
|
createSprite(material: THREE.SpriteMaterial): this;
|
|
34
34
|
add(...args: Parameters<THREE.Object3D['add']>): this;
|
|
35
35
|
remove(...args: Parameters<THREE.Object3D['remove']>): this;
|
|
36
|
+
attach(o: IBaseObject): this;
|
|
36
37
|
getSize(): {
|
|
37
38
|
min: THREE.Vector3;
|
|
38
39
|
max: THREE.Vector3;
|
package/dist/core/Camera.d.ts
CHANGED
|
@@ -4,11 +4,13 @@ export interface CameraParams {
|
|
|
4
4
|
fov: number;
|
|
5
5
|
near: number;
|
|
6
6
|
far: number;
|
|
7
|
+
up: THREE.Vector3;
|
|
7
8
|
}
|
|
8
9
|
export declare const defaultCameraParams: {
|
|
9
10
|
fov: number;
|
|
10
11
|
near: number;
|
|
11
12
|
far: number;
|
|
13
|
+
up: THREE.Vector3;
|
|
12
14
|
};
|
|
13
15
|
interface Options {
|
|
14
16
|
width: number;
|
package/dist/core/Control.d.ts
CHANGED
|
@@ -22,6 +22,11 @@ export default class {
|
|
|
22
22
|
maxY?: number | undefined;
|
|
23
23
|
minY?: number | undefined;
|
|
24
24
|
}): void;
|
|
25
|
+
changeRotation({ vertical, horizontal, distance, }: {
|
|
26
|
+
vertical?: number;
|
|
27
|
+
horizontal?: number;
|
|
28
|
+
distance?: number;
|
|
29
|
+
}): void;
|
|
25
30
|
update(): void;
|
|
26
31
|
dispose(): void;
|
|
27
32
|
}
|
package/dist/core/Pencil.d.ts
CHANGED
|
@@ -35,8 +35,11 @@ interface Options {
|
|
|
35
35
|
css3DRenderer?: boolean;
|
|
36
36
|
css3DRendererParams?: Partial<CSSRendererParams>;
|
|
37
37
|
}
|
|
38
|
+
type DeepRequiredOptions = DeepRequired<Options>;
|
|
38
39
|
export default class Pencil {
|
|
39
|
-
options: Omit<
|
|
40
|
+
options: Omit<DeepRequiredOptions, 'controlParams' | 'renderer'> & Pick<Options, 'controlParams'> & {
|
|
41
|
+
renderer: Omit<DeepRequiredOptions['renderer'], 'canvas' | 'context'> & Pick<RendererParams, 'canvas' | 'context'>;
|
|
42
|
+
};
|
|
40
43
|
composerController: ComposerController;
|
|
41
44
|
private rendererController;
|
|
42
45
|
cssRendererController?: CSSRendererController;
|
|
@@ -72,7 +75,6 @@ export default class Pencil {
|
|
|
72
75
|
outputEncoding: THREE.TextureEncoding;
|
|
73
76
|
logarithmicDepthBuffer: boolean;
|
|
74
77
|
preserveDrawingBuffer: boolean;
|
|
75
|
-
context: null;
|
|
76
78
|
stencil: boolean;
|
|
77
79
|
depth: boolean;
|
|
78
80
|
physicallyCorrectLights: boolean;
|
|
@@ -86,6 +88,7 @@ export default class Pencil {
|
|
|
86
88
|
fov: number;
|
|
87
89
|
near: number;
|
|
88
90
|
far: number;
|
|
91
|
+
up: THREE.Vector3;
|
|
89
92
|
};
|
|
90
93
|
bloom: boolean;
|
|
91
94
|
bloomParams: {
|
package/dist/core/Renderer.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export interface RendererParams {
|
|
|
17
17
|
outputEncoding: THREE.TextureEncoding;
|
|
18
18
|
logarithmicDepthBuffer: boolean;
|
|
19
19
|
preserveDrawingBuffer: boolean;
|
|
20
|
-
|
|
20
|
+
canvas?: HTMLCanvasElement | THREE.OffscreenCanvas;
|
|
21
|
+
context?: WebGLRenderingContext;
|
|
21
22
|
stencil: boolean;
|
|
22
23
|
depth: boolean;
|
|
23
24
|
physicallyCorrectLights: boolean;
|
|
@@ -32,7 +33,6 @@ export declare const defaultRendererParams: {
|
|
|
32
33
|
outputEncoding: THREE.TextureEncoding;
|
|
33
34
|
logarithmicDepthBuffer: boolean;
|
|
34
35
|
preserveDrawingBuffer: boolean;
|
|
35
|
-
context: null;
|
|
36
36
|
stencil: boolean;
|
|
37
37
|
depth: boolean;
|
|
38
38
|
physicallyCorrectLights: boolean;
|
package/dist/effect/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document!="undefined"){var e=document.createElement("style");e.appendChild(document.createTextNode("")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
|
|
2
|
-
"use strict";var _=Object.defineProperty;var z=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var W=Math.pow,D=(a,i,e)=>i in a?_(a,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[i]=e,c=(a,i)=>{for(var e in i||(i={}))T.call(i,e)&&D(a,e,i[e]);if(z)for(var e of z(i))A.call(i,e)&&D(a,e,i[e]);return a};var b=(a,i,e)=>new Promise((t,o)=>{var f=d=>{try{
|
|
2
|
+
"use strict";var _=Object.defineProperty;var z=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var W=Math.pow,D=(a,i,e)=>i in a?_(a,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[i]=e,c=(a,i)=>{for(var e in i||(i={}))T.call(i,e)&&D(a,e,i[e]);if(z)for(var e of z(i))A.call(i,e)&&D(a,e,i[e]);return a};var b=(a,i,e)=>new Promise((t,o)=>{var f=d=>{try{r(e.next(d))}catch(m){o(m)}},l=d=>{try{r(e.throw(d))}catch(m){o(m)}},r=d=>d.done?t(d.value):Promise.resolve(d.value).then(f,l);r((e=e.apply(a,i)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("three"),E=require("@tweenjs/tween.js"),j=require("esus-lite");function S(a){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const e in a)if(e!=="default"){const t=Object.getOwnPropertyDescriptor(a,e);Object.defineProperty(i,e,t.get?t:{enumerable:!0,get:()=>a[e]})}}return i.default=a,Object.freeze(i)}const u=S(V),C=S(E);class k{constructor(i,e={}){this.object=i,this.options=c({color:16777215,opacity:1,lineNum:10,lineWidth:1,lineHieght:10,fade:!1,fadeType:2,radius:0,range:new u.Vector2(0,1),vertical:!1,step:0,pos:"bottom",duration:5e3,yoyo:!1,repeat:0},e)}initMaterial(){const{color:i,lineNum:e,lineWidth:t,lineHieght:o,fade:f,fadeType:l,radius:r,range:d,vertical:m,step:g,opacity:w,exclude:p}=this.options,v={field:{value:new u.Vector4(0,0,0,0)},color:{value:new u.Color(i)},opacity:{value:w},lineNum:{value:e},lineWidth:{value:t},lineHieght:{value:o},sizeNum:{value:new u.Vector3(r,r,r)},objPos:{value:new u.Vector3(0,0,0)},fade:{value:f},fadeType:{value:l},range:{value:d},angle:{value:0},stepNum:{value:g}};if(!r){const{size:h}=this.object.getSize();v.sizeNum.value.copy(h)}this.uniforms=v,this.object.object3d.traverse(h=>{const n=h;!n.material||p&&p.includes(n)||(n.userData.materialO?n.material=n.userData.materialO.clone():n.userData.materialO=Array.isArray(n.material)?n.material.map(s=>s.clone()):n.material.clone(),Array.isArray(n.material)?n.material.forEach(s=>{m?this.setVerticalMaterial(s):this.setMaterial(s)}):m?this.setVerticalMaterial(n.material):this.setMaterial(n.material))})}setMaterial(i){const{uniforms:e}=this;i.onBeforeCompile=t=>{t.uniforms.field=e.field,t.uniforms.fieldColor=e.color,t.uniforms.fieldOpacity=e.opacity,t.uniforms.lineNum=e.lineNum,t.uniforms.lineWidth=e.lineWidth,t.uniforms.sizeNum=e.sizeNum,t.uniforms.fade=e.fade,t.uniforms.fadeType=e.fadeType,t.uniforms.range=e.range,t.uniforms.stepNum=e.stepNum,t.vertexShader=`
|
|
3
3
|
varying vec4 vWorldPos;
|
|
4
4
|
${t.vertexShader}
|
|
5
5
|
`.replace("#include <worldpos_vertex>",`#include <worldpos_vertex>
|
|
@@ -126,7 +126,7 @@
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
`)},i.needsUpdate=!0}resetMaterial(){this.object.object3d.traverse(i=>{const e=i;e.material&&e.userData.materialO&&(e.material=e.userData.materialO.clone(),e.userData.materialO=void 0)})}play(i={}){this.stop();const e=j.makePromiseCreator(!0),{object:t,uniforms:o}=this,{lineNum:f,step:
|
|
129
|
+
`)},i.needsUpdate=!0}resetMaterial(){this.object.object3d.traverse(i=>{const e=i;e.material&&e.userData.materialO&&(e.material=e.userData.materialO.clone(),e.userData.materialO=void 0)})}play(i={}){this.stop();const e=j.makePromiseCreator(!0),{object:t,uniforms:o}=this,{lineNum:f,step:l,lineWidth:r,pos:d,duration:m}=c(c({},this.options),i),{min:g,max:w,size:p}=t.getSize();let v=f,h=r;l>0&&(v=1,h=p.y/l);const n=o.sizeNum.value.y*(v>1?2:1);return this.tween=new C.Tween({latest:0}).to({latest:1},m).onStart(()=>{var N;const s=new u.Vector3;d==="bottom"?s.set(g.x-.001,g.y-.001,g.z-.001):d==="top"&&s.set(w.x+.001,w.y+.001,w.z+.001);const x=((N=t.pencil.control)==null?void 0:N.getAzimuthalAngle())||0,y=this.object.object3d.position.clone();if(x){const M=Math.sqrt(W(p.x,2)+W(p.z,2))/2;s.x=y.x+M,s.z=y.z+M;const P=new u.Vector3().subVectors(s,y),O=new u.Vector3(0,1,0);P.applyAxisAngle(O,x),s.addVectors(y,P)}o.objPos.value.copy(y),o.field.value.set(s.x,s.y,s.z,0),o.angle.value=x,o.lineNum.value=v,o.lineWidth.value=h}).onUpdate(({latest:s})=>{l>0?o.field.value.w=Math.floor(s*l)/l*n:o.field.value.w=s*n}).onStop(()=>{o.field.value.w=0,e.reject("stop")}).onComplete(()=>{e.resolve()}).start(),e.promise}checkRepeat(){return b(this,arguments,function*(i={}){const{yoyo:e,repeat:t,pos:o}=c(c({},this.options),i);t===this.options.repeat&&this.initMaterial();const{err:f}=yield this.play(i);if(f){this.resetMaterial();return}if(t){let l=o;e&&(l=l==="bottom"?"top":"bottom"),yield this.checkRepeat({pos:l,repeat:t===1/0?-1:t-1})}else this.resetMaterial()})}start(){return this.checkRepeat()}stop(){this.tween&&this.tween.stop()}}class H{constructor(i,e={}){this.object=i,this.options=c({color:16777215,lineWidth:2,opacity:.5,fade:!1,position:new u.Vector3(0,0,0),duration:5e3,repeat:0},e)}initMaterial(){const{exclude:i}=this.options,e={field:{value:new u.Vector4(0,0,0,1e-4)},color:{value:new u.Color(this.options.color)},opacity:{value:this.options.opacity},lineWidth:{value:this.options.lineWidth}};this.uniforms=e,this.object.object3d.traverse(t=>{const o=t;!o.material||i&&i.includes(o)||(o.userData.materialO?o.material=o.userData.materialO:o.userData.materialO=Array.isArray(o.material)?o.material.map(f=>f.clone()):o.material.clone(),Array.isArray(o.material)?o.material.forEach(f=>{this.setMaterial(f)}):this.setMaterial(o.material))})}setMaterial(i){const{uniforms:e}=this;i.onBeforeCompile=t=>{t.uniforms.field=e.field,t.uniforms.fieldColor=e.color,t.uniforms.fieldOpacity=e.opacity,t.uniforms.lineWidth=e.lineWidth,t.vertexShader=`
|
|
130
130
|
varying vec4 vWorldPos;
|
|
131
131
|
${t.vertexShader}
|
|
132
132
|
`.replace("#include <worldpos_vertex>",`#include <worldpos_vertex>
|
|
@@ -158,4 +158,4 @@
|
|
|
158
158
|
}
|
|
159
159
|
gl_FragColor.rgb = mix(gl_FragColor.rgb, fieldColor, fadeout);
|
|
160
160
|
|
|
161
|
-
`)},i.needsUpdate=!0}resetMaterial(){this.object.object3d.traverse(i=>{const e=i;e.material&&e.userData.materialO&&(e.material=e.userData.materialO.clone(),e.userData.materialO=void 0)})}play(){this.stop();const i=j.makePromiseCreator(!0),{object:e,uniforms:t}=this,{position:o,duration:f}=this.options;let{radius:
|
|
161
|
+
`)},i.needsUpdate=!0}resetMaterial(){this.object.object3d.traverse(i=>{const e=i;e.material&&e.userData.materialO&&(e.material=e.userData.materialO.clone(),e.userData.materialO=void 0)})}play(){this.stop();const i=j.makePromiseCreator(!0),{object:e,uniforms:t}=this,{position:o,duration:f}=this.options;let{radius:l}=this.options;if(!l){const{size:r}=e.getSize();l=Math.max(r.x,r.y,r.z)}return this.tween=new C.Tween({a:1e-4}).to({a:1},f).onStart(()=>{t.field.value.set(o.x,o.y,o.z,1e-4),this.options.fade&&(t.opacity.value=this.options.opacity)}).onUpdate(({a:r})=>{t.field.value.w=r*l,this.options.fade&&(t.opacity.value=(1-r)*this.options.opacity)}).onStop(()=>{t.field.value.w=0,i.reject("stop")}).onComplete(()=>{i.resolve()}).start(),i.promise}checkRepeat(){return b(this,arguments,function*(i={}){const{repeat:e}=c(c({},this.options),i);e===this.options.repeat&&this.initMaterial();const{err:t}=yield this.play();if(t){this.resetMaterial();return}e?yield this.checkRepeat({repeat:e===1/0?-1:e-1}):this.resetMaterial()})}start(){return this.checkRepeat()}stop(){this.tween&&this.tween.stop()}}exports.Scan=k;exports.Scan2=H;
|
|
@@ -28,7 +28,7 @@ var N = (d, i, e) => new Promise((t, o) => {
|
|
|
28
28
|
});
|
|
29
29
|
import * as u from "three";
|
|
30
30
|
import * as j from "@tweenjs/tween.js";
|
|
31
|
-
import {
|
|
31
|
+
import { makePromiseCreator as C } from "esus-lite";
|
|
32
32
|
class k {
|
|
33
33
|
constructor(i, e = {}) {
|
|
34
34
|
this.object = i, this.options = c({
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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=_;
|
|
1
|
+
"use strict";var Q=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?Q(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},_=(n,e)=>Y(n,Z(e));Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ee=require("three"),te=require("deepmerge"),ne=require("three/examples/jsm/libs/stats.module"),se=require("lil-gui"),re=require("./disposeMesh.js");require("idb-keyval");require("esus-lite");const ie=require("three/examples/jsm/controls/OrbitControls"),oe=require("three/examples/jsm/renderers/CSS3DRenderer"),ae=require("three/examples/jsm/renderers/CSS2DRenderer"),v=require("postprocessing"),ce=require("./isPlainObject.js"),le=require("./BaseObject.js");function de(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 l=de(ee);var R={},fe={get exports(){return R},set exports(n){R=n}},w=typeof Reflect=="object"?Reflect:null,D=w&&typeof w.apply=="function"?w.apply:function(e,t,s){return Function.prototype.apply.call(e,t,s)},x;w&&typeof w.ownKeys=="function"?x=w.ownKeys:Object.getOwnPropertySymbols?x=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:x=function(e){return Object.getOwnPropertyNames(e)};function ue(n){console&&console.warn&&console.warn(n)}var G=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}fe.exports=d;R.once=ge;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var T=10;function S(n){if(typeof n!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof n)}Object.defineProperty(d,"defaultMaxListeners",{enumerable:!0,get:function(){return T},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+".");T=n}});d.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};d.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 N(n){return n._maxListeners===void 0?d.defaultMaxListeners:n._maxListeners}d.prototype.getMaxListeners=function(){return N(this)};d.prototype.emit=function(e){for(var t=[],s=1;s<arguments.length;s++)t.push(arguments[s]);var r=e==="error",i=this._events;if(i!==void 0)r=r&&i.error===void 0;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=i[e];if(c===void 0)return!1;if(typeof c=="function")D(c,this,t);else for(var f=c.length,u=H(c,f),s=0;s<f;++s)D(u[s],this,t);return!0};function V(n,e,t,s){var r,i,o;if(S(t),i=n._events,i===void 0?(i=n._events=Object.create(null),n._eventsCount=0):(i.newListener!==void 0&&(n.emit("newListener",e,t.listener?t.listener:t),i=n._events),o=i[e]),o===void 0)o=i[e]=t,++n._eventsCount;else if(typeof o=="function"?o=i[e]=s?[t,o]:[o,t]:s?o.unshift(t):o.push(t),r=N(n),r>0&&o.length>r&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=n,a.type=e,a.count=o.length,ue(a)}return n}d.prototype.addListener=function(e,t){return V(this,e,t,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,t){return V(this,e,t,!0)};function he(){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=he.bind(s);return r.listener=t,s.wrapFn=r,r}d.prototype.once=function(e,t){return S(t),this.on(e,F(this,e,t)),this};d.prototype.prependOnceListener=function(e,t){return S(t),this.prependListener(e,F(this,e,t)),this};d.prototype.removeListener=function(e,t){var s,r,i,o,a;if(S(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(i=-1,o=s.length-1;o>=0;o--)if(s[o]===t||s[o].listener===t){a=s[o].listener,i=o;break}if(i<0)return this;i===0?s.shift():me(s,i),s.length===1&&(r[e]=s[0]),r.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};d.prototype.off=d.prototype.removeListener;d.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 i=Object.keys(s),o;for(r=0;r<i.length;++r)o=i[r],o!=="removeListener"&&this.removeAllListeners(o);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?pe(r):H(r,r.length)}d.prototype.listeners=function(e){return q(this,e,!0)};d.prototype.rawListeners=function(e){return q(this,e,!1)};d.listenerCount=function(n,e){return typeof n.listenerCount=="function"?n.listenerCount(e):k.call(n,e)};d.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}d.prototype.eventNames=function(){return this._eventsCount>0?x(this._events):[]};function H(n,e){for(var t=new Array(e),s=0;s<e;++s)t[s]=n[s];return t}function me(n,e){for(;e+1<n.length;e++)n[e]=n[e+1];n.pop()}function pe(n){for(var e=new Array(n.length),t=0;t<e.length;++t)e[t]=n[t].listener||n[t];return e}function ge(n,e){return new Promise(function(t,s){function r(o){n.removeListener(e,i),s(o)}function i(){typeof n.removeListener=="function"&&n.removeListener("error",r),t([].slice.call(arguments))}W(n,e,i,{once:!0}),e!=="error"&&ve(n,r,{once:!0})})}function ve(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(i){s.once&&n.removeEventListener(e,r),t(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof n)}class O{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(i=>{const{min:o,max:a,step:c,name:f,paramMap:u,items:m,value:p,target:g}=r[i],M=i.toLowerCase().indexOf("color")>-1;let h;const E=typeof p=="undefined"&&g,b=E?g():r[i],y=E?i:"value";m?h=s.add(b,y,m):M?h=s.addColor(b,y):h=s.add(b,y),h=h.name(f||i),typeof o!="undefined"&&(h=h.min(o)),typeof a!="undefined"&&(h=h.max(a)),typeof c!="undefined"&&(h=h.step(c)),h=h.onChange(()=>{this.setTargetValue(t,i,b[y],u)}),E&&h.listen()})})}setTargetValue(e,t,s,r){const{onChange:i,target:o,value:a}=this.guiParams[e][t],c=t.toLowerCase().indexOf("color")>-1;if(o&&!(typeof a=="undefined"&&o)){let u=o();Array.isArray(u)||(u=[u]),u.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})}i&&i(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 I={None:l.NoToneMapping,Linear:l.LinearToneMapping,Reinhard:l.ReinhardToneMapping,Cineon:l.CineonToneMapping,ACESFilmic:l.ACESFilmicToneMapping},Ce={antialias:!1,devicePixelRatio:window.devicePixelRatio,powerPreference:"high-performance",toneMapping:"None",toneMappingExposure:1,alpha:!1,outputEncoding:l.LinearEncoding,logarithmicDepthBuffer:!1,preserveDrawingBuffer:!1,stencil:!1,depth:!1,physicallyCorrectLights:!1};class be{constructor(e){this.options=e;const{width:t,height:s,rendererParams:r}=e,{canvas:i,context:o,alpha:a,devicePixelRatio:c,antialias:f,powerPreference:u,toneMapping:m,toneMappingExposure:p,outputEncoding:g,logarithmicDepthBuffer:M,preserveDrawingBuffer:h,stencil:E,depth:b,physicallyCorrectLights:y}=r,C=new l.WebGLRenderer({canvas:i,context:o,alpha:a,antialias:f,powerPreference:u,logarithmicDepthBuffer:M,preserveDrawingBuffer:h,stencil:E,depth:b});C.setSize(t,s),C.setPixelRatio(c),C.toneMapping=I[m],C.toneMappingExposure=p,C.outputEncoding=g;const X=+l.REVISION<150?"physicallyCorrectLights":"useLegacyLights";C[X]=y,this.renderer=C}setSize(e,t){this.renderer.setSize(e,t)}render(){const{scene:e,camera:t}=this.options;this.renderer.render(e,t)}setGui(e){new O({renderer:{toneMapping:{value:this.options.rendererParams.toneMapping,items:I,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 ye={fov:45,near:1,far:1e3,up:new l.Vector3(0,1,0)};class Pe{constructor(e){this.oldCameraPosition=new l.Vector3,this.oldCameraRotation=new l.Euler,this.customCamera=!1,this.options=e;const{width:t,height:s,cameraParams:r}=e;if(r instanceof l.Camera)this.camera=r,this.customCamera=!0;else{const{fov:i,far:o,near:a,up:c}=r,f=new l.PerspectiveCamera(i,t/s,a,o);f.position.set(0,0,400),f.lookAt(0,0,0),f.up=c,this.camera=f}}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 l.PerspectiveCamera&&(this.camera.aspect=e/t),this.camera.updateProjectionMatrix()}setGui(e){const t=new O({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 l.PerspectiveCamera&&(t.guiParams.camera.fov={min:0,max:90,step:1,target:()=>this.camera,onChange:s=>{this.camera.updateProjectionMatrix()}}),t.showGui(e)}}const we={background:null};class Ee{constructor(e){this.options=e;const{camera:t,sceneParams:s}=e,{background:r}=s,i=new l.Scene;r&&(i.background=r),i.add(t),this.scene=i}addAxesHelper(){var t;const e=new l.AxesHelper(100);(t=this.scene)==null||t.add(e)}dispose(){var e;(e=this.scene)==null||e.traverse(t=>{re.disposeMesh(t)})}}class Le{constructor(e){this.options=e;const{camera:t,controlParams:s,customControl:r}=e,{domElement:i}=s,o=r?new r(t,i):new ie.OrbitControls(t,i);o.minPolarAngle=Math.PI*.15,o.maxPolarAngle=Math.PI*.85,o.enableDamping=!0,o.dampingFactor=.063,o.autoRotate=!1,o.autoRotateSpeed=-60,o.enableZoom=!0,o.zoomSpeed=.2,this.control=o}limitPan({maxX:e=1/0,minX:t=-1/0,maxZ:s=1/0,minZ:r=-1/0,maxY:i=1/0,minY:o=-1/0}){const a=this.limitPanV||new l.Vector3,c=this.control,{camera:f}=this.options,u=new l.Vector3(t,o,r),m=new l.Vector3(e,i,s);this.limitPanV=a,a.copy(c.target),c.target.clamp(u,m),a.sub(c.target),f.position.sub(a)}changeRotation({vertical:e,horizontal:t,distance:s}){const{camera:r}=this.options,i=this.control,o=t!=null?t:i.getAzimuthalAngle(),a=e!=null?e:i.getPolarAngle(),c=new l.Vector3;c.setFromSphericalCoords(s!=null?s:r.position.distanceTo(i.target),a,o);const f=new l.Quaternion().setFromUnitVectors(new l.Vector3(0,1,0),r.up);c.applyQuaternion(f),r.position.set(c.x+i.target.x,c.y+i.target.y,c.z+i.target.z),i.update()}update(){this.control.update()}dispose(){this.control.dispose()}}const B={zIndex:"auto"};class xe{constructor(e){this.container=e}addRenderer(e,t){const{container:s}=this,r=s.offsetWidth,i=s.offsetHeight,o=e==="css2d"?new ae.CSS2DRenderer:new oe.CSS3DRenderer;o.domElement.style.position="absolute",o.domElement.style.top="0",o.domElement.style.pointerEvents="none",o.domElement.style.zIndex=t.zIndex,o.setSize(r,i),s.appendChild(o.domElement),e==="css2d"?this.css2Drenderer=o:e==="css3d"&&(this.css3Drenderer=o)}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 Re={luminanceThreshold:.1,luminanceSmoothing:.3,mipmapBlur:!0,intensity:4};class Se{constructor(e){this.active=!0,this.options=e;const{renderer:t,scene:s,camera:r,composerParams:i}=e,{multisampling:o}=i,{maxSamples:a}=t.capabilities,c=new v.EffectComposer(t,{multisampling:Math.min(o,a)});c.addPass(new v.RenderPass(s,r)),this.finalComposer=c,this.renderer=t,this.scene=s,this.camera=r}addCopyPass(){const e=new v.CopyPass;e.renderToScreen=!0,this.finalComposer.addPass(e),this.copyPass=e}addFXAAPass(){const{camera:e}=this,t=new v.FXAAEffect({blendFunction:v.BlendFunction.NORMAL}),s=new v.EffectPass(e,t);this.finalComposer.addPass(s),this.fxaaPass=s}addBloomPass(e){const{camera:t,scene:s}=this,r=new v.SelectiveBloomEffect(s,t,P({},e)),i=new v.EffectPass(t,r);i.enabled=!1,this.finalComposer.addPass(i),this.bloomPass=i,this.bloomEffect=r}addBloomGui(e){if(!this.bloomEffect)return;new O({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 l.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 Oe=()=>{try{const n=document.createElement("canvas");return!!(window.WebGL2RenderingContext&&n.getContext("webgl2"))}catch(n){return!1}},L=!1,U=Oe()!==!1,K=class{constructor(n){this.raycaster=new l.Raycaster,this.installPlugins=new Map,this.event=new R.EventEmitter,this.clock=new l.Clock,this.userData={},this.options=te(K.options,n,{isMergeableObject:ce.isPlainObject});const{container:e,stats:t,gui:s,resizeObserver:r}=this.options;if(s){const i=new se;i.open(!1),this.gui=i}if(t){const i=new ne;i.showPanel(0),i.dom.style.position="absolute",e.appendChild(i.dom),this.stats=i}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:i}=this.options,{width:o,height:a}=this.getSize(),c=new Pe({isdev:e,width:o,height:a,cameraParams:i});this.gui&&c.setGui(this.gui);const f=c.camera,u=new Ee({camera:f,sceneParams:r}),m=u.scene,p=new be({width:o,height:a,scene:m,camera:f,isdev:e,rendererParams:_(P({},s),{antialias:!1})});this.gui&&p.setGui(this.gui);const g=p.renderer;t&&u.addAxesHelper(),this.sceneController=u,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:i}=t;i==="msaa"&&!U&&(i=!1,console.warn("MSAA is not supported on this browser"));const o=new Se({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:{multisampling:i==="msaa"?s:0,type:l.UnsignedByteType,encoding:t.outputEncoding}});this.composerController=o,n&&(o.addBloomPass(e),this.gui&&o.addBloomGui(this.gui)),i==="fxaa"&&o.addFXAAPass(),r&&r.forEach(a=>{o.finalComposer.addPass(a)}),o.addCopyPass()}initCSSRenderer(){const{container:n,css2DRenderer:e,css3DRenderer:t,css2DRendererParams:s,css3DRendererParams:r}=this.options;if(e||t){const i=new xe(n);e&&i.addRenderer("css2d",s),t&&i.addRenderer("css3d",r),this.cssRendererController=i}}initControl(){const{control:n,controlParams:e}=this.options;if(n){const t=new Le({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:i}=this;s==null||s.setSize(n,e),t==null||t.setSize(n,e),r==null||r.setSize(n,e),i==null||i.setSize(n,e),this.installPlugins.forEach((o,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:i}=r,o=new l.Vector2,a=i.getBoundingClientRect();if(o.x=(n.clientX-a.left)/(a.right-a.left)*2-1,o.y=-((n.clientY-a.top)/(a.bottom-a.top))*2+1,this.camera&&this.scene){s.setFromCamera(o,this.camera);const c=s.intersectObjects(e||this.scene.children,t);if(c.length)return{object:c[0].object,intersects:c}}}render(){var o,a,c,f,u;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(),i=s.getElapsedTime();(o=this.controlController)==null||o.update(),this.installPlugins.forEach((m,p)=>{var g;(g=p.update)==null||g.call(p,r,i)}),(a=this.composerController)!=null&&a.active?this.composerController.render():(c=this.rendererController)==null||c.render(),(f=this.cssRendererController)==null||f.render(e,t),(u=this.stats)==null||u.update(),this.event.emit("render",{delta:r,elapsed:i})}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,i,o;this.stop(),this.handeleResize(0,0),(n=this.resizeObserver)==null||n.unobserve(this.options.container),this.installPlugins.forEach((a,c)=>{var f;(f=c.dispose)==null||f.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(),(i=this.rendererController)==null||i.dispose(),this.controlController=void 0,this.cssRendererController=void 0,(o=this.gui)==null||o.destroy(),this.event.removeAllListeners(),this.installPlugins.clear()}};let A=K;A.options={isdev:L,stats:L,gui:L,axesHelper:L,control:L,resizeObserver:!0,renderer:_(P({},Ce),{antialias:U?"msaa":"fxaa"}),staticRender:!1,multisampling:4,scene:we,camera:ye,bloom:!1,bloomParams:Re,css2DRenderer:!1,css2DRendererParams:P({},B),css3DRenderer:!1,css3DRendererParams:P({},B)};exports.BaseObject=le.BaseObject;exports.GUIObject=O;exports.Pencil=A;exports.default=A;
|