gl-draw 0.15.0-beta.40 → 0.15.0-beta.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.module2.js +49 -51
- package/dist/index2.js +2 -2
- package/dist/objects/index.js +1 -1
- package/dist/objects/index.module.js +275 -268
- package/dist/objects/line/meshLine/MeshLineGeometry.d.ts +1 -1
- package/dist/objects/line/meshLine/MeshLineMaterial.d.ts +0 -5
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.module.js +21 -21
- package/package.json +1 -1
package/dist/index.module2.js
CHANGED
|
@@ -35,7 +35,7 @@ var ot = (n, t, e) => new Promise((i, s) => {
|
|
|
35
35
|
}, r = (c) => c.done ? i(c.value) : Promise.resolve(c.value).then(a, l);
|
|
36
36
|
r((e = e.apply(n, t)).next());
|
|
37
37
|
});
|
|
38
|
-
import { Material as at, Object3D as R, Texture as ct, VideoTexture as Bt, BufferGeometry as J, Float32BufferAttribute as G, PointsMaterial as zt, Points as H, InstancedMesh as wt, Vector3 as
|
|
38
|
+
import { Material as at, Object3D as R, Texture as ct, VideoTexture as Bt, BufferGeometry as J, Float32BufferAttribute as G, PointsMaterial as zt, Points as H, InstancedMesh as wt, Vector3 as I, Quaternion as Tt, Group as _t, Mesh as St, Sprite as lt, Box3 as jt, Vector4 as O, Matrix4 as Et, Line3 as Lt, Sphere as Ot, InstancedInterleavedBuffer as Vt, InterleavedBufferAttribute as ut, MathUtils as kt, REVISION as Wt, ShaderChunk as W, ShaderMaterial as Nt, Vector2 as K, Color as ft } from "three";
|
|
39
39
|
import { CSS2DObject as Ut } from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
40
40
|
import { CSS3DObject as Rt, CSS3DSprite as Gt } from "three/examples/jsm/renderers/CSS3DRenderer";
|
|
41
41
|
import { geoBounds as At, geoContains as $t, geoDistance as Ft, geoInterpolate as qt } from "d3-geo";
|
|
@@ -131,7 +131,7 @@ const ne = (n, t = 1) => {
|
|
|
131
131
|
if (n instanceof wt || n.isInstantiate)
|
|
132
132
|
n.setMatrixAt(s, r);
|
|
133
133
|
else if (n instanceof H || n.type === "Points") {
|
|
134
|
-
const o = n.geometry, h = o.attributes.position.array, f = o.attributes.scaleAtt.array, p = new
|
|
134
|
+
const o = n.geometry, h = o.attributes.position.array, f = o.attributes.scaleAtt.array, p = new I(), u = new I(), m = new Tt(), d = s * 3, v = s * 1;
|
|
135
135
|
r.decompose(p, m, u), h[d] = p.x, h[d + 1] = p.y, h[d + 2] = p.z, f[v] = Math.max(u.x, u.y, u.z), o.attributes.position.needsUpdate = !0, o.attributes.scaleAtt.needsUpdate = !0;
|
|
136
136
|
}
|
|
137
137
|
});
|
|
@@ -320,8 +320,8 @@ class mt extends ae {
|
|
|
320
320
|
return {
|
|
321
321
|
min: t.min,
|
|
322
322
|
max: t.max,
|
|
323
|
-
size: t.getSize(new
|
|
324
|
-
center: t.getCenter(new
|
|
323
|
+
size: t.getSize(new I()),
|
|
324
|
+
center: t.getCenter(new I())
|
|
325
325
|
};
|
|
326
326
|
}
|
|
327
327
|
setTop(t) {
|
|
@@ -390,7 +390,7 @@ class mt extends ae {
|
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
const Q = new O(), vt = new
|
|
393
|
+
const Q = new O(), vt = new I(), yt = new I(), g = new O(), b = new O(), B = new O(), X = new I(), Y = new Et(), M = new Lt(), gt = new I(), N = new jt(), U = new Ot(), z = new O();
|
|
394
394
|
let T, E;
|
|
395
395
|
function bt(n, t, e) {
|
|
396
396
|
return z.set(0, 0, -t, 1).applyMatrix4(n.projectionMatrix), z.multiplyScalar(1 / z.w), z.x = E / e.width, z.y = E / e.height, z.applyMatrix4(n.projectionMatrixInverse), z.multiplyScalar(1 / z.w), Math.abs(Math.max(z.x, z.y));
|
|
@@ -399,7 +399,7 @@ function ce(n, t) {
|
|
|
399
399
|
const e = n.matrixWorld, i = n.geometry, s = i.attributes.instanceStart, a = i.attributes.instanceEnd, l = Math.min(i.instanceCount, s.count);
|
|
400
400
|
for (let r = 0, c = l; r < c; r++) {
|
|
401
401
|
M.start.fromBufferAttribute(s, r), M.end.fromBufferAttribute(a, r), M.applyMatrix4(e);
|
|
402
|
-
const o = new
|
|
402
|
+
const o = new I(), h = new I();
|
|
403
403
|
T.distanceSqToSegment(M.start, M.end, h, o), h.distanceTo(o) < E * 0.5 && t.push({
|
|
404
404
|
point: h,
|
|
405
405
|
pointOnLine: o,
|
|
@@ -419,22 +419,22 @@ function le(n, t, e) {
|
|
|
419
419
|
if (g.fromBufferAttribute(c, p), b.fromBufferAttribute(o, p), g.w = 1, b.w = 1, g.applyMatrix4(Y), b.applyMatrix4(Y), g.z > f && b.z > f)
|
|
420
420
|
continue;
|
|
421
421
|
if (g.z > f) {
|
|
422
|
-
const
|
|
422
|
+
const D = g.z - b.z, j = (g.z - f) / D;
|
|
423
423
|
g.lerp(b, j);
|
|
424
424
|
} else if (b.z > f) {
|
|
425
|
-
const
|
|
425
|
+
const D = b.z - g.z, j = (b.z - f) / D;
|
|
426
426
|
b.lerp(g, j);
|
|
427
427
|
}
|
|
428
428
|
g.applyMatrix4(i), b.applyMatrix4(i), g.multiplyScalar(1 / g.w), b.multiplyScalar(1 / b.w), g.x *= a.x / 2, g.y *= a.y / 2, b.x *= a.x / 2, b.y *= a.y / 2, M.start.copy(g), M.start.z = 0, M.end.copy(b), M.end.z = 0;
|
|
429
429
|
const d = M.closestPointToPointParameter(X, !0);
|
|
430
430
|
M.at(d, gt);
|
|
431
|
-
const v = kt.lerp(g.z, b.z, d), w = v >= -1 && v <= 1,
|
|
432
|
-
if (w &&
|
|
431
|
+
const v = kt.lerp(g.z, b.z, d), w = v >= -1 && v <= 1, S = X.distanceTo(gt) < E * 0.5;
|
|
432
|
+
if (w && S) {
|
|
433
433
|
M.start.fromBufferAttribute(c, p), M.end.fromBufferAttribute(o, p), M.start.applyMatrix4(l), M.end.applyMatrix4(l);
|
|
434
|
-
const
|
|
435
|
-
T.distanceSqToSegment(M.start, M.end, j,
|
|
434
|
+
const D = new I(), j = new I();
|
|
435
|
+
T.distanceSqToSegment(M.start, M.end, j, D), e.push({
|
|
436
436
|
point: j,
|
|
437
|
-
pointOnLine:
|
|
437
|
+
pointOnLine: D,
|
|
438
438
|
distance: T.origin.distanceTo(j),
|
|
439
439
|
object: n,
|
|
440
440
|
face: null,
|
|
@@ -657,24 +657,22 @@ class Oe extends Nt {
|
|
|
657
657
|
color: i = "#ffffff",
|
|
658
658
|
opacity: s = 1,
|
|
659
659
|
map: a = null,
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
} = S, I = rt(S, [
|
|
660
|
+
dashOffset: l = 0,
|
|
661
|
+
dashArray: r = 0,
|
|
662
|
+
dashRatio: c = 0,
|
|
663
|
+
sizeAttenuation: o = !0,
|
|
664
|
+
offsetLoop: h = !0,
|
|
665
|
+
offset: f = new K(0, 0),
|
|
666
|
+
scaleDown: p = 0,
|
|
667
|
+
alphaMap: u = void 0,
|
|
668
|
+
alphaTest: m = 0,
|
|
669
|
+
repeat: d = new K(1, 1),
|
|
670
|
+
resolution: v = new K(1, 1)
|
|
671
|
+
} = S, w = rt(S, [
|
|
673
672
|
"lineWidth",
|
|
674
673
|
"color",
|
|
675
674
|
"opacity",
|
|
676
675
|
"map",
|
|
677
|
-
"useMap",
|
|
678
676
|
"dashOffset",
|
|
679
677
|
"dashArray",
|
|
680
678
|
"dashRatio",
|
|
@@ -687,26 +685,26 @@ class Oe extends Nt {
|
|
|
687
685
|
"repeat",
|
|
688
686
|
"resolution"
|
|
689
687
|
]);
|
|
690
|
-
super(q(L({},
|
|
688
|
+
super(q(L({}, w), {
|
|
691
689
|
uniforms: {
|
|
692
690
|
lineWidth: { value: e },
|
|
693
691
|
color: { value: new ft(i) },
|
|
694
692
|
opacity: { value: s },
|
|
695
693
|
map: { value: a },
|
|
696
|
-
useMap: { value: a ? 1 :
|
|
697
|
-
resolution: { value:
|
|
698
|
-
sizeAttenuation: { value:
|
|
699
|
-
offset: { value:
|
|
700
|
-
offsetLoop: { value:
|
|
701
|
-
dashArray: { value:
|
|
702
|
-
dashOffset: { value:
|
|
703
|
-
dashRatio: { value:
|
|
704
|
-
useDash: { value:
|
|
705
|
-
scaleDown: { value:
|
|
706
|
-
alphaTest: { value:
|
|
707
|
-
alphaMap: { value:
|
|
708
|
-
useAlphaMap: { value:
|
|
709
|
-
repeat: { value:
|
|
694
|
+
useMap: { value: a ? 1 : 0 },
|
|
695
|
+
resolution: { value: v },
|
|
696
|
+
sizeAttenuation: { value: o ? 1 : 0 },
|
|
697
|
+
offset: { value: f },
|
|
698
|
+
offsetLoop: { value: h ? 1 : 0 },
|
|
699
|
+
dashArray: { value: r },
|
|
700
|
+
dashOffset: { value: l },
|
|
701
|
+
dashRatio: { value: c },
|
|
702
|
+
useDash: { value: r > 0 ? 1 : 0 },
|
|
703
|
+
scaleDown: { value: p / 10 },
|
|
704
|
+
alphaTest: { value: m },
|
|
705
|
+
alphaMap: { value: u },
|
|
706
|
+
useAlphaMap: { value: u ? 1 : 0 },
|
|
707
|
+
repeat: { value: d }
|
|
710
708
|
},
|
|
711
709
|
vertexShader: fe,
|
|
712
710
|
fragmentShader: ue
|
|
@@ -853,14 +851,14 @@ function me(n, { resolution: t = 1 / 0, bbox: e, projection: i } = {}) {
|
|
|
853
851
|
const [y, x] = i([d[0], v[0]]), [A, C] = i([d[1], v[1]]);
|
|
854
852
|
d = [y, A], v = [-x, -C];
|
|
855
853
|
}
|
|
856
|
-
const w = pt(d, [0, 1]),
|
|
854
|
+
const w = pt(d, [0, 1]), S = pt(v, [0, 1]), D = r.map(([y, x]) => {
|
|
857
855
|
if (i) {
|
|
858
856
|
const [A, C] = i([y, x]);
|
|
859
|
-
return [w(A),
|
|
857
|
+
return [w(A), S(-C)];
|
|
860
858
|
} else
|
|
861
|
-
return [w(y),
|
|
859
|
+
return [w(y), S(x)];
|
|
862
860
|
});
|
|
863
|
-
return { contour: s, triangles: { points: r, indices: m, uvs:
|
|
861
|
+
return { contour: s, triangles: { points: r, indices: m, uvs: D } };
|
|
864
862
|
}
|
|
865
863
|
const Mt = new J().setAttribute ? "setAttribute" : "addAttribute";
|
|
866
864
|
function $(n, t, e, i) {
|
|
@@ -989,19 +987,19 @@ class Ve extends J {
|
|
|
989
987
|
userDataRsoOffset: o,
|
|
990
988
|
projection: h
|
|
991
989
|
} = this.parameters, { contour: f, sideTorso: p, topVerts: u, bottomCap: m, topCap: d } = ye(L({}, this.parameters));
|
|
992
|
-
let v = [], w = [],
|
|
990
|
+
let v = [], w = [], S = [], D = 0;
|
|
993
991
|
const j = (y) => {
|
|
994
|
-
const x = Math.round(v.length / 3), A =
|
|
995
|
-
v = v.concat(y.vertices), w = w.concat(y.uvs),
|
|
992
|
+
const x = Math.round(v.length / 3), A = S.length;
|
|
993
|
+
v = v.concat(y.vertices), w = w.concat(y.uvs), S = S.concat(
|
|
996
994
|
x ? y.indices.map((C) => C + x) : y.indices
|
|
997
|
-
), this.addGroup(A,
|
|
995
|
+
), this.addGroup(A, S.length - A, D++);
|
|
998
996
|
};
|
|
999
997
|
s && a && j(d), r && (j(p), this.userData.topVerts = o ? $(
|
|
1000
998
|
f,
|
|
1001
999
|
i + o,
|
|
1002
1000
|
c,
|
|
1003
1001
|
h
|
|
1004
|
-
).vertices : u), l && j(m), s && !a && j(d), this.setIndex(
|
|
1002
|
+
).vertices : u), l && j(m), s && !a && j(d), this.setIndex(S), this[Mt]("position", new G(v, 3)), this[Mt]("uv", new G(w, 2)), this.computeVertexNormals();
|
|
1005
1003
|
}
|
|
1006
1004
|
}
|
|
1007
1005
|
export {
|
package/dist/index2.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";var pe=Object.defineProperty,me=Object.defineProperties;var ve=Object.getOwnPropertyDescriptors;var W=Object.getOwnPropertySymbols;var H=Object.prototype.hasOwnProperty,ee=Object.prototype.propertyIsEnumerable;var te=Math.pow,J=(n,e,t)=>e in n?pe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,_=(n,e)=>{for(var t in e||(e={}))H.call(e,t)&&J(n,t,e[t]);if(W)for(var t of W(e))ee.call(e,t)&&J(n,t,e[t]);return n},q=(n,e)=>me(n,ve(e));var re=(n,e)=>{var t={};for(var r in n)H.call(n,r)&&e.indexOf(r)<0&&(t[r]=n[r]);if(n!=null&&W)for(var r of W(n))e.indexOf(r)<0&&ee.call(n,r)&&(t[r]=n[r]);return t};var ie=(n,e,t)=>new Promise((r,i)=>{var c=l=>{try{s(t.next(l))}catch(a){i(a)}},u=l=>{try{s(t.throw(l))}catch(a){i(a)}},s=l=>l.done?r(l.value):Promise.resolve(l.value).then(c,u);s((t=t.apply(n,e)).next())});const o=require("three"),ye=require("three/examples/jsm/renderers/CSS2DRenderer"),ne=require("three/examples/jsm/renderers/CSS3DRenderer"),O=require("d3-geo");require("d3-geo-projection");const Q=require("./parseVector.js"),be=require("three/examples/jsm/lines/LineSegmentsGeometry"),L=require("d3-array"),X=require("earcut"),ge=require("@turf/boolean-clockwise"),Me=require("delaunator"),Se=require("@turf/boolean-point-in-polygon"),xe=require("d3-geo-voronoi"),se=require("d3-scale"),we=0,je=1,Ae=2,Ce=!1;class fe{constructor(){this.resources=new Set,this.disposeMaterial=!0,this.disposeVideo=!0}track(e){if(!e)return e;if(Array.isArray(e))return e.forEach(t=>this.track(t)),e;if(!this.disposeMaterial&&e instanceof o.Material)return e;if(e instanceof Y?(e.disposeTrack&&e.object3d?this.track(e.object3d):this.resources.add(e),Object.values(e.materialList).map(t=>this.track(t))):(e instanceof o.Object3D||Reflect.has(e,"dispose"))&&this.resources.add(e),e instanceof Y)e.children.forEach(t=>{t.disposeTrack=!1}),this.track(e.children);else if(e instanceof o.Object3D){const t=e;this.track(t.geometry),this.track(t.material),this.track(t.children)}else if(e instanceof o.Material){for(const r of Object.values(e))r instanceof o.Texture&&this.track(r);const t=e;if(t.uniforms){for(const r of Object.values(t.uniforms))if(r){const i=r.value;(i instanceof o.Texture||Array.isArray(i))&&this.track(i)}}}else this.disposeVideo&&e instanceof o.VideoTexture&&e.source.data&&this.resources.add(e.source.data);return e}dispose(){const e=[];for(const t of this.resources)t instanceof o.Object3D?e.push(t):t instanceof HTMLVideoElement&&t.pause(),Reflect.has(t,"dispose")&&t.dispose();e.forEach(t=>{t.removeFromParent()}),e.length=0,this.resources.clear()}}const Pe=(n,e=1)=>{const t=new o.BufferGeometry;t.setAttribute("position",new o.Float32BufferAttribute(new Array(e*3).fill(0),3)),t.setAttribute("scaleAtt",new o.Float32BufferAttribute(new Array(e).fill(1),1));const r=n.material,i=new o.PointsMaterial({size:10,map:r.map,alphaMap:r.alphaMap,color:r.color,blending:r.blending,depthTest:r.depthTest,depthWrite:!1,opacity:r.opacity,transparent:!0,alphaTest:r.alphaTest,sizeAttenuation:!1});return i.onBeforeCompile=c=>{c.vertexShader=`
|
|
2
2
|
attribute float scaleAtt;
|
|
3
3
|
${c.vertexShader.replace("gl_PointSize = size;","gl_PointSize = size * scaleAtt;")}
|
|
4
|
-
`},new o.Points(t,i)},Be=(n,e)=>{const t=new o.Object3D;e.forEach((r,i)=>{const c=Q.parseVector3(r.position),u=Q.parseVector3(r.scale||[1,1,1]);t.position.copy(c),t.scale.copy(u),t.updateMatrix();const s=t.matrix.clone();if(n instanceof o.InstancedMesh||n.isInstantiate)n.setMatrixAt(i,s);else if(n instanceof o.Points||n.type==="Points"){const a=n.geometry,p=a.attributes.position.array,f=a.attributes.scaleAtt.array,m=new o.Vector3,d=new o.Vector3,v=new o.Quaternion,h=i*3,y=i*1;s.decompose(m,v,d),p[h]=m.x,p[h+1]=m.y,p[h+2]=m.z,f[y]=Math.max(d.x,d.y,d.z),a.attributes.position.needsUpdate=!0,a.attributes.scaleAtt.needsUpdate=!0}})};class Ie{constructor(){this.onPointerIndex=[]}onPointerEvent(e,t){const r=this.lead.handlePick([this],e,t);this.onPointerIndex.push(r)}onClick(e){this.onPointerEvent("click",e)}onPointerEnter(e){this.onPointerEvent("enter",e)}onPointerLeave(e){this.onPointerEvent("leave",e)}onPointerMove(e){this.onPointerEvent("move",e)}onPointerDown(e){this.onPointerEvent("down",e)}dispose(){this.onPointerIndex.forEach(e=>{this.lead.removePick(e)})}}class De extends Ie{constructor(){super(...arguments),this.userData={},this.materialList={},this.useMaterialType="origin",this.disposeMaterialIfNotUsed=!0}cloneMaterial(){const e=this.object3d;if(!e||!e.material)return;const t=e.material;if(Array.isArray(t))return t.map(r=>{const i=r.userData;r.userData={};const c=r.clone();return r.userData=i,c});{const r=t.userData;t.userData={};const i=t.clone();return t.userData=r,i}}setMaterialList(e,t){const r=this.object3d;if(!r||!r.material)return;this.materialList.origin||(this.materialList.origin=r.material);const i=t==="clone"?this.cloneMaterial():Array.isArray(t)?t.slice():t;return this.materialList[e]=i,i}useMaterial(e){const t=this.object3d;!t||!t.material||this.useMaterialType===e||!this.materialList[e]||(this.useMaterialType=e,t.material=this.materialList[e])}useMListById(e,t){if(!this.mList)return;const r=this.mList.get(e);if(!r)return;const i=this.object3d;Array.isArray(i.material)&&t!==void 0?i.material[t]=r:i.material=r}useMListByName(e,t){if(!this.mList)return;const r=this.mList.getKeyByName(e);r&&this.useMListById(r,t)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class Y extends De{constructor(){super(...arguments),this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.isBloom=!1,this.disposeTrack=!0}get parent(){const e=this.object3d.parent;return e&&this.lead.objMap.get(e)||null}get children(){return this.object3d.children.map(e=>this.lead.objMap.get(e)).filter(e=>!!e)}get position(){return this.object3d.position}get rotation(){return this.object3d.rotation}get scale(){return this.object3d.scale}get lookAt(){return this.object3d.lookAt}add(...e){[...e].forEach(t=>{this.lead.objMap.get(t)?this.object3d.add(t):this.lead.createBaseObject(t,{target:this})})}remove(...e){[...e].forEach(t=>{var r;this.lead.objMap.get(t)?(r=this.lead.objMap.get(t))==null||r.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}get visibleWithAncestors(){if(this.visible){let e=this.parent;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}else return!1}create(){this.createGroup()}render(){}update(e,t){}resize(e,t){}show(){return this.object3d.visible=!0,this.object3d.layers.set(we),this}hide(){return this.object3d.visible=!1,this.object3d.layers.set(Ae),this}createGroup(){return this.object3d=new o.Group,this}createMesh(...e){return this.object3d=new o.Mesh(...e),this}createPoints(...e){return this.object3d=new o.Points(...e),this}createCSS2DObject(e){return this.object3d=new ye.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new ne.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new ne.CSS3DSprite(e),this}createSprite(e){return this.object3d=new o.Sprite(e),this}attach(...e){return[...e].forEach(t=>{this.object3d.attach(t.object3d)}),this}getSize(){const e=new o.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new o.Vector3),center:e.getCenter(new o.Vector3)}}setTop(e){this.object3d&&(this.object3d.renderOrder=e)}traverse(e){e(this),this.children.forEach(t=>{t.traverse(e)})}instantiate(e){return ie(this,null,function*(){var l;const t=(l=e==null?void 0:e.recursive)!=null?l:!0,{objectType:r,objectOptions:i}=this,[,c]=r.split("#");let u=e==null?void 0:e.create;u===void 0&&(u=a=>{var p;if(this.object3d){if((p=e==null?void 0:e.instancedAttr)!=null&&p.length){const f=e.instancedAttr.length;if(this.object3d instanceof o.Sprite)a.object3d=Pe(this.object3d,f);else{const m=this.object3d,d=this.cloneMaterial();a.object3d=new o.InstancedMesh(m.geometry,d,f)}Be(a.object3d,e==null?void 0:e.instancedAttr)}else a.object3d=this.object3d.clone(!1),a.object3d.material&&(a.object3d.material=this.cloneMaterial());a.object3d.userData.prefab&&delete a.object3d.userData.prefab}});const s=yield this.lead.draw(c,q(_({},i||{}),{create:u,prefab:!1,key:(e==null?void 0:e.key)||(i==null?void 0:i.key),target:(e==null?void 0:e.target)||(i==null?void 0:i.target)}));return this.isBloom&&s.enableBloom(),t&&(yield Promise.all(this.children.map(a=>a.instantiate({target:s})))),s.isInstantiate=!0,s})}erase(){this.lead.erase(this)}handleMaterialChange(e){}enableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!0),this.isBloom=!0}disableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!1),this.isBloom=!1}dispose(){var e;if(super.dispose(),(e=this.pencil.composerController)==null||e.bloomSelection.delete(this),this.lead&&(this.lead.objects.delete(this.key),this.lead.objectWrapChindIdMap.delete(this),this.object3d&&this.lead.objMap.delete(this.object3d)),this.disposeTrack){const t=new fe;t.disposeMaterial=!1,t.track(this),t.dispose()}}}const F=new o.Vector4,oe=new o.Vector3,ae=new o.Vector3,g=new o.Vector4,M=new o.Vector4,D=new o.Vector4,$=new o.Vector3,K=new o.Matrix4,S=new o.Line3,ce=new o.Vector3,N=new o.Box3,U=new o.Sphere,V=new o.Vector4;let T,E;function le(n,e,t){return V.set(0,0,-e,1).applyMatrix4(n.projectionMatrix),V.multiplyScalar(1/V.w),V.x=E/t.width,V.y=E/t.height,V.applyMatrix4(n.projectionMatrixInverse),V.multiplyScalar(1/V.w),Math.abs(Math.max(V.x,V.y))}function Ve(n,e){const t=n.matrixWorld,r=n.geometry,i=r.attributes.instanceStart,c=r.attributes.instanceEnd,u=Math.min(r.instanceCount,i.count);for(let s=0,l=u;s<l;s++){S.start.fromBufferAttribute(i,s),S.end.fromBufferAttribute(c,s),S.applyMatrix4(t);const a=new o.Vector3,p=new o.Vector3;T.distanceSqToSegment(S.start,S.end,p,a),p.distanceTo(a)<E*.5&&e.push({point:p,pointOnLine:a,distance:T.origin.distanceTo(p),object:n,face:null,faceIndex:s,uv:null,uv1:null})}}function Te(n,e,t){const r=e.projectionMatrix,c=n.material.resolution,u=n.matrixWorld,s=n.geometry,l=s.attributes.instanceStart,a=s.attributes.instanceEnd,p=Math.min(s.instanceCount,l.count),f=-e.near;T.at(1,D),D.w=1,D.applyMatrix4(e.matrixWorldInverse),D.applyMatrix4(r),D.multiplyScalar(1/D.w),D.x*=c.x/2,D.y*=c.y/2,D.z=0,$.copy(D),K.multiplyMatrices(e.matrixWorldInverse,u);for(let m=0,d=p;m<d;m++){if(g.fromBufferAttribute(l,m),M.fromBufferAttribute(a,m),g.w=1,M.w=1,g.applyMatrix4(K),M.applyMatrix4(K),g.z>f&&M.z>f)continue;if(g.z>f){const
|
|
4
|
+
`},new o.Points(t,i)},Be=(n,e)=>{const t=new o.Object3D;e.forEach((r,i)=>{const c=Q.parseVector3(r.position),u=Q.parseVector3(r.scale||[1,1,1]);t.position.copy(c),t.scale.copy(u),t.updateMatrix();const s=t.matrix.clone();if(n instanceof o.InstancedMesh||n.isInstantiate)n.setMatrixAt(i,s);else if(n instanceof o.Points||n.type==="Points"){const a=n.geometry,p=a.attributes.position.array,f=a.attributes.scaleAtt.array,m=new o.Vector3,d=new o.Vector3,v=new o.Quaternion,h=i*3,y=i*1;s.decompose(m,v,d),p[h]=m.x,p[h+1]=m.y,p[h+2]=m.z,f[y]=Math.max(d.x,d.y,d.z),a.attributes.position.needsUpdate=!0,a.attributes.scaleAtt.needsUpdate=!0}})};class Ie{constructor(){this.onPointerIndex=[]}onPointerEvent(e,t){const r=this.lead.handlePick([this],e,t);this.onPointerIndex.push(r)}onClick(e){this.onPointerEvent("click",e)}onPointerEnter(e){this.onPointerEvent("enter",e)}onPointerLeave(e){this.onPointerEvent("leave",e)}onPointerMove(e){this.onPointerEvent("move",e)}onPointerDown(e){this.onPointerEvent("down",e)}dispose(){this.onPointerIndex.forEach(e=>{this.lead.removePick(e)})}}class De extends Ie{constructor(){super(...arguments),this.userData={},this.materialList={},this.useMaterialType="origin",this.disposeMaterialIfNotUsed=!0}cloneMaterial(){const e=this.object3d;if(!e||!e.material)return;const t=e.material;if(Array.isArray(t))return t.map(r=>{const i=r.userData;r.userData={};const c=r.clone();return r.userData=i,c});{const r=t.userData;t.userData={};const i=t.clone();return t.userData=r,i}}setMaterialList(e,t){const r=this.object3d;if(!r||!r.material)return;this.materialList.origin||(this.materialList.origin=r.material);const i=t==="clone"?this.cloneMaterial():Array.isArray(t)?t.slice():t;return this.materialList[e]=i,i}useMaterial(e){const t=this.object3d;!t||!t.material||this.useMaterialType===e||!this.materialList[e]||(this.useMaterialType=e,t.material=this.materialList[e])}useMListById(e,t){if(!this.mList)return;const r=this.mList.get(e);if(!r)return;const i=this.object3d;Array.isArray(i.material)&&t!==void 0?i.material[t]=r:i.material=r}useMListByName(e,t){if(!this.mList)return;const r=this.mList.getKeyByName(e);r&&this.useMListById(r,t)}dispose(){super.dispose(),this.mList.rmBaseObjectMap(this,void 0,this.disposeMaterialIfNotUsed)}}class Y extends De{constructor(){super(...arguments),this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.isBloom=!1,this.disposeTrack=!0}get parent(){const e=this.object3d.parent;return e&&this.lead.objMap.get(e)||null}get children(){return this.object3d.children.map(e=>this.lead.objMap.get(e)).filter(e=>!!e)}get position(){return this.object3d.position}get rotation(){return this.object3d.rotation}get scale(){return this.object3d.scale}get lookAt(){return this.object3d.lookAt}add(...e){[...e].forEach(t=>{this.lead.objMap.get(t)?this.object3d.add(t):this.lead.createBaseObject(t,{target:this})})}remove(...e){[...e].forEach(t=>{var r;this.lead.objMap.get(t)?(r=this.lead.objMap.get(t))==null||r.erase():this.object3d.remove(t)})}get visible(){return this.object3d.visible}get visibleWithAncestors(){if(this.visible){let e=this.parent;for(;e;){if(!e.visible)return!1;e=e.parent}return!0}else return!1}create(){this.createGroup()}render(){}update(e,t){}resize(e,t){}show(){return this.object3d.visible=!0,this.object3d.layers.set(we),this}hide(){return this.object3d.visible=!1,this.object3d.layers.set(Ae),this}createGroup(){return this.object3d=new o.Group,this}createMesh(...e){return this.object3d=new o.Mesh(...e),this}createPoints(...e){return this.object3d=new o.Points(...e),this}createCSS2DObject(e){return this.object3d=new ye.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new ne.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new ne.CSS3DSprite(e),this}createSprite(e){return this.object3d=new o.Sprite(e),this}attach(...e){return[...e].forEach(t=>{this.object3d.attach(t.object3d)}),this}getSize(){const e=new o.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new o.Vector3),center:e.getCenter(new o.Vector3)}}setTop(e){this.object3d&&(this.object3d.renderOrder=e)}traverse(e){e(this),this.children.forEach(t=>{t.traverse(e)})}instantiate(e){return ie(this,null,function*(){var l;const t=(l=e==null?void 0:e.recursive)!=null?l:!0,{objectType:r,objectOptions:i}=this,[,c]=r.split("#");let u=e==null?void 0:e.create;u===void 0&&(u=a=>{var p;if(this.object3d){if((p=e==null?void 0:e.instancedAttr)!=null&&p.length){const f=e.instancedAttr.length;if(this.object3d instanceof o.Sprite)a.object3d=Pe(this.object3d,f);else{const m=this.object3d,d=this.cloneMaterial();a.object3d=new o.InstancedMesh(m.geometry,d,f)}Be(a.object3d,e==null?void 0:e.instancedAttr)}else a.object3d=this.object3d.clone(!1),a.object3d.material&&(a.object3d.material=this.cloneMaterial());a.object3d.userData.prefab&&delete a.object3d.userData.prefab}});const s=yield this.lead.draw(c,q(_({},i||{}),{create:u,prefab:!1,key:(e==null?void 0:e.key)||(i==null?void 0:i.key),target:(e==null?void 0:e.target)||(i==null?void 0:i.target)}));return this.isBloom&&s.enableBloom(),t&&(yield Promise.all(this.children.map(a=>a.instantiate({target:s})))),s.isInstantiate=!0,s})}erase(){this.lead.erase(this)}handleMaterialChange(e){}enableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!0),this.isBloom=!0}disableBloom(){var e;(e=this.pencil.composerController)==null||e.setBloomSelection(this,!1),this.isBloom=!1}dispose(){var e;if(super.dispose(),(e=this.pencil.composerController)==null||e.bloomSelection.delete(this),this.lead&&(this.lead.objects.delete(this.key),this.lead.objectWrapChindIdMap.delete(this),this.object3d&&this.lead.objMap.delete(this.object3d)),this.disposeTrack){const t=new fe;t.disposeMaterial=!1,t.track(this),t.dispose()}}}const F=new o.Vector4,oe=new o.Vector3,ae=new o.Vector3,g=new o.Vector4,M=new o.Vector4,D=new o.Vector4,$=new o.Vector3,K=new o.Matrix4,S=new o.Line3,ce=new o.Vector3,N=new o.Box3,U=new o.Sphere,V=new o.Vector4;let T,E;function le(n,e,t){return V.set(0,0,-e,1).applyMatrix4(n.projectionMatrix),V.multiplyScalar(1/V.w),V.x=E/t.width,V.y=E/t.height,V.applyMatrix4(n.projectionMatrixInverse),V.multiplyScalar(1/V.w),Math.abs(Math.max(V.x,V.y))}function Ve(n,e){const t=n.matrixWorld,r=n.geometry,i=r.attributes.instanceStart,c=r.attributes.instanceEnd,u=Math.min(r.instanceCount,i.count);for(let s=0,l=u;s<l;s++){S.start.fromBufferAttribute(i,s),S.end.fromBufferAttribute(c,s),S.applyMatrix4(t);const a=new o.Vector3,p=new o.Vector3;T.distanceSqToSegment(S.start,S.end,p,a),p.distanceTo(a)<E*.5&&e.push({point:p,pointOnLine:a,distance:T.origin.distanceTo(p),object:n,face:null,faceIndex:s,uv:null,uv1:null})}}function Te(n,e,t){const r=e.projectionMatrix,c=n.material.resolution,u=n.matrixWorld,s=n.geometry,l=s.attributes.instanceStart,a=s.attributes.instanceEnd,p=Math.min(s.instanceCount,l.count),f=-e.near;T.at(1,D),D.w=1,D.applyMatrix4(e.matrixWorldInverse),D.applyMatrix4(r),D.multiplyScalar(1/D.w),D.x*=c.x/2,D.y*=c.y/2,D.z=0,$.copy(D),K.multiplyMatrices(e.matrixWorldInverse,u);for(let m=0,d=p;m<d;m++){if(g.fromBufferAttribute(l,m),M.fromBufferAttribute(a,m),g.w=1,M.w=1,g.applyMatrix4(K),M.applyMatrix4(K),g.z>f&&M.z>f)continue;if(g.z>f){const I=g.z-M.z,A=(g.z-f)/I;g.lerp(M,A)}else if(M.z>f){const I=M.z-g.z,A=(M.z-f)/I;M.lerp(g,A)}g.applyMatrix4(r),M.applyMatrix4(r),g.multiplyScalar(1/g.w),M.multiplyScalar(1/M.w),g.x*=c.x/2,g.y*=c.y/2,M.x*=c.x/2,M.y*=c.y/2,S.start.copy(g),S.start.z=0,S.end.copy(M),S.end.z=0;const h=S.closestPointToPointParameter($,!0);S.at(h,ce);const y=o.MathUtils.lerp(g.z,M.z,h),w=y>=-1&&y<=1,j=$.distanceTo(ce)<E*.5;if(w&&j){S.start.fromBufferAttribute(l,m),S.end.fromBufferAttribute(a,m),S.start.applyMatrix4(u),S.end.applyMatrix4(u);const I=new o.Vector3,A=new o.Vector3;T.distanceSqToSegment(S.start,S.end,A,I),t.push({point:A,pointOnLine:I,distance:T.origin.distanceTo(A),object:n,face:null,faceIndex:m,uv:null,uv1:null})}}}class ze extends o.Mesh{constructor(e=new be.LineSegmentsGeometry,t){super(e,t),this.isLineSegments2=!0,this.type="LineSegments2"}computeLineDistances(){const e=this.geometry,t=e.attributes.instanceStart,r=e.attributes.instanceEnd,i=new Float32Array(2*t.count);for(let u=0,s=0,l=t.count;u<l;u++,s+=2)oe.fromBufferAttribute(t,u),ae.fromBufferAttribute(r,u),i[s]=s===0?0:i[s-1],i[s+1]=i[s]+oe.distanceTo(ae);const c=new o.InstancedInterleavedBuffer(i,2,1);return e.setAttribute("instanceDistanceStart",new o.InterleavedBufferAttribute(c,1,0)),e.setAttribute("instanceDistanceEnd",new o.InterleavedBufferAttribute(c,1,1)),this}raycast(e,t){const r=this.material.worldUnits,i=e.camera;i===null&&!r&&console.error('LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.');const c=e.params.Line2!==void 0&&e.params.Line2.threshold||0;T=e.ray;const u=this.matrixWorld,s=this.geometry,l=this.material;E=l.linewidth+c,s.boundingSphere===null&&s.computeBoundingSphere(),U.copy(s.boundingSphere).applyMatrix4(u);let a;if(r)a=E*.5;else{const f=Math.max(i.near,U.distanceToPoint(T.origin));a=le(i,f,l.resolution)}if(U.radius+=a,T.intersectsSphere(U)===!1)return;s.boundingBox===null&&s.computeBoundingBox(),N.copy(s.boundingBox).applyMatrix4(u);let p;if(r)p=E*.5;else{const f=Math.max(i.near,N.distanceToPoint(T.origin));p=le(i,f,l.resolution)}N.expandByScalar(p),T.intersectsBox(N)!==!1&&(r?Ve(this,t):Te(this,i,t))}onBeforeRender(e){const t=this.material.uniforms;t&&t.resolution&&(e.getViewport(F),this.material.uniforms.resolution.value.set(F.z,F.w))}}const Ee=`
|
|
5
5
|
#include <fog_pars_fragment>
|
|
6
6
|
#include <logdepthbuf_pars_fragment>
|
|
7
7
|
|
|
@@ -136,4 +136,4 @@ void main() {
|
|
|
136
136
|
${o.ShaderChunk.logdepthbuf_vertex}
|
|
137
137
|
${o.ShaderChunk.fog_vertex}
|
|
138
138
|
}
|
|
139
|
-
`;class _e extends o.ShaderMaterial{constructor(e={}){const j=e,{lineWidth:t=1,color:r="#ffffff",opacity:i=1,map:c=null,
|
|
139
|
+
`;class _e extends o.ShaderMaterial{constructor(e={}){const j=e,{lineWidth:t=1,color:r="#ffffff",opacity:i=1,map:c=null,dashOffset:u=0,dashArray:s=0,dashRatio:l=0,sizeAttenuation:a=!0,offsetLoop:p=!0,offset:f=new o.Vector2(0,0),scaleDown:m=0,alphaMap:d=void 0,alphaTest:v=0,repeat:h=new o.Vector2(1,1),resolution:y=new o.Vector2(1,1)}=j,w=re(j,["lineWidth","color","opacity","map","dashOffset","dashArray","dashRatio","sizeAttenuation","offsetLoop","offset","scaleDown","alphaMap","alphaTest","repeat","resolution"]);super(q(_({},w),{uniforms:{lineWidth:{value:t},color:{value:new o.Color(r)},opacity:{value:i},map:{value:c},useMap:{value:c?1:0},resolution:{value:y},sizeAttenuation:{value:a?1:0},offset:{value:f},offsetLoop:{value:p?1:0},dashArray:{value:s},dashOffset:{value:u},dashRatio:{value:l},useDash:{value:s>0?1:0},scaleDown:{value:m/10},alphaTest:{value:v},alphaMap:{value:d},useAlphaMap:{value:d?1:0},repeat:{value:h}},vertexShader:Le,fragmentShader:Ee})),this.type="MeshLineMaterial"}get color(){return this.uniforms.color.value}set color(e){this.uniforms.color.value=new o.Color(e)}get opacity(){var e;return((e=this.uniforms)==null?void 0:e.opacity.value)||1}set opacity(e){this.uniforms&&(this.uniforms.opacity.value=e)}get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e,this.uniforms.useMap.value=e?1:0}get repeat(){return this.uniforms.repeat.value}set repeat(e){this.uniforms.repeat.value.copy(e)}get lineWidth(){return this.uniforms.lineWidth.value}set lineWidth(e){this.uniforms.lineWidth.value=e}get sizeAttenuation(){return this.uniforms.sizeAttenuation.value===1}set sizeAttenuation(e){this.uniforms.sizeAttenuation.value=e?1:0}}function Oe(n,e){return n.map(t=>{const r=[];let i;return t.forEach(c=>{if(i){const u=O.geoDistance(c,i)*180/Math.PI;if(u>e){const s=O.geoInterpolate(i,c),l=1/Math.ceil(u/e);let a=l;for(;a<1;)r.push(s(a)),a+=l}}r.push(i=c)}),r})}function ke(n,{minLng:e,maxLng:t,minLat:r,maxLat:i}={}){const c=Math.round(te(360/n,2)/Math.PI),u=(1+Math.sqrt(5))/2,s=d=>d/u*360%360-180,l=d=>Math.acos(2*d/c-1)/Math.PI*180-90,a=d=>c*(Math.cos((d+90)*Math.PI/180)+1)/2,p=[i!==void 0?Math.ceil(a(i)):0,r!==void 0?Math.floor(a(r)):c-1],f=e===void 0&&t===void 0?()=>!0:e===void 0?d=>d<=t:t===void 0?d=>d>=e:t>=e?d=>d>=e&&d<=t:d=>d>=e||d<=t,m=[];for(let d=p[0];d<=p[1];d++){const v=s(d);f(v)&&m.push([v,l(d)])}return m}function Z(n,e,t=!1){return t?O.geoContains(e,n):Se(n,e)}function We(n,e){const t={type:"Polygon",coordinates:n},[[r,i],[c,u]]=O.geoBounds(t);if(Math.min(Math.abs(c-r),Math.abs(u-i))<e)return[];const s=r>c||u>=89||i<=-89;return ke(e,{minLng:r,maxLng:c,minLat:i,maxLat:u}).filter(l=>Z(l,t,s))}function Ne(n,{resolution:e=1/0,bbox:t,projection:r}={}){const i=Oe(n,e),c=L.merge(i),u=We(n,e),s=[...c,...u],l={type:"Polygon",coordinates:n},[[a,p],[f,m]]=O.geoBounds(l),d=a>f||m>=89||p<=-89;let v=[];if(d){const b=xe.geoVoronoi(s).triangles(),x=new Map(s.map(([C,P],z)=>[`${C}-${P}`,z]));b.features.forEach(C=>{const P=C.geometry.coordinates[0].slice(0,3).reverse(),z=[];if(P.forEach(([B,R])=>{const k=`${B}-${R}`;x.has(k)&&z.push(x.get(k))}),z.length===3){if(z.some(B=>B<c.length)){const B=C.properties.circumcenter;if(!Z(B,l,d))return}v.push(...z)}})}else if(u.length){const b=Me.from(s);for(let x=0,C=b.triangles.length;x<C;x+=3){const P=[2,1,0].map(B=>b.triangles[x+B]),z=P.map(B=>s[B]);if(P.some(B=>B<c.length)){const B=[0,1].map(R=>L.mean(z,k=>k[R]));if(!Z(B,l,d))continue}v.push(...P)}}else{const{vertices:b,holes:x=[]}=X.flatten(i);v=X(b,x,2)}let h=t?[t[0],t[2]]:L.extent(s,b=>b[0]),y=t?[t[1],t[3]]:L.extent(s,b=>b[1]);if(r){const[b,x]=r([h[0],y[0]]),[C,P]=r([h[1],y[1]]);h=[b,C],y=[-x,-P]}const w=se.scaleLinear(h,[0,1]),j=se.scaleLinear(y,[0,1]),I=s.map(([b,x])=>{if(r){const[C,P]=r([b,x]);return[w(C),j(-P)]}else return[w(b),j(x)]});return{contour:i,triangles:{points:s,indices:v,uvs:I}}}const ue=new o.BufferGeometry().setAttribute?"setAttribute":"addAttribute";function G(n,e,t,r){const i=n.map(c=>c.map(([u,s])=>{if(r){const[l,a]=r([u,s]);return[l,-a,e]}return t?Q.polar2Cartesian(u,s,e):[u,s,e]}));return X.flatten(i)}function Ue(n,e,t,r,i){const{vertices:c,holes:u}=G(n,e,r,i),{vertices:s}=G(n,t,r,i),l=L.merge([s,c]),a=Math.round(s.length/3),p=new Set(u);let f=0;const m=[];for(let v=0;v<a;v++){let h=v+1;if(h===a)h=f;else if(p.has(h)){const y=h;h=f,f=y}m.push(v,v+a,h+a),m.push(h+a,h,v)}const d=[];for(let v=1;v>=0;v--)for(let h=0;h<a;h+=1)d.push(h/(a-1),v);return{indices:m,vertices:l,uvs:d,topVerts:s}}function de(n,e,t,r,i,c){return{indices:r?n.indices:n.indices.slice().reverse(),vertices:G([n.points],e,i,c).vertices,uvs:t}}const he=({polygonGeoJson:n,startHeight:e,endHeight:t,curvatureResolution:r=1,cartesian:i=!0,hasSide:c=!0,hasBottom:u=!1,hasTop:s=!1,projection:l,bbox:a})=>{n.forEach(w=>{ge(w)||w.reverse()});const{contour:p,triangles:f}=Ne(n,{resolution:r,bbox:a,projection:l});let m={},d;c&&(m=Ue(p,e!=null?e:t,t!=null?t:e,i,l),d=m.topVerts);let v=[];(u||s)&&(v=L.merge(f.uvs));let h={};u&&(h=de(f,e,v,!1,i,l));let y={};return s&&(y=de(f,t,v,!0,i,l)),{contour:p,triangles:f,sideTorso:m,bottomCap:h,topCap:y,topVerts:d}};class Ge extends o.BufferGeometry{constructor(e,t={}){super(),this.type="PolygonBufferGeometry",this.parameters=_({polygonGeoJson:e,startHeight:0,endHeight:1,hasTop:!0,topFirst:!1,hasBottom:!0,hasSide:!0,curvatureResolution:1,cartesian:!0,userDataRsoOffset:0},t);const{endHeight:r,hasTop:i,topFirst:c,hasBottom:u,hasSide:s,cartesian:l,userDataRsoOffset:a,projection:p}=this.parameters,{contour:f,sideTorso:m,topVerts:d,bottomCap:v,topCap:h}=he(_({},this.parameters));let y=[],w=[],j=[],I=0;const A=b=>{const x=Math.round(y.length/3),C=j.length;y=y.concat(b.vertices),w=w.concat(b.uvs),j=j.concat(x?b.indices.map(P=>P+x):b.indices),this.addGroup(C,j.length-C,I++)};i&&c&&A(h),s&&(A(m),this.userData.topVerts=a?G(f,r+a,l,p).vertices:d),u&&A(v),i&&!c&&A(h),this.setIndex(j),this[ue]("position",new o.Float32BufferAttribute(y,3)),this[ue]("uv",new o.Float32BufferAttribute(w,2)),this.computeVertexNormals()}}exports.BLOOM_SCENE=je;exports.BaseObject=Y;exports.IS_DEV=Ce;exports.LineSegments2=ze;exports.MeshLineMaterial=_e;exports.PolygonGeometry=Ge;exports.ResourceTracker=fe;exports.getMetas=he;
|
package/dist/objects/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var $e=Object.defineProperty,Xe=Object.defineProperties;var Ye=Object.getOwnPropertyDescriptors;var ce=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Be=(a,e,t)=>e in a?$e(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,E=(a,e)=>{for(var t in e||(e={}))Ee.call(e,t)&&Be(a,t,e[t]);if(ce)for(var t of ce(e))_e.call(e,t)&&Be(a,t,e[t]);return a},le=(a,e)=>Xe(a,Ye(e));var me=(a,e)=>{var t={};for(var n in a)Ee.call(a,n)&&e.indexOf(n)<0&&(t[n]=a[n]);if(a!=null&&ce)for(var n of ce(a))e.indexOf(n)<0&&_e.call(a,n)&&(t[n]=a[n]);return t};var ne=(a,e,t)=>new Promise((n,s)=>{var o=r=>{try{p(t.next(r))}catch(y){s(y)}},l=r=>{try{p(t.throw(r))}catch(y){s(y)}},p=r=>r.done?n(r.value):Promise.resolve(r.value).then(o,l);p((t=t.apply(a,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("../index2.js"),u=require("three"),Ze=require("@tweenjs/tween.js"),Je=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),pe=require("three/examples/jsm/utils/BufferGeometryUtils"),Qe=require("three/examples/jsm/lines/LineSegments2"),Re=require("three/examples/jsm/lines/LineSegmentsGeometry"),De=require("three/examples/jsm/lines/LineMaterial"),Pe=require("../uvGenerator.js"),he=require("three-bvh-csg");function Ke(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const K=Ke(Ze);class et extends _.BaseObject{constructor(e){super(),this.objectType="BaseObject#Node",this.onNodePointerIndex=[],this.options=E({type:"2d"},e)}create(){const{position:e,children:t}=this.options,n=document.createElement("div");this.element=n,t&&n.appendChild(t),this.options.type==="3d"?this.createCSS3DObject(n):this.options.type==="3dSprite"?this.createCSS3DSprite(n):this.createCSS2DObject(n),e&&this.object3d.position.copy(e)}setChildren(e){this.options.children=e,this.element.innerHTML="",this.element.appendChild(e)}showAndEnsureVisible(){const e=this.options.children;e&&(e.style.visibility="hidden",this.show(),setTimeout(()=>{e.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const e=this.options.children;if(!e)return;const t=e.getBoundingClientRect(),n=window.innerWidth,s=window.innerHeight;let o=0,l=0;t.left<0?o=-t.left:t.right>n&&(o=n-t.right),t.top<0?l=-t.top:t.bottom>s&&(l=s-t.bottom),t.left+o<0&&(o=-t.left),t.top+l<0&&(l=-t.top),(o!==0||l!==0)&&(e.style.transform=`translate(${o}px, ${l}px)`)}ensureVisible(){const e=this.options.children;if(!e)return;e.style.transform&&(e.style.transform="");const t=new IntersectionObserver(n=>{n.forEach(s=>{s.isIntersecting&&(this.moveElementToViewport(),t.disconnect())})});t.observe(e)}onPointerEvent(e,t){const n=this.lead.handlePickNode([this],e,t);this.onNodePointerIndex.push(n)}dispose(){this.onNodePointerIndex.forEach(e=>{this.lead.removePickNode(e)}),super.dispose()}}class tt extends _.BaseObject{create(){this.createGroup()}}const nt={ArcCurve:u.ArcCurve,CatmullRomCurve3:u.CatmullRomCurve3,CubicBezierCurve:u.CubicBezierCurve,CubicBezierCurve3:u.CubicBezierCurve3,EllipseCurve:u.EllipseCurve,LineCurve:u.LineCurve,LineCurve3:u.LineCurve3,QuadraticBezierCurve:u.QuadraticBezierCurve,QuadraticBezierCurve3:u.QuadraticBezierCurve3,SplineCurve:u.SplineCurve};class Z extends u.BufferGeometry{constructor(e=new u.Shape([new u.Vector2(.5,.5),new u.Vector2(-.5,.5),new u.Vector2(-.5,-.5),new u.Vector2(.5,-.5)]),t={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:e,options:t},e=Array.isArray(e)?e:[e];const n=this,s=[],o=[];for(let p=0,r=e.length;p<r;p++){const y=e[p];l(y)}this.setAttribute("position",new u.Float32BufferAttribute(s,3)),this.setAttribute("uv",new u.Float32BufferAttribute(o,2)),this.computeVertexNormals();function l(p){var Se,Ae,Me;const r=[],y=t.curveSegments!==void 0?t.curveSegments:12,i=t.steps!==void 0?t.steps:1,c=t.depth!==void 0?t.depth:1;let x=t.bevelEnabled!==void 0?t.bevelEnabled:!0,f=t.bevelThickness!==void 0?t.bevelThickness:.2,w=t.bevelSize!==void 0?t.bevelSize:f-.1,C=t.bevelOffset!==void 0?t.bevelOffset:0,L=t.bevelSegments!==void 0?t.bevelSegments:3;const M=t.extrudePath,B=t.UVGenerator!==void 0?t.UVGenerator:st,S=(Se=t.hasTop)!=null?Se:!0,I=(Ae=t.hasBottom)!=null?Ae:!0,ue=(Me=t.hasSide)!=null?Me:!0;let F,J=!1,$,ee,te,D;M&&(F=M.getSpacedPoints(i),J=!0,x=!1,$=M.computeFrenetFrames(i,!1),ee=new u.Vector3,te=new u.Vector3,D=new u.Vector3),x||(L=0,f=0,w=0,C=0);const ye=p.extractPoints(y);let z=ye.shape;const P=ye.holes;if(!u.ShapeUtils.isClockWise(z)){z=z.reverse();for(let h=0,d=P.length;h<d;h++){const m=P[h];u.ShapeUtils.isClockWise(m)&&(P[h]=m.reverse())}}function be(h){const m=10000000000000001e-36;let b=h[0];for(let g=1;g<=h.length;g++){const A=g%h.length,v=h[A],T=v.x-b.x,G=v.y-b.y,j=T*T+G*G,V=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(b.x),Math.abs(b.y)),Y=m*V*V;if(j<=Y){h.splice(A,1),g--;continue}b=v}}be(z),P.forEach(be);const fe=P.length,U=z;for(let h=0;h<fe;h++){const d=P[h];z=z.concat(d)}function Q(h,d,m){return d||console.error("THREE.ExtrudeGeometry: vec does not exist"),h.clone().addScaledVector(d,m)}const H=z.length;function xe(h,d,m){let b,g,A;const v=h.x-d.x,T=h.y-d.y,G=m.x-h.x,j=m.y-h.y,V=v*v+T*T,Y=v*j-T*G;if(Math.abs(Y)>Number.EPSILON){const O=Math.sqrt(V),Le=Math.sqrt(G*G+j*j),Ce=d.x-T/O,Te=d.y+v/O,ke=m.x-j/Le,Fe=m.y+G/Le,Ge=((ke-Ce)*j-(Fe-Te)*G)/(v*j-T*G);b=Ce+v*Ge-h.x,g=Te+T*Ge-h.y;const je=b*b+g*g;if(je<=2)return new u.Vector2(b,g);A=Math.sqrt(je/2)}else{let O=!1;v>Number.EPSILON?G>Number.EPSILON&&(O=!0):v<-Number.EPSILON?G<-Number.EPSILON&&(O=!0):Math.sign(T)===Math.sign(j)&&(O=!0),O?(b=-T,g=v,A=Math.sqrt(V)):(b=v,g=T,A=Math.sqrt(V/2))}return new u.Vector2(b/A,g/A)}const ie=[];for(let h=0,d=U.length,m=d-1,b=h+1;h<d;h++,m++,b++)m===d&&(m=0),b===d&&(b=0),ie[h]=xe(U[h],U[m],U[b]);const de=[];let k,oe=ie.concat();for(let h=0,d=fe;h<d;h++){const m=P[h];k=[];for(let b=0,g=m.length,A=g-1,v=b+1;b<g;b++,A++,v++)A===g&&(A=0),v===g&&(v=0),k[b]=xe(m[b],m[A],m[v]);de.push(k),oe=oe.concat(k)}let X;if(L===0)X=u.ShapeUtils.triangulateShape(U,P);else{const h=[],d=[];for(let m=0;m<L;m++){const b=m/L,g=f*Math.cos(b*Math.PI/2),A=w*Math.sin(b*Math.PI/2)+C;for(let v=0,T=U.length;v<T;v++){const G=Q(U[v],ie[v],A);N(G.x,G.y,-g),b===0&&h.push(G)}for(let v=0,T=fe;v<T;v++){const G=P[v];k=de[v];const j=[];for(let V=0,Y=G.length;V<Y;V++){const O=Q(G[V],k[V],A);N(O.x,O.y,-g),b===0&&j.push(O)}b===0&&d.push(j)}}X=u.ShapeUtils.triangulateShape(h,d)}const re=X.length,we=w+C;for(let h=0;h<H;h++){const d=x?Q(z[h],oe[h],we):z[h];J?(te.copy($.normals[0]).multiplyScalar(d.x),ee.copy($.binormals[0]).multiplyScalar(d.y),D.copy(F[0]).add(te).add(ee),N(D.x,D.y,D.z)):N(d.x,d.y,0)}for(let h=1;h<=i;h++)for(let d=0;d<H;d++){const m=x?Q(z[d],oe[d],we):z[d];J?(te.copy($.normals[h]).multiplyScalar(m.x),ee.copy($.binormals[h]).multiplyScalar(m.y),D.copy(F[h]).add(te).add(ee),N(D.x,D.y,D.z)):N(m.x,m.y,c/i*h)}for(let h=L-1;h>=0;h--){const d=h/L,m=f*Math.cos(d*Math.PI/2),b=w*Math.sin(d*Math.PI/2)+C;for(let g=0,A=U.length;g<A;g++){const v=Q(U[g],ie[g],b);N(v.x,v.y,c+m)}for(let g=0,A=P.length;g<A;g++){const v=P[g];k=de[g];for(let T=0,G=v.length;T<G;T++){const j=Q(v[T],k[T],b);J?N(j.x,j.y+F[i-1].y,F[i-1].x+m):N(j.x,j.y,c+m)}}}Ne(),ue&&We();function Ne(){const h=s.length/3;if(x){let d=0,m=H*d;if(I)for(let b=0;b<re;b++){const g=X[b];ae(g[2]+m,g[1]+m,g[0]+m)}if(d=i+L*2,m=H*d,S)for(let b=0;b<re;b++){const g=X[b];ae(g[0]+m,g[1]+m,g[2]+m)}}else{if(I)for(let d=0;d<re;d++){const m=X[d];ae(m[2],m[1],m[0])}if(S)for(let d=0;d<re;d++){const m=X[d];ae(m[0]+H*i,m[1]+H*i,m[2]+H*i)}}n.addGroup(h,s.length/3-h,0)}function We(){const h=s.length/3;let d=0;ve(U,d),d+=U.length;for(let m=0,b=P.length;m<b;m++){const g=P[m];ve(g,d),d+=g.length}n.addGroup(h,s.length/3-h,1)}function ve(h,d){let m=h.length;for(;--m>=0;){const b=m;let g=m-1;g<0&&(g=h.length-1);for(let A=0,v=i+L*2;A<v;A++){const T=H*A,G=H*(A+1),j=d+b+T,V=d+g+T,Y=d+g+G,O=d+b+G;qe(j,V,Y,O)}}}function N(h,d,m){r.push(h),r.push(d),r.push(m)}function ae(h,d,m){W(h),W(d),W(m);const b=s.length/3,g=B.generateTopUV(n,s,b-3,b-2,b-1);q(g[0]),q(g[1]),q(g[2])}function qe(h,d,m,b){W(h),W(d),W(b),W(d),W(m),W(b);const g=s.length/3,A=B.generateSideWallUV(n,s,g-6,g-3,g-2,g-1);q(A[0]),q(A[1]),q(A[3]),q(A[1]),q(A[2]),q(A[3])}function W(h){s.push(r[h*3+0]),s.push(r[h*3+1]),s.push(r[h*3+2])}function q(h){o.push(h.x),o.push(h.y)}}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON(),t=this.parameters.shapes,n=this.parameters.options;return it(t,n,e)}static fromJSON(e,t){const n=[];for(let o=0,l=e.shapes.length;o<l;o++){const p=t[e.shapes[o]];n.push(p)}const s=e.options.extrudePath;return s!==void 0&&(e.options.extrudePath=new nt[`${s.type}`]().fromJSON(s)),new Z(n,e.options)}}const st={generateTopUV:function(a,e,t,n,s){const o=e[t*3],l=e[t*3+1],p=e[n*3],r=e[n*3+1],y=e[s*3],i=e[s*3+1];return[new u.Vector2(o,l),new u.Vector2(p,r),new u.Vector2(y,i)]},generateSideWallUV:function(a,e,t,n,s,o){const l=e[t*3],p=e[t*3+1],r=e[t*3+2],y=e[n*3],i=e[n*3+1],c=e[n*3+2],x=e[s*3],f=e[s*3+1],w=e[s*3+2],C=e[o*3],L=e[o*3+1],M=e[o*3+2];return Math.abs(p-i)<Math.abs(l-y)?[new u.Vector2(l,1-r),new u.Vector2(y,1-c),new u.Vector2(x,1-w),new u.Vector2(C,1-M)]:[new u.Vector2(p,1-r),new u.Vector2(i,1-c),new u.Vector2(f,1-w),new u.Vector2(L,1-M)]}};function it(a,e,t){if(t.shapes=[],Array.isArray(a))for(let n=0,s=a.length;n<s;n++){const o=a[n];t.shapes.push(o.uuid)}else t.shapes.push(a.uuid);return t.options=Object.assign({},e),e.extrudePath!==void 0&&(t.options.extrudePath=e.extrudePath.toJSON()),t}class ot extends _.BaseObject{constructor(e){super(),this.options=E({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},e)}create(){return ne(this,null,function*(){this.createGroup();const{data:e,maxDepth:t,colors:n,material:s,percentDepth:o,activeIndex:l}=this.options,p=Math.max(...e),r=e.reduce((i,c)=>i+c,0);let y=Math.PI/2;e.forEach((i,c)=>{if(i===0)return;const x=Math.PI*2*(i/r),f=n[c],w=o?t*(i/p):t,C=this.createGeometry(w,x),L=s?s.clone():new u.MeshBasicMaterial({color:f});s&&L.color.set(f);const M=new u.Mesh(C,L);M.userData.depth=w,M.userData.index=c,M.rotateZ(y),y+=x,this.add(M)}),l!==-1&&this.setActive(l)})}createGeometry(e,t){const{outRadius:n,innerRadius:s}=this.options,o=new u.Shape;return o.moveTo(n,0),o.lineTo(s,0),o.absarc(0,0,s,0,t,!1),o.absarc(0,0,n,t,0,!0),new Z(o,{curveSegments:48,depth:e,bevelEnabled:!1})}handlePick(e,t=1.3){const{object:n}=this.pencil.pick(e,this.object3d.children)||{},s=n?this.object3d.children.findIndex(o=>o===n):this.options.activeIndex;return this.setActive(s,t)}setActive(e,t=1.3){const n=this.object3d.children[e];if(this.object3d.children.forEach(s=>{if(!(n&&n===s)&&s.scale.z!==1){if(s.userData.levTween)return;s.userData.enTween&&(s.userData.enTween.stop(),s.userData.enTween=null);const o=new K.Tween(s.scale).to({z:1},100);s.userData.levTween=o,o.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const s=new K.Tween(n.scale).to({z:t},100);return n.userData.enTween=s,s.start(),n.userData.index}return-1}render(){this.object3d.scale.z=0,new K.Tween(this.object3d.scale).to({z:1},1e3).easing(K.Easing.Sinusoidal.InOut).start()}}class rt extends _.BaseObject{constructor(e){super(),this.rectAreaLightUniformsLibInit=!1,this.options=e}create(){var t,n,s,o,l,p,r,y,i,c,x,f,w,C,L,M,B;const e=this.options;if(e.type==="AmbientLight"){const S=new u.AmbientLight(e.color);S.name="环境光",this.object3d=S}else if(e.type==="DirectionalLight"){const S=new u.DirectionalLight(e.color,e.intensity);S.name="平行光",S.target.position.set(0,0,0),this.object3d=S,S.target.name="平行光目标",S.shadow.camera.name="平行光阴影相机",S.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=S}else if(e.type==="PointLight"){const S=new u.PointLight((t=e.color)!=null?t:16777215,(n=e.intensity)!=null?n:1,(s=e.distance)!=null?s:0,(o=e.decay)!=null?o:2);S.name="点光源",this.object3d=S,this.pointLight=S}else if(e.type==="SpotLight"){const S=new u.SpotLight((l=e.color)!=null?l:16777215,(p=e.intensity)!=null?p:1,(r=e.distance)!=null?r:0,(y=e.angle)!=null?y:Math.PI/3,(i=e.penumbra)!=null?i:1,(c=e.decay)!=null?c:2);S.name="聚光灯",this.object3d=S,this.spotLight=S,S.target.name="聚光灯目标"}else if(e.type==="HemisphereLight"){const S=new u.HemisphereLight((x=e.color)!=null?x:16777215,(f=e.groundColor)!=null?f:16777215,(w=e.intensity)!=null?w:1);S.name="半球光",this.object3d=S,this.hemisphereLight=S}else if(e.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Je.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const S=new u.RectAreaLight((C=e.color)!=null?C:16777215,(L=e.intensity)!=null?L:1,(M=e.width)!=null?M:10,(B=e.height)!=null?B:10);S.name="矩形区域光",this.object3d=S,this.rectAreaLight=S}}render(){const e=this.object3d;e.target&&this.pencil.scene.add(e.target);const t=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const n=this.spotLight||this.directionalLight;n.position.copy(t),n.target.position.copy(t)}else this.pointLight&&this.pointLight.position.copy(t)}dispose(){const e=this.object3d;e.target&&this.pencil.scene.remove(e.target),super.dispose()}}function R(a,e=0){const t=a[0].index!==null,n=new Set(Object.keys(a[0].attributes)),s=new Set(Object.keys(a[0].morphAttributes)),o={},l={},p=a[0].morphTargetsRelative,r=new u.BufferGeometry;let y=0;for(let i=0;i<a.length;++i){const c=a[i];let x=0;if(t!==(c.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in c.attributes){if(!n.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;o[f]===void 0&&(o[f]=[]),o[f].push(c.attributes[f]),x++}if(x!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". Make sure all geometries have the same number of attributes."),null;if(p!==c.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in c.morphAttributes){if(!s.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphAttributes must be consistent throughout all geometries."),null;l[f]===void 0&&(l[f]=[]),l[f].push(c.morphAttributes[f])}if(e){let f;if(t)f=c.index.count;else if(c.attributes.position!==void 0)f=c.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". The geometry must have either an index or a position attribute"),null;if(e===1)r.addGroup(y,f,i);else if(e===2&&c.groups.length>0)for(let w of c.groups){let C=w.materialIndex;r.addGroup(y+w.start,Math.min(w.count,f),C)}y+=f}}if(t){let i=0;const c=[];for(let x=0;x<a.length;++x){const f=a[x].index;for(let w=0;w<f.count;++w)c.push(f.getX(w)+i);i+=a[x].attributes.position.count}r.setIndex(c)}for(const i in o){const c=pe.mergeAttributes(o[i]);if(!c)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" attribute."),null;r.setAttribute(i,c)}for(const i in l){const c=l[i][0].length;if(c===0)break;r.morphAttributes=r.morphAttributes||{},r.morphAttributes[i]=[];for(let x=0;x<c;++x){const f=[];for(let C=0;C<l[i].length;++C)f.push(l[i][C][x]);const w=pe.mergeAttributes(f);if(!w)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" morphAttribute."),null;r.morphAttributes[i].push(w)}}return e===2?pe.mergeGroups(r):r}const Ve=a=>{const{points:e}=a,t=e.reduce((s,o,l)=>(l<e.length-1&&s.push(o,e[l+1]),s),[]);return new u.BufferGeometry().setFromPoints(t)};let at=class extends _.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return ne(this,null,function*(){const{points:e,pointsArr:t,geometry:n,geometryArr:s,material:o,useGroups:l,setPointWidth:p,lineWidthArr:r,materialParameters:y,instanceCount:i}=this.options;let c=o,x=n;!c&&y&&(c=this.getMaterial(y)),!x&&e?x=Ve({points:e}):!x&&t?x=R(t.map(w=>Ve({points:w})),l!=null?l:0):!x&&s&&s.length>1?x=R(s,l!=null?l:0):!x&&s&&s.length===1&&([x]=s);const f=new Re.LineSegmentsGeometry().fromLineSegments(new u.LineSegments(x));if(this.pencil.options.WebGPUTHREE){i&&(f.instanceCount=i);const w=new _.LineSegments2(f,c);w.computeLineDistances(),this.object3d=w}else{const w=new Qe.LineSegments2(f,c);w.computeLineDistances(),this.object3d=w}})}getMaterial(e){return new De.LineMaterial(E({color:new u.Color("#ffffff")},e))}};const se=(a,e,t,n,s)=>{a[e+0]=t,a[e+1]=n,a[e+2]=s,a[e+3]=t,a[e+4]=n,a[e+5]=s},Oe=(a,e,t,n)=>{a[e+0]=t,a[e+1]=n},ze=(a,e,t,n,s)=>{a[e+0]=t,a[e+1]=n,a[e+2]=s},ct=(a,e,t,n,s,o)=>{a[e+0]=t,a[e+1]=n,a[e+2]=s,a[e+3]=o};class He extends u.BufferGeometry{constructor(e=[],t="none",n){super(),this.type="MeshLineGeometry",this.pointCount=0,this._points=[],this.shape="none",this.shapeFunction=s=>1,this.matrixWorld=new u.Matrix4,this.shape=t,n&&(this.shapeFunction=n),e.length>0&&this.setPoints(e)}convertToVector3Array(e){return e.map(t=>{var n;if(t instanceof u.Vector2)return new u.Vector3(t.x,t.y,0);if(t instanceof u.Vector3)return t;if(Array.isArray(t)&&t.length>=2)return new u.Vector3(t[0],t[1],(n=t[2])!=null?n:0)}).filter(Boolean)}setMatrixWorld(e){this.matrixWorld=e}setPoints(e,t){!e||e.length===0||(this._points=this.convertToVector3Array(e),this.pointCount=this._points.length,t&&(this.shapeFunction=t,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const e=[];let t=0;const n=[],s=[];let o=0;const l=[];let p=0;const r=[];let y=0;this.shape==="taper"&&(this.shapeFunction=i=>1*Math.pow(4*i*(1-i),1));for(let i=0;i<this.pointCount;i++){const c=i/this._points.length;e[t+0]=c,e[t+1]=c,t+=2,Oe(n,o,1,-1);const x=this.shape==="none"?1:this.shapeFunction(i/(this.pointCount-1));if(Oe(s,o,x,x),o+=2,ct(l,p,i/(this.pointCount-1),0,i/(this.pointCount-1),1),p+=4,i<this.pointCount-1){const f=i*2;ze(r,y,f+0,f+1,f+2),ze(r,y+3,f+2,f+1,f+3),y+=6}}this.setAttribute("position",new u.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("previous",new u.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("next",new u.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("counters",new u.BufferAttribute(new Float32Array(e),1)),this.setAttribute("side",new u.BufferAttribute(new Float32Array(n),1)),this.setAttribute("width",new u.BufferAttribute(new Float32Array(s),1)),this.setAttribute("uv",new u.BufferAttribute(new Float32Array(l),2)),this.setIndex(new u.BufferAttribute(new Uint16Array(r),1))}updateGeometry(){if(!this._points[0])return;const e=[],t=[],n=[];let s=0,o=0,l=0;se(t,o,this._points[0].x,this._points[0].y,this._points[0].z),o+=6;for(let i=0;i<this.pointCount;i++){const c=this._points[i];se(e,s,c.x,c.y,c.z),s+=6,i<this.pointCount-1&&(se(t,o,c.x,c.y,c.z),o+=6),i>0&&i+1<=this.pointCount&&(se(n,l,c.x,c.y,c.z),l+=6)}se(n,l,this._points[this.pointCount-1].x,this._points[this.pointCount-1].y,this._points[this.pointCount-1].z);const p=this.getAttribute("position"),r=this.getAttribute("previous"),y=this.getAttribute("next");p.set(e),r.set(t),y.set(n),p.needsUpdate=!0,r.needsUpdate=!0,y.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(e){this.setPoints(e)}updatePoints(e,t){const n=this.convertToVector3Array(e);if(n.length!==this.pointCount){console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.");return}this._points=n,t&&(this.shapeFunction=t,this.shape="custom",this.initializeGeometry()),this.updateGeometry()}setShape(e,t){this.shape=e,t&&(this.shapeFunction=t),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}const ge=a=>{const{setPointWidth:e,nodes:t}=a,n=new He;return n.setPoints(t,e),n};class lt extends _.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return ne(this,null,function*(){const{nodes:e,nodesArr:t,geometry:n,geometryArr:s,material:o,useGroups:l,setPointWidth:p,lineWidthArr:r,materialParameters:y}=this.options;let i=o,c=n;!i&&y&&(i=this.getMaterial(y)),!c&&e?c=ge({nodes:e,setPointWidth:p}):!c&&t?c=R(t.map((x,f)=>{let w=p;return!w&&r&&(w=()=>{var C;return(C=r[f])!=null?C:r[0]}),ge({nodes:x,setPointWidth:w})}),l!=null?l:0):!c&&s&&s.length>1?c=R(s,l!=null?l:0):!c&&s&&s.length===1&&([c]=s),this.createMesh(c,i)})}setGeometry(e,t){const n=ge({nodes:e,setPointWidth:t}),s=this.object3d,o=s.geometry;s.geometry=n,o.dispose()}getMaterial(e){const{width:t,height:n}=this.pencil.getSize(),s=new _.MeshLineMaterial(E({color:new u.Color("#ffffff")},e));return s.uniforms.resolution.value.set(t,n),s}addGeometries(e){const t=this.object3d,n=R([t.geometry,...e]);t.geometry=n}resize(e,t){var n,s;(s=(n=this.material)==null?void 0:n.uniforms)==null||s.resolution.value.set(e,t)}handleMaterialChange(e){if(e){const{width:t,height:n}=this.pencil.getSize();this.resize(t,n)}}animate({duration:e=1e3,delay:t=0,repeat:n=0,lineLoop:s,onRepeat:o,onUpdate:l,onComplete:p,startShow:r}={}){const{offset:y,offsetLoop:i}=this.material.uniforms;if(this.material.userData.tween)return;const c=s!=null?s:!0;y.value.x=1,i.value=c&&r?1:0;let x=0;const f=new K.Tween(y.value).to({x:-1},e).delay(t).repeat(n).onUpdate(({x:w})=>{c&&w<=0&&i.value===0&&(i.value=1),l&&l(w)}).onRepeat(()=>{x+=1,o&&o(x)}).onComplete(()=>{p&&p()}).start();this.material.userData.tween=f}render(){const{width:e,height:t}=this.pencil.getSize();this.resize(e,t)}dispose(){this.material.userData.tween&&(this.material.userData.tween.stop(),K.remove(this.material.userData.tween)),super.dispose()}}const Ie=a=>{const p=a,{coordinate:e,startHeight:t,height:n}=p,s=me(p,["coordinate","startHeight","height"]);let o=t||0;return typeof t!="undefined"&&typeof n!="undefined"&&(o=t+n),new _.PolygonGeometry([e],le(E({},s),{startHeight:t,endHeight:o}))};class ht extends _.BaseObject{constructor(e){super(),this.options=E({},e)}create(){const r=this.options,{geometry:e,coordinateArr:t,coordinate:n,material:s,useGroups:o}=r,l=me(r,["geometry","coordinateArr","coordinate","material","useGroups"]);let p=e;if(!p&&n)p=Ie(E({coordinate:n},l));else if(!p&&t){const y=t.map(i=>Ie(E({coordinate:i},l)));p=R(y,o!=null?o:0)}this.createMesh(p,s)}}class ut extends Z{constructor(e,t){super(e,t);const n=new he.Brush(new Z(e,le(E({},t),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const s=new u.Box3().setFromObject(n),o=new u.Vector3;s.getSize(o);const l=new u.Vector3(s.min.x+o.x/2,s.min.y+o.y/2,0);let p=t.topSegments,r=t.box3;if(r){r=r.union(s);const M=new u.Vector3;r.getSize(M);const B=Math.max(o.x/M.x,o.y/M.y);p=Math.ceil(t.topSegments*B)}if(p<4)return this;const y=new u.PlaneGeometry(o.x,o.y,p,p),i=new he.Brush(y);i.position.set(l.x,l.y,l.z),i.updateMatrixWorld();const x=new he.Evaluator().evaluate(i,n,he.INTERSECTION),f=x.geometry.getAttribute("position"),w=new u.Float32BufferAttribute(f.count*2,2);for(let M=0;M<f.count;M++){const B=f.getZ(M);f.setZ(M,t.depth+B)}if(r){const M=r.min,B=r.max,S=new u.Vector3().subVectors(B,M);for(let I=0;I<f.count;I++){const ue=f.getX(I),F=f.getY(I),J=(ue-M.x)/S.x,$=(F-M.y)/S.y;w.setXY(I,J,$)}x.geometry.setAttribute("uv",w)}f.needsUpdate=!0;const C=new Z(e,le(E({},t),{hasTop:!1})),L=R([x.geometry,C],2);this.copy(L.toNonIndexed())}}const Ue=a=>{const{split:e,depth:t,points:n,box3:s,hasTop:o,hasBottom:l,hasSide:p,sideRepeat:r,topSegments:y}=a,i=y?ut:Z,c=new i(new u.Shape(n),{depth:t,bevelEnabled:!1,box3:s,UVGenerator:Pe.getUVGenerator({split:e,box3:s,sideRepeat:r}),hasTop:o,hasBottom:l,hasSide:p,topSegments:y});return Pe.claerUVGenerator(),c};class ft extends _.BaseObject{constructor(e){super(),this.options=E({depth:1},e)}create(){return ne(this,null,function*(){const{points:e,pointsArr:t,useGroups:n,depth:s,geometry:o,geometryArr:l,material:p,box3:r,split:y,hasTop:i,hasBottom:c,hasSide:x}=this.options,f=Array.isArray(s)?s:[s],w=Array.isArray(r)?r:[r],C=p;let L=o;C||console.log("material is null"),!L&&e?L=Ue({points:e,depth:f[0],box3:w[0],split:y,hasTop:i,hasBottom:c,hasSide:x}):!L&&t?L=R(t.map((M,B)=>{var S,I;return Ue({points:M,depth:(S=f[B])!=null?S:f[0],box3:(I=w[B])!=null?I:w[0],split:y,hasTop:i,hasBottom:c,hasSide:x})}),n!=null?n:0):!L&&l&&l.length>1?L=R(l,n!=null?n:0):!L&&l&&l.length===1&&([L]=l),this.createMesh(L,C)})}addGeometries(e){const t=this.object3d,n=R([t.geometry,...e]);t.geometry=n}setTextureAnisotropic(e,t){e.anisotropy=t||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const dt=a=>{const{topColor:e,sideColor:t,sideMap:n,createCanvasObjectURL:s,split:o,maxAnisotropy:l}=a;return new Promise(p=>{const r=n?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};r.onload=()=>{const y=o,i=document.createElement("canvas"),c=i.getContext("2d");i.height=r.height/(1-y),i.width=r.width,y&&e&&(c.fillStyle=e,c.fillRect(0,0,r.width,i.height*y)),n&&r instanceof HTMLImageElement?c.drawImage(r,0,i.height*y,r.width,r.height):t&&(c.fillStyle=t,c.fillRect(0,i.height*y,r.width,r.height)),s&&i.toBlob(f=>{console.log(URL.createObjectURL(f))});const x=new u.CanvasTexture(i);p(x)},n?r.src=n:r instanceof HTMLImageElement||r.onload()})};exports.MeshLineMaterial=_.MeshLineMaterial;exports.getConicPolygonGeometry=_.PolygonGeometry;exports.getConicPolygonGeometryMetas=_.getMetas;Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Re.LineSegmentsGeometry});Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>De.LineMaterial});exports.ConicPolygon=ht;exports.ExtrudePolygon=ft;exports.Group=tt;exports.Light=rt;exports.Line=lt;exports.Line2=at;exports.MeshLineGeometry=He;exports.Node=et;exports.Pie=ot;exports.getSplitTexture=dt;
|
|
1
|
+
"use strict";var $e=Object.defineProperty,Xe=Object.defineProperties;var Ye=Object.getOwnPropertyDescriptors;var ae=Object.getOwnPropertySymbols;var Ee=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable;var Be=(c,e,t)=>e in c?$e(c,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):c[e]=t,E=(c,e)=>{for(var t in e||(e={}))Ee.call(e,t)&&Be(c,t,e[t]);if(ae)for(var t of ae(e))_e.call(e,t)&&Be(c,t,e[t]);return c},le=(c,e)=>Xe(c,Ye(e));var me=(c,e)=>{var t={};for(var n in c)Ee.call(c,n)&&e.indexOf(n)<0&&(t[n]=c[n]);if(c!=null&&ae)for(var n of ae(c))e.indexOf(n)<0&&_e.call(c,n)&&(t[n]=c[n]);return t};var ne=(c,e,t)=>new Promise((n,s)=>{var o=r=>{try{p(t.next(r))}catch(y){s(y)}},l=r=>{try{p(t.throw(r))}catch(y){s(y)}},p=r=>r.done?n(r.value):Promise.resolve(r.value).then(o,l);p((t=t.apply(c,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("../index2.js"),h=require("three"),Ze=require("@tweenjs/tween.js"),Je=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),pe=require("three/examples/jsm/utils/BufferGeometryUtils"),Qe=require("three/examples/jsm/lines/LineSegments2"),Re=require("three/examples/jsm/lines/LineSegmentsGeometry"),De=require("three/examples/jsm/lines/LineMaterial"),Pe=require("../uvGenerator.js"),he=require("three-bvh-csg");function Ke(c){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const t in c)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(c,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>c[t]})}}return e.default=c,Object.freeze(e)}const K=Ke(Ze);class et extends _.BaseObject{constructor(e){super(),this.objectType="BaseObject#Node",this.onNodePointerIndex=[],this.options=E({type:"2d"},e)}create(){const{position:e,children:t}=this.options,n=document.createElement("div");this.element=n,t&&n.appendChild(t),this.options.type==="3d"?this.createCSS3DObject(n):this.options.type==="3dSprite"?this.createCSS3DSprite(n):this.createCSS2DObject(n),e&&this.object3d.position.copy(e)}setChildren(e){this.options.children=e,this.element.innerHTML="",this.element.appendChild(e)}showAndEnsureVisible(){const e=this.options.children;e&&(e.style.visibility="hidden",this.show(),setTimeout(()=>{e.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const e=this.options.children;if(!e)return;const t=e.getBoundingClientRect(),n=window.innerWidth,s=window.innerHeight;let o=0,l=0;t.left<0?o=-t.left:t.right>n&&(o=n-t.right),t.top<0?l=-t.top:t.bottom>s&&(l=s-t.bottom),t.left+o<0&&(o=-t.left),t.top+l<0&&(l=-t.top),(o!==0||l!==0)&&(e.style.transform=`translate(${o}px, ${l}px)`)}ensureVisible(){const e=this.options.children;if(!e)return;e.style.transform&&(e.style.transform="");const t=new IntersectionObserver(n=>{n.forEach(s=>{s.isIntersecting&&(this.moveElementToViewport(),t.disconnect())})});t.observe(e)}onPointerEvent(e,t){const n=this.lead.handlePickNode([this],e,t);this.onNodePointerIndex.push(n)}dispose(){this.onNodePointerIndex.forEach(e=>{this.lead.removePickNode(e)}),super.dispose()}}class tt extends _.BaseObject{create(){this.createGroup()}}const nt={ArcCurve:h.ArcCurve,CatmullRomCurve3:h.CatmullRomCurve3,CubicBezierCurve:h.CubicBezierCurve,CubicBezierCurve3:h.CubicBezierCurve3,EllipseCurve:h.EllipseCurve,LineCurve:h.LineCurve,LineCurve3:h.LineCurve3,QuadraticBezierCurve:h.QuadraticBezierCurve,QuadraticBezierCurve3:h.QuadraticBezierCurve3,SplineCurve:h.SplineCurve};class Z extends h.BufferGeometry{constructor(e=new h.Shape([new h.Vector2(.5,.5),new h.Vector2(-.5,.5),new h.Vector2(-.5,-.5),new h.Vector2(.5,-.5)]),t={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:e,options:t},e=Array.isArray(e)?e:[e];const n=this,s=[],o=[];for(let p=0,r=e.length;p<r;p++){const y=e[p];l(y)}this.setAttribute("position",new h.Float32BufferAttribute(s,3)),this.setAttribute("uv",new h.Float32BufferAttribute(o,2)),this.computeVertexNormals();function l(p){var Se,Ae,Me;const r=[],y=t.curveSegments!==void 0?t.curveSegments:12,i=t.steps!==void 0?t.steps:1,a=t.depth!==void 0?t.depth:1;let w=t.bevelEnabled!==void 0?t.bevelEnabled:!0,f=t.bevelThickness!==void 0?t.bevelThickness:.2,x=t.bevelSize!==void 0?t.bevelSize:f-.1,C=t.bevelOffset!==void 0?t.bevelOffset:0,L=t.bevelSegments!==void 0?t.bevelSegments:3;const M=t.extrudePath,B=t.UVGenerator!==void 0?t.UVGenerator:st,S=(Se=t.hasTop)!=null?Se:!0,I=(Ae=t.hasBottom)!=null?Ae:!0,ue=(Me=t.hasSide)!=null?Me:!0;let F,J=!1,$,ee,te,D;M&&(F=M.getSpacedPoints(i),J=!0,w=!1,$=M.computeFrenetFrames(i,!1),ee=new h.Vector3,te=new h.Vector3,D=new h.Vector3),w||(L=0,f=0,x=0,C=0);const ye=p.extractPoints(y);let z=ye.shape;const P=ye.holes;if(!h.ShapeUtils.isClockWise(z)){z=z.reverse();for(let u=0,d=P.length;u<d;u++){const m=P[u];h.ShapeUtils.isClockWise(m)&&(P[u]=m.reverse())}}function be(u){const m=10000000000000001e-36;let b=u[0];for(let g=1;g<=u.length;g++){const A=g%u.length,v=u[A],T=v.x-b.x,G=v.y-b.y,j=T*T+G*G,V=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(b.x),Math.abs(b.y)),Y=m*V*V;if(j<=Y){u.splice(A,1),g--;continue}b=v}}be(z),P.forEach(be);const fe=P.length,U=z;for(let u=0;u<fe;u++){const d=P[u];z=z.concat(d)}function Q(u,d,m){return d||console.error("THREE.ExtrudeGeometry: vec does not exist"),u.clone().addScaledVector(d,m)}const H=z.length;function we(u,d,m){let b,g,A;const v=u.x-d.x,T=u.y-d.y,G=m.x-u.x,j=m.y-u.y,V=v*v+T*T,Y=v*j-T*G;if(Math.abs(Y)>Number.EPSILON){const O=Math.sqrt(V),Le=Math.sqrt(G*G+j*j),Ce=d.x-T/O,Te=d.y+v/O,ke=m.x-j/Le,Fe=m.y+G/Le,Ge=((ke-Ce)*j-(Fe-Te)*G)/(v*j-T*G);b=Ce+v*Ge-u.x,g=Te+T*Ge-u.y;const je=b*b+g*g;if(je<=2)return new h.Vector2(b,g);A=Math.sqrt(je/2)}else{let O=!1;v>Number.EPSILON?G>Number.EPSILON&&(O=!0):v<-Number.EPSILON?G<-Number.EPSILON&&(O=!0):Math.sign(T)===Math.sign(j)&&(O=!0),O?(b=-T,g=v,A=Math.sqrt(V)):(b=v,g=T,A=Math.sqrt(V/2))}return new h.Vector2(b/A,g/A)}const ie=[];for(let u=0,d=U.length,m=d-1,b=u+1;u<d;u++,m++,b++)m===d&&(m=0),b===d&&(b=0),ie[u]=we(U[u],U[m],U[b]);const de=[];let k,oe=ie.concat();for(let u=0,d=fe;u<d;u++){const m=P[u];k=[];for(let b=0,g=m.length,A=g-1,v=b+1;b<g;b++,A++,v++)A===g&&(A=0),v===g&&(v=0),k[b]=we(m[b],m[A],m[v]);de.push(k),oe=oe.concat(k)}let X;if(L===0)X=h.ShapeUtils.triangulateShape(U,P);else{const u=[],d=[];for(let m=0;m<L;m++){const b=m/L,g=f*Math.cos(b*Math.PI/2),A=x*Math.sin(b*Math.PI/2)+C;for(let v=0,T=U.length;v<T;v++){const G=Q(U[v],ie[v],A);N(G.x,G.y,-g),b===0&&u.push(G)}for(let v=0,T=fe;v<T;v++){const G=P[v];k=de[v];const j=[];for(let V=0,Y=G.length;V<Y;V++){const O=Q(G[V],k[V],A);N(O.x,O.y,-g),b===0&&j.push(O)}b===0&&d.push(j)}}X=h.ShapeUtils.triangulateShape(u,d)}const re=X.length,xe=x+C;for(let u=0;u<H;u++){const d=w?Q(z[u],oe[u],xe):z[u];J?(te.copy($.normals[0]).multiplyScalar(d.x),ee.copy($.binormals[0]).multiplyScalar(d.y),D.copy(F[0]).add(te).add(ee),N(D.x,D.y,D.z)):N(d.x,d.y,0)}for(let u=1;u<=i;u++)for(let d=0;d<H;d++){const m=w?Q(z[d],oe[d],xe):z[d];J?(te.copy($.normals[u]).multiplyScalar(m.x),ee.copy($.binormals[u]).multiplyScalar(m.y),D.copy(F[u]).add(te).add(ee),N(D.x,D.y,D.z)):N(m.x,m.y,a/i*u)}for(let u=L-1;u>=0;u--){const d=u/L,m=f*Math.cos(d*Math.PI/2),b=x*Math.sin(d*Math.PI/2)+C;for(let g=0,A=U.length;g<A;g++){const v=Q(U[g],ie[g],b);N(v.x,v.y,a+m)}for(let g=0,A=P.length;g<A;g++){const v=P[g];k=de[g];for(let T=0,G=v.length;T<G;T++){const j=Q(v[T],k[T],b);J?N(j.x,j.y+F[i-1].y,F[i-1].x+m):N(j.x,j.y,a+m)}}}Ne(),ue&&We();function Ne(){const u=s.length/3;if(w){let d=0,m=H*d;if(I)for(let b=0;b<re;b++){const g=X[b];ce(g[2]+m,g[1]+m,g[0]+m)}if(d=i+L*2,m=H*d,S)for(let b=0;b<re;b++){const g=X[b];ce(g[0]+m,g[1]+m,g[2]+m)}}else{if(I)for(let d=0;d<re;d++){const m=X[d];ce(m[2],m[1],m[0])}if(S)for(let d=0;d<re;d++){const m=X[d];ce(m[0]+H*i,m[1]+H*i,m[2]+H*i)}}n.addGroup(u,s.length/3-u,0)}function We(){const u=s.length/3;let d=0;ve(U,d),d+=U.length;for(let m=0,b=P.length;m<b;m++){const g=P[m];ve(g,d),d+=g.length}n.addGroup(u,s.length/3-u,1)}function ve(u,d){let m=u.length;for(;--m>=0;){const b=m;let g=m-1;g<0&&(g=u.length-1);for(let A=0,v=i+L*2;A<v;A++){const T=H*A,G=H*(A+1),j=d+b+T,V=d+g+T,Y=d+g+G,O=d+b+G;qe(j,V,Y,O)}}}function N(u,d,m){r.push(u),r.push(d),r.push(m)}function ce(u,d,m){W(u),W(d),W(m);const b=s.length/3,g=B.generateTopUV(n,s,b-3,b-2,b-1);q(g[0]),q(g[1]),q(g[2])}function qe(u,d,m,b){W(u),W(d),W(b),W(d),W(m),W(b);const g=s.length/3,A=B.generateSideWallUV(n,s,g-6,g-3,g-2,g-1);q(A[0]),q(A[1]),q(A[3]),q(A[1]),q(A[2]),q(A[3])}function W(u){s.push(r[u*3+0]),s.push(r[u*3+1]),s.push(r[u*3+2])}function q(u){o.push(u.x),o.push(u.y)}}}copy(e){return super.copy(e),this.parameters=Object.assign({},e.parameters),this}toJSON(){const e=super.toJSON(),t=this.parameters.shapes,n=this.parameters.options;return it(t,n,e)}static fromJSON(e,t){const n=[];for(let o=0,l=e.shapes.length;o<l;o++){const p=t[e.shapes[o]];n.push(p)}const s=e.options.extrudePath;return s!==void 0&&(e.options.extrudePath=new nt[`${s.type}`]().fromJSON(s)),new Z(n,e.options)}}const st={generateTopUV:function(c,e,t,n,s){const o=e[t*3],l=e[t*3+1],p=e[n*3],r=e[n*3+1],y=e[s*3],i=e[s*3+1];return[new h.Vector2(o,l),new h.Vector2(p,r),new h.Vector2(y,i)]},generateSideWallUV:function(c,e,t,n,s,o){const l=e[t*3],p=e[t*3+1],r=e[t*3+2],y=e[n*3],i=e[n*3+1],a=e[n*3+2],w=e[s*3],f=e[s*3+1],x=e[s*3+2],C=e[o*3],L=e[o*3+1],M=e[o*3+2];return Math.abs(p-i)<Math.abs(l-y)?[new h.Vector2(l,1-r),new h.Vector2(y,1-a),new h.Vector2(w,1-x),new h.Vector2(C,1-M)]:[new h.Vector2(p,1-r),new h.Vector2(i,1-a),new h.Vector2(f,1-x),new h.Vector2(L,1-M)]}};function it(c,e,t){if(t.shapes=[],Array.isArray(c))for(let n=0,s=c.length;n<s;n++){const o=c[n];t.shapes.push(o.uuid)}else t.shapes.push(c.uuid);return t.options=Object.assign({},e),e.extrudePath!==void 0&&(t.options.extrudePath=e.extrudePath.toJSON()),t}class ot extends _.BaseObject{constructor(e){super(),this.options=E({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},e)}create(){return ne(this,null,function*(){this.createGroup();const{data:e,maxDepth:t,colors:n,material:s,percentDepth:o,activeIndex:l}=this.options,p=Math.max(...e),r=e.reduce((i,a)=>i+a,0);let y=Math.PI/2;e.forEach((i,a)=>{if(i===0)return;const w=Math.PI*2*(i/r),f=n[a],x=o?t*(i/p):t,C=this.createGeometry(x,w),L=s?s.clone():new h.MeshBasicMaterial({color:f});s&&L.color.set(f);const M=new h.Mesh(C,L);M.userData.depth=x,M.userData.index=a,M.rotateZ(y),y+=w,this.add(M)}),l!==-1&&this.setActive(l)})}createGeometry(e,t){const{outRadius:n,innerRadius:s}=this.options,o=new h.Shape;return o.moveTo(n,0),o.lineTo(s,0),o.absarc(0,0,s,0,t,!1),o.absarc(0,0,n,t,0,!0),new Z(o,{curveSegments:48,depth:e,bevelEnabled:!1})}handlePick(e,t=1.3){const{object:n}=this.pencil.pick(e,this.object3d.children)||{},s=n?this.object3d.children.findIndex(o=>o===n):this.options.activeIndex;return this.setActive(s,t)}setActive(e,t=1.3){const n=this.object3d.children[e];if(this.object3d.children.forEach(s=>{if(!(n&&n===s)&&s.scale.z!==1){if(s.userData.levTween)return;s.userData.enTween&&(s.userData.enTween.stop(),s.userData.enTween=null);const o=new K.Tween(s.scale).to({z:1},100);s.userData.levTween=o,o.start()}}),n){if(n.userData.enTween)return;n.userData.levTween&&(n.userData.levTween.stop(),n.userData.levTween=null);const s=new K.Tween(n.scale).to({z:t},100);return n.userData.enTween=s,s.start(),n.userData.index}return-1}render(){this.object3d.scale.z=0,new K.Tween(this.object3d.scale).to({z:1},1e3).easing(K.Easing.Sinusoidal.InOut).start()}}class rt extends _.BaseObject{constructor(e){super(),this.rectAreaLightUniformsLibInit=!1,this.options=e}create(){var t,n,s,o,l,p,r,y,i,a,w,f,x,C,L,M,B;const e=this.options;if(e.type==="AmbientLight"){const S=new h.AmbientLight(e.color);S.name="环境光",this.object3d=S}else if(e.type==="DirectionalLight"){const S=new h.DirectionalLight(e.color,e.intensity);S.name="平行光",S.target.position.set(0,0,0),this.object3d=S,S.target.name="平行光目标",S.shadow.camera.name="平行光阴影相机",S.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=S}else if(e.type==="PointLight"){const S=new h.PointLight((t=e.color)!=null?t:16777215,(n=e.intensity)!=null?n:1,(s=e.distance)!=null?s:0,(o=e.decay)!=null?o:2);S.name="点光源",this.object3d=S,this.pointLight=S}else if(e.type==="SpotLight"){const S=new h.SpotLight((l=e.color)!=null?l:16777215,(p=e.intensity)!=null?p:1,(r=e.distance)!=null?r:0,(y=e.angle)!=null?y:Math.PI/3,(i=e.penumbra)!=null?i:1,(a=e.decay)!=null?a:2);S.name="聚光灯",this.object3d=S,this.spotLight=S,S.target.name="聚光灯目标"}else if(e.type==="HemisphereLight"){const S=new h.HemisphereLight((w=e.color)!=null?w:16777215,(f=e.groundColor)!=null?f:16777215,(x=e.intensity)!=null?x:1);S.name="半球光",this.object3d=S,this.hemisphereLight=S}else if(e.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Je.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const S=new h.RectAreaLight((C=e.color)!=null?C:16777215,(L=e.intensity)!=null?L:1,(M=e.width)!=null?M:10,(B=e.height)!=null?B:10);S.name="矩形区域光",this.object3d=S,this.rectAreaLight=S}}render(){const e=this.object3d;e.target&&this.pencil.scene.add(e.target);const t=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const n=this.spotLight||this.directionalLight;n.position.copy(t),n.target.position.copy(t)}else this.pointLight&&this.pointLight.position.copy(t)}dispose(){const e=this.object3d;e.target&&this.pencil.scene.remove(e.target),super.dispose()}}function R(c,e=0){const t=c[0].index!==null,n=new Set(Object.keys(c[0].attributes)),s=new Set(Object.keys(c[0].morphAttributes)),o={},l={},p=c[0].morphTargetsRelative,r=new h.BufferGeometry;let y=0;for(let i=0;i<c.length;++i){const a=c[i];let w=0;if(t!==(a.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in a.attributes){if(!n.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;o[f]===void 0&&(o[f]=[]),o[f].push(a.attributes[f]),w++}if(w!==n.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". Make sure all geometries have the same number of attributes."),null;if(p!==a.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in a.morphAttributes){if(!s.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". .morphAttributes must be consistent throughout all geometries."),null;l[f]===void 0&&(l[f]=[]),l[f].push(a.morphAttributes[f])}if(e){let f;if(t)f=a.index.count;else if(a.attributes.position!==void 0)f=a.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+i+". The geometry must have either an index or a position attribute"),null;if(e===1)r.addGroup(y,f,i);else if(e===2&&a.groups.length>0)for(let x of a.groups){let C=x.materialIndex;r.addGroup(y+x.start,Math.min(x.count,f),C)}y+=f}}if(t){let i=0;const a=[];for(let w=0;w<c.length;++w){const f=c[w].index;for(let x=0;x<f.count;++x)a.push(f.getX(x)+i);i+=c[w].attributes.position.count}r.setIndex(a)}for(const i in o){const a=pe.mergeAttributes(o[i]);if(!a)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" attribute."),null;r.setAttribute(i,a)}for(const i in l){const a=l[i][0].length;if(a===0)break;r.morphAttributes=r.morphAttributes||{},r.morphAttributes[i]=[];for(let w=0;w<a;++w){const f=[];for(let C=0;C<l[i].length;++C)f.push(l[i][C][w]);const x=pe.mergeAttributes(f);if(!x)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+i+" morphAttribute."),null;r.morphAttributes[i].push(x)}}return e===2?pe.mergeGroups(r):r}const Ve=c=>{const{points:e}=c,t=e.reduce((s,o,l)=>(l<e.length-1&&s.push(o,e[l+1]),s),[]);return new h.BufferGeometry().setFromPoints(t)};let ct=class extends _.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return ne(this,null,function*(){const{points:e,pointsArr:t,geometry:n,geometryArr:s,material:o,useGroups:l,setPointWidth:p,lineWidthArr:r,materialParameters:y,instanceCount:i}=this.options;let a=o,w=n;!a&&y&&(a=this.getMaterial(y)),!w&&e?w=Ve({points:e}):!w&&t?w=R(t.map(x=>Ve({points:x})),l!=null?l:0):!w&&s&&s.length>1?w=R(s,l!=null?l:0):!w&&s&&s.length===1&&([w]=s);const f=new Re.LineSegmentsGeometry().fromLineSegments(new h.LineSegments(w));if(this.pencil.options.WebGPUTHREE){i&&(f.instanceCount=i);const x=new _.LineSegments2(f,a);x.computeLineDistances(),this.object3d=x}else{const x=new Qe.LineSegments2(f,a);x.computeLineDistances(),this.object3d=x}})}getMaterial(e){return new De.LineMaterial(E({color:new h.Color("#ffffff")},e))}};const se=(c,e,t,n,s)=>{c[e+0]=t,c[e+1]=n,c[e+2]=s,c[e+3]=t,c[e+4]=n,c[e+5]=s},Oe=(c,e,t,n)=>{c[e+0]=t,c[e+1]=n},ze=(c,e,t,n,s)=>{c[e+0]=t,c[e+1]=n,c[e+2]=s},at=(c,e,t,n,s,o)=>{c[e+0]=t,c[e+1]=n,c[e+2]=s,c[e+3]=o};class He extends h.BufferGeometry{constructor(e=[],t="none",n){super(),this.type="MeshLineGeometry",this.pointCount=0,this._points=[],this.shape="none",this.shapeFunction=s=>1,this.matrixWorld=new h.Matrix4,this.shape=t,n&&(this.shapeFunction=n),e.length>0&&this.setPoints(e)}convertToVector3Array(e){if(typeof e[0]=="number"){const t=[],n=e;for(let s=0;s<n.length;s+=3)t.push(new h.Vector3(n[s],n[s+1],n[s+2]));return t}else return e.map(t=>{if(t instanceof h.Vector2)return new h.Vector3(t.x,t.y,0);if(t instanceof h.Vector3)return t;if(Array.isArray(t)&&t.length===2)return new h.Vector3(t[0],t[1],0);if(Array.isArray(t)&&t.length===3)return new h.Vector3(t[0],t[1],t[2])}).filter(Boolean)}setMatrixWorld(e){this.matrixWorld=e}setPoints(e,t){!e||e.length===0||(this._points=this.convertToVector3Array(e),this.pointCount=this._points.length,t&&(this.shapeFunction=t,this.shape="custom"),this.initializeGeometry(),this.updateGeometry())}initializeGeometry(){const e=[];let t=0;const n=[],s=[];let o=0;const l=[];let p=0;const r=[];let y=0;this.shape==="taper"&&(this.shapeFunction=i=>1*Math.pow(4*i*(1-i),1));for(let i=0;i<this.pointCount;i++){const a=i/this._points.length;e[t+0]=a,e[t+1]=a,t+=2,Oe(n,o,1,-1);const w=this.shape==="none"?1:this.shapeFunction(i/(this.pointCount-1));if(Oe(s,o,w,w),o+=2,at(l,p,i/(this.pointCount-1),0,i/(this.pointCount-1),1),p+=4,i<this.pointCount-1){const f=i*2;ze(r,y,f+0,f+1,f+2),ze(r,y+3,f+2,f+1,f+3),y+=6}}this.setAttribute("position",new h.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("previous",new h.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("next",new h.BufferAttribute(new Float32Array(this.pointCount*6),3)),this.setAttribute("counters",new h.BufferAttribute(new Float32Array(e),1)),this.setAttribute("side",new h.BufferAttribute(new Float32Array(n),1)),this.setAttribute("width",new h.BufferAttribute(new Float32Array(s),1)),this.setAttribute("uv",new h.BufferAttribute(new Float32Array(l),2)),this.setIndex(new h.BufferAttribute(new Uint16Array(r),1))}updateGeometry(){if(!this._points[0])return;const e=[],t=[],n=[];let s=0,o=0,l=0;se(t,o,this._points[0].x,this._points[0].y,this._points[0].z),o+=6;for(let i=0;i<this.pointCount;i++){const a=this._points[i];se(e,s,a.x,a.y,a.z),s+=6,i<this.pointCount-1&&(se(t,o,a.x,a.y,a.z),o+=6),i>0&&i+1<=this.pointCount&&(se(n,l,a.x,a.y,a.z),l+=6)}se(n,l,this._points[this.pointCount-1].x,this._points[this.pointCount-1].y,this._points[this.pointCount-1].z);const p=this.getAttribute("position"),r=this.getAttribute("previous"),y=this.getAttribute("next");p.set(e),r.set(t),y.set(n),p.needsUpdate=!0,r.needsUpdate=!0,y.needsUpdate=!0,this.computeBoundingSphere(),this.computeBoundingBox()}get points(){return this._points}set points(e){this.setPoints(e)}updatePoints(e,t){const n=this.convertToVector3Array(e);if(n.length!==this.pointCount){console.warn("MeshLineGeometry: Cannot update points with different length. Use setPoints() instead.");return}this._points=n,t&&(this.shapeFunction=t,this.shape="custom",this.initializeGeometry()),this.updateGeometry()}setShape(e,t){this.shape=e,t&&(this.shapeFunction=t),this._points.length>0&&(this.initializeGeometry(),this.updateGeometry())}}const ge=c=>{const{setPointWidth:e,nodes:t}=c,n=new He;return n.setPoints(t,e),n};class lt extends _.BaseObject{constructor(e={}){super(),this.options=E({},e)}get material(){var e;return(e=this.object3d)==null?void 0:e.material}create(){return ne(this,null,function*(){const{nodes:e,nodesArr:t,geometry:n,geometryArr:s,material:o,useGroups:l,setPointWidth:p,lineWidthArr:r,materialParameters:y}=this.options;let i=o,a=n;!i&&y&&(i=this.getMaterial(y)),!a&&e?a=ge({nodes:e,setPointWidth:p}):!a&&t?a=R(t.map((w,f)=>{let x=p;return!x&&r&&(x=()=>{var C;return(C=r[f])!=null?C:r[0]}),ge({nodes:w,setPointWidth:x})}),l!=null?l:0):!a&&s&&s.length>1?a=R(s,l!=null?l:0):!a&&s&&s.length===1&&([a]=s),this.createMesh(a,i)})}setGeometry(e,t){const n=ge({nodes:e,setPointWidth:t}),s=this.object3d,o=s.geometry;s.geometry=n,o.dispose()}getMaterial(e){const{width:t,height:n}=this.pencil.getSize(),s=new _.MeshLineMaterial(E({color:new h.Color("#ffffff")},e));return s.uniforms.resolution.value.set(t,n),s}addGeometries(e){const t=this.object3d,n=R([t.geometry,...e]);t.geometry=n}resize(e,t){var n,s;(s=(n=this.material)==null?void 0:n.uniforms)==null||s.resolution.value.set(e,t)}handleMaterialChange(e){if(e){const{width:t,height:n}=this.pencil.getSize();this.resize(t,n)}}animate({duration:e=1e3,delay:t=0,repeat:n=0,lineLoop:s,onRepeat:o,onUpdate:l,onComplete:p,startShow:r}={}){const{offset:y,offsetLoop:i}=this.material.uniforms;if(this.material.userData.tween)return;const a=s!=null?s:!0;y.value.x=1,i.value=a&&r?1:0;let w=0;const f=new K.Tween(y.value).to({x:-1},e).delay(t).repeat(n).onUpdate(({x})=>{a&&x<=0&&i.value===0&&(i.value=1),l&&l(x)}).onRepeat(()=>{w+=1,o&&o(w)}).onComplete(()=>{p&&p()}).start();this.material.userData.tween=f}render(){const{width:e,height:t}=this.pencil.getSize();this.resize(e,t)}dispose(){this.material.userData.tween&&(this.material.userData.tween.stop(),K.remove(this.material.userData.tween)),super.dispose()}}const Ie=c=>{const p=c,{coordinate:e,startHeight:t,height:n}=p,s=me(p,["coordinate","startHeight","height"]);let o=t||0;return typeof t!="undefined"&&typeof n!="undefined"&&(o=t+n),new _.PolygonGeometry([e],le(E({},s),{startHeight:t,endHeight:o}))};class ht extends _.BaseObject{constructor(e){super(),this.options=E({},e)}create(){const r=this.options,{geometry:e,coordinateArr:t,coordinate:n,material:s,useGroups:o}=r,l=me(r,["geometry","coordinateArr","coordinate","material","useGroups"]);let p=e;if(!p&&n)p=Ie(E({coordinate:n},l));else if(!p&&t){const y=t.map(i=>Ie(E({coordinate:i},l)));p=R(y,o!=null?o:0)}this.createMesh(p,s)}}class ut extends Z{constructor(e,t){super(e,t);const n=new he.Brush(new Z(e,le(E({},t),{hasTop:!0,hasSide:!0,hasBottom:!1})));n.updateMatrixWorld();const s=new h.Box3().setFromObject(n),o=new h.Vector3;s.getSize(o);const l=new h.Vector3(s.min.x+o.x/2,s.min.y+o.y/2,0);let p=t.topSegments,r=t.box3;if(r){r=r.union(s);const M=new h.Vector3;r.getSize(M);const B=Math.max(o.x/M.x,o.y/M.y);p=Math.ceil(t.topSegments*B)}if(p<4)return this;const y=new h.PlaneGeometry(o.x,o.y,p,p),i=new he.Brush(y);i.position.set(l.x,l.y,l.z),i.updateMatrixWorld();const w=new he.Evaluator().evaluate(i,n,he.INTERSECTION),f=w.geometry.getAttribute("position"),x=new h.Float32BufferAttribute(f.count*2,2);for(let M=0;M<f.count;M++){const B=f.getZ(M);f.setZ(M,t.depth+B)}if(r){const M=r.min,B=r.max,S=new h.Vector3().subVectors(B,M);for(let I=0;I<f.count;I++){const ue=f.getX(I),F=f.getY(I),J=(ue-M.x)/S.x,$=(F-M.y)/S.y;x.setXY(I,J,$)}w.geometry.setAttribute("uv",x)}f.needsUpdate=!0;const C=new Z(e,le(E({},t),{hasTop:!1})),L=R([w.geometry,C],2);this.copy(L.toNonIndexed())}}const Ue=c=>{const{split:e,depth:t,points:n,box3:s,hasTop:o,hasBottom:l,hasSide:p,sideRepeat:r,topSegments:y}=c,i=y?ut:Z,a=new i(new h.Shape(n),{depth:t,bevelEnabled:!1,box3:s,UVGenerator:Pe.getUVGenerator({split:e,box3:s,sideRepeat:r}),hasTop:o,hasBottom:l,hasSide:p,topSegments:y});return Pe.claerUVGenerator(),a};class ft extends _.BaseObject{constructor(e){super(),this.options=E({depth:1},e)}create(){return ne(this,null,function*(){const{points:e,pointsArr:t,useGroups:n,depth:s,geometry:o,geometryArr:l,material:p,box3:r,split:y,hasTop:i,hasBottom:a,hasSide:w}=this.options,f=Array.isArray(s)?s:[s],x=Array.isArray(r)?r:[r],C=p;let L=o;C||console.log("material is null"),!L&&e?L=Ue({points:e,depth:f[0],box3:x[0],split:y,hasTop:i,hasBottom:a,hasSide:w}):!L&&t?L=R(t.map((M,B)=>{var S,I;return Ue({points:M,depth:(S=f[B])!=null?S:f[0],box3:(I=x[B])!=null?I:x[0],split:y,hasTop:i,hasBottom:a,hasSide:w})}),n!=null?n:0):!L&&l&&l.length>1?L=R(l,n!=null?n:0):!L&&l&&l.length===1&&([L]=l),this.createMesh(L,C)})}addGeometries(e){const t=this.object3d,n=R([t.geometry,...e]);t.geometry=n}setTextureAnisotropic(e,t){e.anisotropy=t||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const dt=c=>{const{topColor:e,sideColor:t,sideMap:n,createCanvasObjectURL:s,split:o,maxAnisotropy:l}=c;return new Promise(p=>{const r=n?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};r.onload=()=>{const y=o,i=document.createElement("canvas"),a=i.getContext("2d");i.height=r.height/(1-y),i.width=r.width,y&&e&&(a.fillStyle=e,a.fillRect(0,0,r.width,i.height*y)),n&&r instanceof HTMLImageElement?a.drawImage(r,0,i.height*y,r.width,r.height):t&&(a.fillStyle=t,a.fillRect(0,i.height*y,r.width,r.height)),s&&i.toBlob(f=>{console.log(URL.createObjectURL(f))});const w=new h.CanvasTexture(i);p(w)},n?r.src=n:r instanceof HTMLImageElement||r.onload()})};exports.MeshLineMaterial=_.MeshLineMaterial;exports.getConicPolygonGeometry=_.PolygonGeometry;exports.getConicPolygonGeometryMetas=_.getMetas;Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Re.LineSegmentsGeometry});Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>De.LineMaterial});exports.ConicPolygon=ht;exports.ExtrudePolygon=ft;exports.Group=tt;exports.Light=rt;exports.Line=lt;exports.Line2=ct;exports.MeshLineGeometry=He;exports.Node=et;exports.Pie=ot;exports.getSplitTexture=dt;
|