gl-draw 0.14.34 → 0.14.35
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.js +2 -2
- package/dist/index.module.js +214 -213
- package/dist/objects/extrudePolygon/ExtrudeGeometry.d.ts +90 -6
- package/dist/objects/extrudePolygon/createGeometry.d.ts +64 -2
- package/dist/objects/index.js +1 -1
- package/dist/objects/index.module.js +542 -589
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.module.js +28 -28
- package/dist/utils/mergeGeometries.d.ts +10 -0
- package/package.json +1 -1
- package/dist/utils/BufferGeometryUtils.d.ts +0 -62
|
@@ -1,11 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ~Options
|
|
3
|
+
*/
|
|
4
|
+
export type ExtrudeGeometry = {
|
|
5
|
+
/**
|
|
6
|
+
* - Number of points on the curves.
|
|
7
|
+
*/
|
|
8
|
+
curveSegments?: number | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* - Number of points used for subdividing segments along the depth of the extruded spline.
|
|
11
|
+
*/
|
|
12
|
+
steps?: number | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* - Depth to extrude the shape.
|
|
15
|
+
*/
|
|
16
|
+
depth?: number | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* - Whether to beveling to the shape or not.
|
|
19
|
+
*/
|
|
20
|
+
bevelEnabled?: boolean | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* - How deep into the original shape the bevel goes.
|
|
23
|
+
*/
|
|
24
|
+
bevelThickness?: number | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* - Distance from the shape outline that the bevel extends.
|
|
27
|
+
*/
|
|
28
|
+
bevelSize?: number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* - Distance from the shape outline that the bevel starts.
|
|
31
|
+
*/
|
|
32
|
+
bevelOffset?: number | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* - Number of bevel layers.
|
|
35
|
+
*/
|
|
36
|
+
bevelSegments?: number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* - A 3D spline path along which the shape should be extruded. Bevels not supported for path extrusion.
|
|
39
|
+
*/
|
|
40
|
+
extrudePath?: Curve | null;
|
|
41
|
+
/**
|
|
42
|
+
* - An object that provides UV generator functions for custom UV generation.
|
|
43
|
+
*/
|
|
44
|
+
UVGenerator?: Object | undefined;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Creates extruded geometry from a path shape.
|
|
48
|
+
*
|
|
49
|
+
* ```js
|
|
50
|
+
* const length = 12, width = 8;
|
|
51
|
+
*
|
|
52
|
+
* const shape = new THREE.Shape();
|
|
53
|
+
* shape.moveTo( 0,0 );
|
|
54
|
+
* shape.lineTo( 0, width );
|
|
55
|
+
* shape.lineTo( length, width );
|
|
56
|
+
* shape.lineTo( length, 0 );
|
|
57
|
+
* shape.lineTo( 0, 0 );
|
|
58
|
+
*
|
|
59
|
+
* const geometry = new THREE.ExtrudeGeometry( shape );
|
|
60
|
+
* const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
|
|
61
|
+
* const mesh = new THREE.Mesh( geometry, material ) ;
|
|
62
|
+
* scene.add( mesh );
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @augments BufferGeometry
|
|
66
|
+
*/
|
|
1
67
|
export class ExtrudeGeometry extends BufferGeometry<Three.NormalBufferAttributes> {
|
|
2
|
-
|
|
3
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Factory method for creating an instance of this class from the given
|
|
70
|
+
* JSON object.
|
|
71
|
+
*
|
|
72
|
+
* @param {Object} data - A JSON object representing the serialized geometry.
|
|
73
|
+
* @param {Array<Shape>} shapes - An array of shapes.
|
|
74
|
+
* @return {ExtrudeGeometry} A new instance.
|
|
75
|
+
*/
|
|
76
|
+
static fromJSON(data: Object, shapes: Array<Shape>): ExtrudeGeometry;
|
|
77
|
+
/**
|
|
78
|
+
* Constructs a new extrude geometry.
|
|
79
|
+
*
|
|
80
|
+
* @param {Shape|Array<Shape>} [shapes] - A shape or an array of shapes.
|
|
81
|
+
* @param {ExtrudeGeometry~Options} [options] - The extrude settings.
|
|
82
|
+
*/
|
|
83
|
+
constructor(shapes?: Shape | Shape[] | undefined, options?: {});
|
|
4
84
|
type: string;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Holds the constructor parameters that have been
|
|
87
|
+
* used to generate the geometry. Any modification
|
|
88
|
+
* after instantiation does not change the geometry.
|
|
89
|
+
*
|
|
90
|
+
* @type {Object}
|
|
91
|
+
*/
|
|
92
|
+
parameters: Object;
|
|
9
93
|
copy(source: any): this;
|
|
10
94
|
toJSON(): any;
|
|
11
95
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
|
-
import { ExtrudeGeometry } from './ExtrudeGeometry';
|
|
3
2
|
interface Options {
|
|
4
3
|
points: THREE.Vector2[];
|
|
5
4
|
split?: number;
|
|
@@ -11,5 +10,68 @@ interface Options {
|
|
|
11
10
|
hasSide?: boolean;
|
|
12
11
|
topSegments?: number;
|
|
13
12
|
}
|
|
14
|
-
declare const _default: (options: Options) =>
|
|
13
|
+
declare const _default: (options: Options) => {
|
|
14
|
+
type: string;
|
|
15
|
+
parameters: Object;
|
|
16
|
+
copy(source: any): any;
|
|
17
|
+
toJSON(): any;
|
|
18
|
+
id: number;
|
|
19
|
+
uuid: string;
|
|
20
|
+
name: string;
|
|
21
|
+
index: THREE.BufferAttribute | null;
|
|
22
|
+
indirect: import("three/src/renderers/common/IndirectStorageBufferAttribute").default | null;
|
|
23
|
+
attributes: THREE.NormalBufferAttributes;
|
|
24
|
+
morphAttributes: Record<"position" | "normal" | "color", Array<THREE.BufferAttribute | THREE.InterleavedBufferAttribute>>;
|
|
25
|
+
morphTargetsRelative: boolean;
|
|
26
|
+
groups: THREE.GeometryGroup[];
|
|
27
|
+
boundingBox: THREE.Box3 | null;
|
|
28
|
+
boundingSphere: THREE.Sphere | null;
|
|
29
|
+
drawRange: {
|
|
30
|
+
start: number;
|
|
31
|
+
count: number;
|
|
32
|
+
};
|
|
33
|
+
userData: Record<string, any>;
|
|
34
|
+
readonly isBufferGeometry: true;
|
|
35
|
+
getIndex(): THREE.BufferAttribute | null;
|
|
36
|
+
setIndex(index: THREE.BufferAttribute | number[] | null): any;
|
|
37
|
+
setIndirect(indirect: import("three/src/renderers/common/IndirectStorageBufferAttribute").default | null): any;
|
|
38
|
+
getIndirect(): import("three/src/renderers/common/IndirectStorageBufferAttribute").default | null;
|
|
39
|
+
setAttribute<K extends string>(name: K, attribute: THREE.BufferAttribute | THREE.InterleavedBufferAttribute): any;
|
|
40
|
+
getAttribute<K extends string>(name: K): THREE.BufferAttribute | THREE.InterleavedBufferAttribute;
|
|
41
|
+
deleteAttribute(name: string): any;
|
|
42
|
+
hasAttribute(name: string): boolean;
|
|
43
|
+
addGroup(start: number, count: number, materialIndex?: number): void;
|
|
44
|
+
clearGroups(): void;
|
|
45
|
+
setDrawRange(start: number, count: number): void;
|
|
46
|
+
applyMatrix4(matrix: THREE.Matrix4): any;
|
|
47
|
+
applyQuaternion(quaternion: THREE.Quaternion): any;
|
|
48
|
+
rotateX(angle: number): any;
|
|
49
|
+
rotateY(angle: number): any;
|
|
50
|
+
rotateZ(angle: number): any;
|
|
51
|
+
translate(x: number, y: number, z: number): any;
|
|
52
|
+
scale(x: number, y: number, z: number): any;
|
|
53
|
+
lookAt(vector: THREE.Vector3): any;
|
|
54
|
+
center(): any;
|
|
55
|
+
setFromPoints(points: THREE.Vector3[] | THREE.Vector2[]): any;
|
|
56
|
+
computeBoundingBox(): void;
|
|
57
|
+
computeBoundingSphere(): void;
|
|
58
|
+
computeTangents(): void;
|
|
59
|
+
computeVertexNormals(): void;
|
|
60
|
+
normalizeNormals(): void;
|
|
61
|
+
toNonIndexed(): THREE.BufferGeometry;
|
|
62
|
+
clone(): any;
|
|
63
|
+
dispose(): void;
|
|
64
|
+
addEventListener<T extends "dispose">(type: T, listener: THREE.EventListener<{
|
|
65
|
+
dispose: {};
|
|
66
|
+
}[T], T, any>): void;
|
|
67
|
+
hasEventListener<T extends "dispose">(type: T, listener: THREE.EventListener<{
|
|
68
|
+
dispose: {};
|
|
69
|
+
}[T], T, any>): boolean;
|
|
70
|
+
removeEventListener<T extends "dispose">(type: T, listener: THREE.EventListener<{
|
|
71
|
+
dispose: {};
|
|
72
|
+
}[T], T, any>): void;
|
|
73
|
+
dispatchEvent<T extends "dispose">(event: THREE.BaseEvent<T> & {
|
|
74
|
+
dispose: {};
|
|
75
|
+
}[T]): void;
|
|
76
|
+
};
|
|
15
77
|
export default _default;
|
package/dist/objects/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Ft=Object.defineProperty,qt=Object.defineProperties;var $t=Object.getOwnPropertyDescriptors;var ct=Object.getOwnPropertySymbols;var jt=Object.prototype.hasOwnProperty,Gt=Object.prototype.propertyIsEnumerable;var Et=(r,t,e)=>t in r?Ft(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,P=(r,t)=>{for(var e in t||(t={}))jt.call(t,e)&&Et(r,e,t[e]);if(ct)for(var e of ct(t))Gt.call(t,e)&&Et(r,e,t[e]);return r},lt=(r,t)=>qt(r,$t(t));var dt=(r,t)=>{var e={};for(var s in r)jt.call(r,s)&&t.indexOf(s)<0&&(e[s]=r[s]);if(r!=null&&ct)for(var s of ct(r))t.indexOf(s)<0&&Gt.call(r,s)&&(e[s]=r[s]);return e};var it=(r,t,e)=>new Promise((s,i)=>{var n=c=>{try{l(e.next(c))}catch(m){i(m)}},o=c=>{try{l(e.throw(c))}catch(m){i(m)}},l=c=>c.done?s(c.value):Promise.resolve(c.value).then(n,o);l((e=e.apply(r,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("../index2.js"),T=require("three"),Jt=require("@tweenjs/tween.js"),Xt=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),Yt=require("three/examples/jsm/lines/LineSegments2"),Ot=require("three/examples/jsm/lines/LineSegmentsGeometry"),Rt=require("three/examples/jsm/lines/LineMaterial"),Bt=require("../uvGenerator.js"),ht=require("three-bvh-csg");function zt(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const w=zt(T),Z=zt(Jt);class Zt extends I.BaseObject{constructor(t){super(),this.objectType="BaseObject#Node",this.onNodePointerIndex=[],this.options=P({type:"2d"},t)}create(){const{position:t,children:e}=this.options,s=document.createElement("div");this.element=s,e&&s.appendChild(e),this.options.type==="3d"?this.createCSS3DObject(s):this.options.type==="3dSprite"?this.createCSS3DSprite(s):this.createCSS2DObject(s),t&&this.object3d.position.copy(t)}setChildren(t){this.options.children=t,this.element.innerHTML="",this.element.appendChild(t)}showAndEnsureVisible(){const t=this.options.children;t&&(t.style.visibility="hidden",this.show(),setTimeout(()=>{t.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const t=this.options.children;if(!t)return;const e=t.getBoundingClientRect(),s=window.innerWidth,i=window.innerHeight;let n=0,o=0;e.left<0?n=-e.left:e.right>s&&(n=s-e.right),e.top<0?o=-e.top:e.bottom>i&&(o=i-e.bottom),e.left+n<0&&(n=-e.left),e.top+o<0&&(o=-e.top),(n!==0||o!==0)&&(t.style.transform=`translate(${n}px, ${o}px)`)}ensureVisible(){const t=this.options.children;if(!t)return;t.style.transform&&(t.style.transform="");const e=new IntersectionObserver(s=>{s.forEach(i=>{i.isIntersecting&&(this.moveElementToViewport(),e.disconnect())})});e.observe(t)}onPointerEvent(t,e){const s=this.lead.handlePickNode([this],t,e);this.onNodePointerIndex.push(s)}dispose(){this.onNodePointerIndex.forEach(t=>{this.lead.removePickNode(t)}),super.dispose()}}class Kt extends I.BaseObject{constructor(t){super(),this.options=P({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},t)}create(){return it(this,null,function*(){this.createGroup();const{data:t,maxDepth:e,colors:s,material:i,percentDepth:n,activeIndex:o}=this.options,l=Math.max(...t),c=t.reduce((a,h)=>a+h,0);let m=Math.PI/2;t.forEach((a,h)=>{if(a===0)return;const g=Math.PI*2*(a/c),f=s[h],b=n?e*(a/l):e,_=this.createGeometry(b,g),A=i?i.clone():new w.MeshBasicMaterial({color:f});i&&A.color.set(f);const S=new w.Mesh(_,A);S.userData.depth=b,S.userData.index=h,S.rotateZ(m),m+=g,this.add(S)}),o!==-1&&this.setActive(o)})}createGeometry(t,e){const{outRadius:s,innerRadius:i}=this.options,n=new w.Shape;return n.moveTo(s,0),n.lineTo(i,0),n.absarc(0,0,i,0,e,!1),n.absarc(0,0,s,e,0,!0),new w.ExtrudeGeometry(n,{curveSegments:48,depth:t,bevelEnabled:!1})}handlePick(t,e=1.3){const{object:s}=this.pencil.pick(t,this.object3d.children)||{},i=s?this.object3d.children.findIndex(n=>n===s):this.options.activeIndex;return this.setActive(i,e)}setActive(t,e=1.3){const s=this.object3d.children[t];if(this.object3d.children.forEach(i=>{if(!(s&&s===i)&&i.scale.z!==1){if(i.userData.levTween)return;i.userData.enTween&&(i.userData.enTween.stop(),i.userData.enTween=null);const n=new Z.Tween(i.scale).to({z:1},100);i.userData.levTween=n,n.start()}}),s){if(s.userData.enTween)return;s.userData.levTween&&(s.userData.levTween.stop(),s.userData.levTween=null);const i=new Z.Tween(s.scale).to({z:e},100);return s.userData.enTween=i,i.start(),s.userData.index}return-1}render(){this.object3d.scale.z=0,new Z.Tween(this.object3d.scale).to({z:1},1e3).easing(Z.Easing.Sinusoidal.InOut).start()}}class Qt extends I.BaseObject{constructor(t){super(),this.rectAreaLightUniformsLibInit=!1,this.options=t}create(){var e,s,i,n,o,l,c,m,a,h,g,f,b,_,A,S,G;const t=this.options;if(t.type==="AmbientLight"){const v=new w.AmbientLight(t.color);v.name="环境光",this.object3d=v}else if(t.type==="DirectionalLight"){const v=new w.DirectionalLight(t.color,t.intensity);v.name="平行光",v.target.position.set(0,0,0),this.object3d=v,v.target.name="平行光目标",v.shadow.camera.name="平行光阴影相机",v.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=v}else if(t.type==="PointLight"){const v=new w.PointLight((e=t.color)!=null?e:16777215,(s=t.intensity)!=null?s:1,(i=t.distance)!=null?i:0,(n=t.decay)!=null?n:2);v.name="点光源",this.object3d=v,this.pointLight=v}else if(t.type==="SpotLight"){const v=new w.SpotLight((o=t.color)!=null?o:16777215,(l=t.intensity)!=null?l:1,(c=t.distance)!=null?c:0,(m=t.angle)!=null?m:Math.PI/3,(a=t.penumbra)!=null?a:1,(h=t.decay)!=null?h:2);v.name="聚光灯",this.object3d=v,this.spotLight=v,v.target.name="聚光灯目标"}else if(t.type==="HemisphereLight"){const v=new w.HemisphereLight((g=t.color)!=null?g:16777215,(f=t.groundColor)!=null?f:16777215,(b=t.intensity)!=null?b:1);v.name="半球光",this.object3d=v,this.hemisphereLight=v}else if(t.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Xt.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const v=new w.RectAreaLight((_=t.color)!=null?_:16777215,(A=t.intensity)!=null?A:1,(S=t.width)!=null?S:10,(G=t.height)!=null?G:10);v.name="矩形区域光",this.object3d=v,this.rectAreaLight=v}}render(){const t=this.object3d;t.target&&this.pencil.scene.add(t.target);const e=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const s=this.spotLight||this.directionalLight;s.position.copy(e),s.target.position.copy(e)}else this.pointLight&&this.pointLight.position.copy(e)}dispose(){const t=this.object3d;t.target&&this.pencil.scene.remove(t.target),super.dispose()}}function N(r,t=0){const e=r[0].index!==null,s=new Set(Object.keys(r[0].attributes)),i=new Set(Object.keys(r[0].morphAttributes)),n={},o={},l=r[0].morphTargetsRelative,c=new T.BufferGeometry;let m=0;for(let a=0;a<r.length;++a){const h=r[a];let g=0;if(e!==(h.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+a+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in h.attributes){if(!s.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+a+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;n[f]===void 0&&(n[f]=[]),n[f].push(h.attributes[f]),g++}if(g!==s.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+a+". Make sure all geometries have the same number of attributes."),null;if(l!==h.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+a+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in h.morphAttributes){if(!i.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+a+". .morphAttributes must be consistent throughout all geometries."),null;o[f]===void 0&&(o[f]=[]),o[f].push(h.morphAttributes[f])}if(t){let f;if(e)f=h.index.count;else if(h.attributes.position!==void 0)f=h.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+a+". The geometry must have either an index or a position attribute"),null;if(t===1)c.addGroup(m,f,a);else if(t===2&&h.groups.length>0)for(let b of h.groups){let _=b.materialIndex;c.addGroup(m+b.start,Math.min(b.count,f),_)}m+=f}}if(e){let a=0;const h=[];for(let g=0;g<r.length;++g){const f=r[g].index;for(let b=0;b<f.count;++b)h.push(f.getX(b)+a);a+=r[g].attributes.position.count}c.setIndex(h)}for(const a in n){const h=Vt(n[a]);if(!h)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+a+" attribute."),null;c.setAttribute(a,h)}for(const a in o){const h=o[a][0].length;if(h===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[a]=[];for(let g=0;g<h;++g){const f=[];for(let _=0;_<o[a].length;++_)f.push(o[a][_][g]);const b=Vt(f);if(!b)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+a+" morphAttribute."),null;c.morphAttributes[a].push(b)}}return t===2?te(c):c}function Vt(r){let t,e,s,i=-1,n=0;for(let m=0;m<r.length;++m){const a=r[m];if(t===void 0&&(t=a.array.constructor),t!==a.array.constructor)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.array must be of consistent array types across matching attributes."),null;if(e===void 0&&(e=a.itemSize),e!==a.itemSize)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.itemSize must be consistent across matching attributes."),null;if(s===void 0&&(s=a.normalized),s!==a.normalized)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.normalized must be consistent across matching attributes."),null;if(i===-1&&(i=a.gpuType),i!==a.gpuType)return console.error("THREE.BufferGeometryUtils: .mergeAttributes() failed. BufferAttribute.gpuType must be consistent across matching attributes."),null;n+=a.count*e}const o=new t(n),l=new T.BufferAttribute(o,e,s);let c=0;for(let m=0;m<r.length;++m){const a=r[m];if(a.isInterleavedBufferAttribute){const h=c/e;for(let g=0,f=a.count;g<f;g++)for(let b=0;b<e;b++){const _=a.getComponent(g,b);l.setComponent(g+h,b,_)}}else o.set(a.array,c);c+=a.count*e}return i!==void 0&&(l.gpuType=i),l}function te(r){if(r.groups.length===0)return console.warn("THREE.BufferGeometryUtils.mergeGroups(): No groups are defined. Nothing to merge."),r;let t=r.groups;if(t=t.sort((o,l)=>o.materialIndex!==l.materialIndex?o.materialIndex-l.materialIndex:o.start-l.start),r.getIndex()===null){const o=r.getAttribute("position"),l=[];for(let c=0;c<o.count;c+=3)l.push(c,c+1,c+2);r.setIndex(l)}const e=r.getIndex(),s=[];for(let o=0;o<t.length;o++){const l=t[o],c=l.start,m=c+l.count;for(let a=c;a<m;a++)s.push(e.getX(a))}r.dispose(),r.setIndex(s);let i=0;for(let o=0;o<t.length;o++){const l=t[o];l.start=i,i+=l.count}let n=t[0];r.groups=[n];for(let o=1;o<t.length;o++){const l=t[o];n.materialIndex===l.materialIndex?n.count+=l.count:(n=l,r.groups.push(n))}return r}const Pt=r=>{const{points:t}=r,e=t.reduce((i,n,o)=>(o<t.length-1&&i.push(n,t[o+1]),i),[]);return new w.BufferGeometry().setFromPoints(e)};let ee=class extends I.BaseObject{constructor(t={}){super(),this.options=P({},t)}get material(){var t;return(t=this.object3d)==null?void 0:t.material}create(){return it(this,null,function*(){const{points:t,pointsArr:e,geometry:s,geometryArr:i,material:n,useGroups:o,setPointWidth:l,lineWidthArr:c,materialParameters:m,instanceCount:a}=this.options;let h=n,g=s;!h&&m&&(h=this.getMaterial(m)),!g&&t?g=Pt({points:t}):!g&&e?g=N(e.map(b=>Pt({points:b})),o!=null?o:0):!g&&i&&i.length>1?g=N(i,o!=null?o:0):!g&&i&&i.length===1&&([g]=i);const f=new Ot.LineSegmentsGeometry().fromLineSegments(new w.LineSegments(g));if(this.pencil.options.WebGPUTHREE){a&&(f.instanceCount=a);const b=new I.LineSegments2(f,h);b.computeLineDistances(),this.object3d=b}else{const b=new Yt.LineSegments2(f,h);b.computeLineDistances(),this.object3d=b}})}getMaterial(t){return new Rt.LineMaterial(P({color:new w.Color("#ffffff")},t))}};function pt(r,t,e,s,i){let n;if(r=r.subarray||r.slice?r:r.buffer,e=e.subarray||e.slice?e:e.buffer,r=t?r.subarray?r.subarray(t,i&&t+i):r.slice(t,i&&t+i):r,e.set)e.set(r,s);else for(n=0;n<r.length;n++)e[n+s]=r[n];return e}function se(r){return r instanceof Float32Array?r:r instanceof w.BufferGeometry?r.getAttribute("position").array:r.map(t=>{const e=Array.isArray(t);return t instanceof w.Vector3?[t.x,t.y,t.z]:t instanceof w.Vector2?[t.x,t.y,0]:e&&t.length===3?[t[0],t[1],t[2]]:e&&t.length===2?[t[0],t[1],0]:t}).flat()}class Nt extends w.BufferGeometry{constructor(){super(),this.type="MeshLine",this.isMeshLine=!0,this.positions=[],this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[],this.counters=[],this.widthCallback=null,this._points=[],this.matrixWorld=new w.Matrix4,Object.defineProperties(this,{points:{enumerable:!0,get(){return this._points},set(t){this.setPoints(t,this.widthCallback)}}})}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e){if(t=se(t),this._points=t,this.widthCallback=e!=null?e:null,this.positions=[],this.counters=[],t.length&&t[0]instanceof w.Vector3)for(let s=0;s<t.length;s++){const i=t[s],n=s/(t.length-1);this.positions.push(i.x,i.y,i.z),this.positions.push(i.x,i.y,i.z),this.counters.push(n),this.counters.push(n)}else for(let s=0;s<t.length;s+=3){const i=s/(t.length-1);this.positions.push(t[s],t[s+1],t[s+2]),this.positions.push(t[s],t[s+1],t[s+2]),this.counters.push(i),this.counters.push(i)}this.process()}compareV3(t,e){const s=t*6,i=e*6;return this.positions[s]===this.positions[i]&&this.positions[s+1]===this.positions[i+1]&&this.positions[s+2]===this.positions[i+2]}copyV3(t){const e=t*6;return[this.positions[e],this.positions[e+1],this.positions[e+2]]}process(){const t=this.positions.length/6;this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[];let e,s;this.compareV3(0,t-1)?s=this.copyV3(t-2):s=this.copyV3(0),this.previous.push(s[0],s[1],s[2]),this.previous.push(s[0],s[1],s[2]);for(let i=0;i<t;i++){if(this.side.push(1),this.side.push(-1),this.widthCallback?e=this.widthCallback(i/(t-1)):e=1,this.width.push(e),this.width.push(e),this.uvs.push(i/(t-1),0),this.uvs.push(i/(t-1),1),i<t-1){s=this.copyV3(i),this.previous.push(s[0],s[1],s[2]),this.previous.push(s[0],s[1],s[2]);const n=i*2;this.indices_array.push(n,n+1,n+2),this.indices_array.push(n+2,n+1,n+3)}i>0&&(s=this.copyV3(i),this.next.push(s[0],s[1],s[2]),this.next.push(s[0],s[1],s[2]))}this.compareV3(t-1,0)?s=this.copyV3(1):s=this.copyV3(t-1),this.next.push(s[0],s[1],s[2]),this.next.push(s[0],s[1],s[2]),!this._attributes||this._attributes.position.count!==this.counters.length?this._attributes={position:new w.BufferAttribute(new Float32Array(this.positions),3),previous:new w.BufferAttribute(new Float32Array(this.previous),3),next:new w.BufferAttribute(new Float32Array(this.next),3),side:new w.BufferAttribute(new Float32Array(this.side),1),width:new w.BufferAttribute(new Float32Array(this.width),1),uv:new w.BufferAttribute(new Float32Array(this.uvs),2),index:new w.BufferAttribute(new Uint16Array(this.indices_array),1),counters:new w.BufferAttribute(new Float32Array(this.counters),1)}:(this._attributes.position.copyArray(new Float32Array(this.positions)),this._attributes.position.needsUpdate=!0,this._attributes.previous.copyArray(new Float32Array(this.previous)),this._attributes.previous.needsUpdate=!0,this._attributes.next.copyArray(new Float32Array(this.next)),this._attributes.next.needsUpdate=!0,this._attributes.side.copyArray(new Float32Array(this.side)),this._attributes.side.needsUpdate=!0,this._attributes.width.copyArray(new Float32Array(this.width)),this._attributes.width.needsUpdate=!0,this._attributes.uv.copyArray(new Float32Array(this.uvs)),this._attributes.uv.needsUpdate=!0,this._attributes.index.copyArray(new Uint16Array(this.indices_array)),this._attributes.index.needsUpdate=!0),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setIndex(this._attributes.index),this.computeBoundingSphere(),this.computeBoundingBox()}advance({x:t,y:e,z:s}){const i=this._attributes.position.array,n=this._attributes.previous.array,o=this._attributes.next.array,l=i.length;pt(i,0,n,0,l),pt(i,6,i,0,l-6),i[l-6]=t,i[l-5]=e,i[l-4]=s,i[l-3]=t,i[l-2]=e,i[l-1]=s,pt(i,6,o,0,l-6),o[l-6]=t,o[l-5]=e,o[l-4]=s,o[l-3]=t,o[l-2]=e,o[l-1]=s,this._attributes.position.needsUpdate=!0,this._attributes.previous.needsUpdate=!0,this._attributes.next.needsUpdate=!0}}function ie(r,t){const e=new w.Matrix4,s=new w.Ray,i=new w.Sphere,n=new w.Vector3,o=this.geometry;if(i.copy(o.boundingSphere),i.applyMatrix4(this.matrixWorld),!r.ray.intersectSphere(i,n))return;e.copy(this.matrixWorld).invert(),s.copy(r.ray).applyMatrix4(e);const l=new w.Vector3,c=new w.Vector3,m=new w.Vector3,a=this instanceof w.LineSegments?2:1,h=o.index,g=o.attributes;if(h!==null){const f=h.array,b=g.position.array,_=g.width.array;for(let A=0,S=f.length-1;A<S;A+=a){const G=f[A],v=f[A+1];l.fromArray(b,G*3),c.fromArray(b,v*3);const U=_[Math.floor(A/3)]!=null?_[Math.floor(A/3)]:1,X=r.params.Line.threshold+this.material.lineWidth*U/2,C=X*X;if(s.distanceSqToSegment(l,c,n,m)>C)continue;n.applyMatrix4(this.matrixWorld);const R=r.ray.origin.distanceTo(n);R<r.near||R>r.far||(t.push({distance:R,point:m.clone().applyMatrix4(this.matrixWorld),index:A,face:null,faceIndex:void 0,object:this}),A=S)}}}const mt=r=>{const{setPointWidth:t,nodes:e}=r,s=new Nt;return s.setPoints(e,t),s};class ne extends I.BaseObject{constructor(t={}){super(),this.options=P({},t)}get material(){var t;return(t=this.object3d)==null?void 0:t.material}create(){return it(this,null,function*(){const{nodes:t,nodesArr:e,geometry:s,geometryArr:i,material:n,useGroups:o,setPointWidth:l,lineWidthArr:c,materialParameters:m}=this.options;let a=n,h=s;!a&&m&&(a=this.getMaterial(m)),!h&&t?h=mt({nodes:t,setPointWidth:l}):!h&&e?h=N(e.map((g,f)=>{let b=l;return!b&&c&&(b=()=>{var _;return(_=c[f])!=null?_:c[0]}),mt({nodes:g,setPointWidth:b})}),o!=null?o:0):!h&&i&&i.length>1?h=N(i,o!=null?o:0):!h&&i&&i.length===1&&([h]=i),this.createMesh(h,a)})}setGeometry(t,e){const s=mt({nodes:t,setPointWidth:e}),i=this.object3d,n=i.geometry;i.geometry=s,n.dispose()}getMaterial(t){const{width:e,height:s}=this.pencil.getSize();return new I.MeshLineMaterial(P({color:new w.Color("#ffffff"),resolution:new w.Vector2(e,s)},t))}addGeometries(t){const e=this.object3d,s=N([e.geometry,...t]);e.geometry=s}resize(t,e){var s,i;(i=(s=this.material)==null?void 0:s.uniforms)==null||i.resolution.value.set(t,e)}useMaterial(t){super.useMaterial(t);const{width:e,height:s}=this.pencil.getSize();this.resize(e,s)}animate({duration:t=1e3,delay:e=0,repeat:s=0,lineLoop:i,onRepeat:n,onUpdate:o,onComplete:l,startShow:c}={}){const{offset:m,offsetLoop:a}=this.material.uniforms;if(this.material.userData.tween)return;const h=i!=null?i:!0;m.value.x=1,a.value=h&&c?1:0;let g=0;const f=new Z.Tween(m.value).to({x:-1},t).delay(e).repeat(s).onUpdate(({x:b})=>{h&&b<=0&&a.value===0&&(a.value=1),o&&o(b)}).onRepeat(()=>{g+=1,n&&n(g)}).onComplete(()=>{l&&l()}).start();this.material.userData.tween=f}render(){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}dispose(){this.material.userData.tween&&(this.material.userData.tween.stop(),Z.remove(this.material.userData.tween)),super.dispose()}}const It=r=>{const l=r,{coordinate:t,startHeight:e,height:s}=l,i=dt(l,["coordinate","startHeight","height"]);let n=e||0;return typeof e!="undefined"&&typeof s!="undefined"&&(n=e+s),new I.PolygonGeometry([t],lt(P({},i),{startHeight:e,endHeight:n}))};class re extends I.BaseObject{constructor(t){super(),this.options=P({},t)}create(){const c=this.options,{geometry:t,coordinateArr:e,coordinate:s,material:i,useGroups:n}=c,o=dt(c,["geometry","coordinateArr","coordinate","material","useGroups"]);let l=t;if(!l&&s)l=It(P({coordinate:s},o));else if(!l&&e){const m=e.map(a=>It(P({coordinate:a},o)));l=N(m,n!=null?n:0)}this.createMesh(l,i)}}class K extends T.BufferGeometry{constructor(t=new T.Shape([new T.Vector2(.5,.5),new T.Vector2(-.5,.5),new T.Vector2(-.5,-.5),new T.Vector2(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const s=this,i=[],n=[];for(let l=0,c=t.length;l<c;l++){const m=t[l];o(m)}this.setAttribute("position",new T.Float32BufferAttribute(i,3)),this.setAttribute("uv",new T.Float32BufferAttribute(n,2)),this.computeVertexNormals();function o(l){var xt,vt,At;const c=[],m=e.curveSegments!==void 0?e.curveSegments:12,a=e.steps!==void 0?e.steps:1,h=e.depth!==void 0?e.depth:1;let g=e.bevelEnabled!==void 0?e.bevelEnabled:!0,f=e.bevelThickness!==void 0?e.bevelThickness:.2,b=e.bevelSize!==void 0?e.bevelSize:f-.1,_=e.bevelOffset!==void 0?e.bevelOffset:0,A=e.bevelSegments!==void 0?e.bevelSegments:3;const S=e.extrudePath,G=e.UVGenerator!==void 0?e.UVGenerator:oe,v=(xt=e.hasTop)!=null?xt:!0,U=(vt=e.hasBottom)!=null?vt:!0,X=(At=e.hasSide)!=null?At:!0;let C,J=!1,R,Q,tt,D;S&&(C=S.getSpacedPoints(a),J=!0,g=!1,R=S.computeFrenetFrames(a,!1),Q=new T.Vector3,tt=new T.Vector3,D=new T.Vector3),g||(A=0,f=0,b=0,_=0);const gt=l.extractPoints(m);let O=gt.shape;const V=gt.holes;if(!T.ShapeUtils.isClockWise(O)){O=O.reverse();for(let u=0,d=V.length;u<d;u++){const p=V[u];T.ShapeUtils.isClockWise(p)&&(V[u]=p.reverse())}}const et=T.ShapeUtils.triangulateShape(O,V),z=O;for(let u=0,d=V.length;u<d;u++){const p=V[u];O=O.concat(p)}function Y(u,d,p){return d||console.error("THREE.ExtrudeGeometry: vec does not exist"),u.clone().addScaledVector(d,p)}const H=O.length,nt=et.length;function yt(u,d,p){let x,y,M;const L=u.x-d.x,E=u.y-d.y,B=p.x-u.x,j=p.y-u.y,st=L*L+E*E,ft=L*j-E*B;if(Math.abs(ft)>Number.EPSILON){const q=Math.sqrt(st),St=Math.sqrt(B*B+j*j),_t=d.x-E/q,Mt=d.y+L/q,Wt=p.x-j/St,kt=p.y+B/St,Tt=((Wt-_t)*j-(kt-Mt)*B)/(L*j-E*B);x=_t+L*Tt-u.x,y=Mt+E*Tt-u.y;const Lt=x*x+y*y;if(Lt<=2)return new T.Vector2(x,y);M=Math.sqrt(Lt/2)}else{let q=!1;L>Number.EPSILON?B>Number.EPSILON&&(q=!0):L<-Number.EPSILON?B<-Number.EPSILON&&(q=!0):Math.sign(E)===Math.sign(j)&&(q=!0),q?(x=-E,y=L,M=Math.sqrt(st)):(x=L,y=E,M=Math.sqrt(st/2))}return new T.Vector2(x/M,y/M)}const rt=[];for(let u=0,d=z.length,p=d-1,x=u+1;u<d;u++,p++,x++)p===d&&(p=0),x===d&&(x=0),rt[u]=yt(z[u],z[p],z[x]);const ut=[];let $,ot=rt.concat();for(let u=0,d=V.length;u<d;u++){const p=V[u];$=[];for(let x=0,y=p.length,M=y-1,L=x+1;x<y;x++,M++,L++)M===y&&(M=0),L===y&&(L=0),$[x]=yt(p[x],p[M],p[L]);ut.push($),ot=ot.concat($)}for(let u=0;u<A;u++){const d=u/A,p=f*Math.cos(d*Math.PI/2),x=b*Math.sin(d*Math.PI/2)+_;for(let y=0,M=z.length;y<M;y++){const L=Y(z[y],rt[y],x);W(L.x,L.y,-p)}for(let y=0,M=V.length;y<M;y++){const L=V[y];$=ut[y];for(let E=0,B=L.length;E<B;E++){const j=Y(L[E],$[E],x);W(j.x,j.y,-p)}}}const bt=b+_;for(let u=0;u<H;u++){const d=g?Y(O[u],ot[u],bt):O[u];J?(tt.copy(R.normals[0]).multiplyScalar(d.x),Q.copy(R.binormals[0]).multiplyScalar(d.y),D.copy(C[0]).add(tt).add(Q),W(D.x,D.y,D.z)):W(d.x,d.y,0)}for(let u=1;u<=a;u++)for(let d=0;d<H;d++){const p=g?Y(O[d],ot[d],bt):O[d];J?(tt.copy(R.normals[u]).multiplyScalar(p.x),Q.copy(R.binormals[u]).multiplyScalar(p.y),D.copy(C[u]).add(tt).add(Q),W(D.x,D.y,D.z)):W(p.x,p.y,h/a*u)}for(let u=A-1;u>=0;u--){const d=u/A,p=f*Math.cos(d*Math.PI/2),x=b*Math.sin(d*Math.PI/2)+_;for(let y=0,M=z.length;y<M;y++){const L=Y(z[y],rt[y],x);W(L.x,L.y,h+p)}for(let y=0,M=V.length;y<M;y++){const L=V[y];$=ut[y];for(let E=0,B=L.length;E<B;E++){const j=Y(L[E],$[E],x);J?W(j.x,j.y+C[a-1].y,C[a-1].x+p):W(j.x,j.y,h+p)}}}Ct(),X&&Dt();function Ct(){const u=i.length/3;if(g){let d=0,p=H*d;if(U)for(let x=0;x<nt;x++){const y=et[x];at(y[2]+p,y[1]+p,y[0]+p)}if(d=a+A*2,p=H*d,v)for(let x=0;x<nt;x++){const y=et[x];at(y[0]+p,y[1]+p,y[2]+p)}}else{if(U)for(let d=0;d<nt;d++){const p=et[d];at(p[2],p[1],p[0])}if(v)for(let d=0;d<nt;d++){const p=et[d];at(p[0]+H*a,p[1]+H*a,p[2]+H*a)}}s.addGroup(u,i.length/3-u,0)}function Dt(){const u=i.length/3;let d=0;wt(z,d),d+=z.length;for(let p=0,x=V.length;p<x;p++){const y=V[p];wt(y,d),d+=y.length}s.addGroup(u,i.length/3-u,1)}function wt(u,d){let p=u.length;for(;--p>=0;){const x=p;let y=p-1;y<0&&(y=u.length-1);for(let M=0,L=a+A*2;M<L;M++){const E=H*M,B=H*(M+1),j=d+x+E,st=d+y+E,ft=d+y+B,q=d+x+B;Ht(j,st,ft,q)}}}function W(u,d,p){c.push(u),c.push(d),c.push(p)}function at(u,d,p){k(u),k(d),k(p);const x=i.length/3,y=G.generateTopUV(s,i,x-3,x-2,x-1);F(y[0]),F(y[1]),F(y[2])}function Ht(u,d,p,x){k(u),k(d),k(x),k(d),k(p),k(x);const y=i.length/3,M=G.generateSideWallUV(s,i,y-6,y-3,y-2,y-1);F(M[0]),F(M[1]),F(M[3]),F(M[1]),F(M[2]),F(M[3])}function k(u){i.push(c[u*3+0]),i.push(c[u*3+1]),i.push(c[u*3+2])}function F(u){n.push(u.x),n.push(u.y)}}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON(),e=this.parameters.shapes,s=this.parameters.options;return ae(e,s,t)}static fromJSON(t,e){const s=[];for(let n=0,o=t.shapes.length;n<o;n++){const l=e[t.shapes[n]];s.push(l)}const i=t.options.extrudePath;return console.log(i.type),i!==void 0&&(t.options.extrudePath=new w[`${i.type}Curve`]().fromJSON(i)),new K(s,t.options)}}const oe={generateTopUV:function(r,t,e,s,i){const n=t[e*3],o=t[e*3+1],l=t[s*3],c=t[s*3+1],m=t[i*3],a=t[i*3+1];return[new T.Vector2(n,o),new T.Vector2(l,c),new T.Vector2(m,a)]},generateSideWallUV:function(r,t,e,s,i,n){const o=t[e*3],l=t[e*3+1],c=t[e*3+2],m=t[s*3],a=t[s*3+1],h=t[s*3+2],g=t[i*3],f=t[i*3+1],b=t[i*3+2],_=t[n*3],A=t[n*3+1],S=t[n*3+2];return Math.abs(l-a)<Math.abs(o-m)?[new T.Vector2(o,1-c),new T.Vector2(m,1-h),new T.Vector2(g,1-b),new T.Vector2(_,1-S)]:[new T.Vector2(l,1-c),new T.Vector2(a,1-h),new T.Vector2(f,1-b),new T.Vector2(A,1-S)]}};function ae(r,t,e){if(e.shapes=[],Array.isArray(r))for(let s=0,i=r.length;s<i;s++){const n=r[s];e.shapes.push(n.uuid)}else e.shapes.push(r.uuid);return e.options=Object.assign({},t),t.extrudePath!==void 0&&(e.options.extrudePath=t.extrudePath.toJSON()),e}class ce extends K{constructor(t,e){super(t,e);const s=new ht.Brush(new K(t,lt(P({},e),{hasTop:!0,hasSide:!0,hasBottom:!1})));s.updateMatrixWorld();const i=new w.Box3().setFromObject(s),n=new w.Vector3;i.getSize(n);const o=new w.Vector3(i.min.x+n.x/2,i.min.y+n.y/2,0);let l=e.topSegments,c=e.box3;if(c){c=c.union(i);const S=new w.Vector3;c.getSize(S);const G=Math.max(n.x/S.x,n.y/S.y);l=Math.ceil(e.topSegments*G)}if(l<4)return this;const m=new w.PlaneGeometry(n.x,n.y,l,l),a=new ht.Brush(m);a.position.set(o.x,o.y,o.z),a.updateMatrixWorld();const g=new ht.Evaluator().evaluate(a,s,ht.INTERSECTION),f=g.geometry.getAttribute("position"),b=new w.Float32BufferAttribute(f.count*2,2);for(let S=0;S<f.count;S++){const G=f.getZ(S);f.setZ(S,e.depth+G)}if(c){const S=c.min,G=c.max,v=new w.Vector3().subVectors(G,S);for(let U=0;U<f.count;U++){const X=f.getX(U),C=f.getY(U),J=(X-S.x)/v.x,R=(C-S.y)/v.y;b.setXY(U,J,R)}g.geometry.setAttribute("uv",b)}f.needsUpdate=!0;const _=new K(t,lt(P({},e),{hasTop:!1})),A=N([g.geometry,_],2);this.copy(A.toNonIndexed())}}const Ut=r=>{const{split:t,depth:e,points:s,box3:i,hasTop:n,hasBottom:o,hasSide:l,sideRepeat:c,topSegments:m}=r,a=m?ce:K,h=new a(new w.Shape(s),{depth:e,bevelEnabled:!1,box3:i,UVGenerator:Bt.getUVGenerator({split:t,box3:i,sideRepeat:c}),hasTop:n,hasBottom:o,hasSide:l,topSegments:m});return Bt.claerUVGenerator(),h};class le extends I.BaseObject{constructor(t){super(),this.options=P({depth:1},t)}create(){return it(this,null,function*(){const{points:t,pointsArr:e,useGroups:s,depth:i,geometry:n,geometryArr:o,material:l,box3:c,split:m,hasTop:a,hasBottom:h,hasSide:g}=this.options,f=Array.isArray(i)?i:[i],b=Array.isArray(c)?c:[c],_=l;let A=n;_||console.log("material is null"),!A&&t?A=Ut({points:t,depth:f[0],box3:b[0],split:m,hasTop:a,hasBottom:h,hasSide:g}):!A&&e?A=N(e.map((S,G)=>{var v,U;return Ut({points:S,depth:(v=f[G])!=null?v:f[0],box3:(U=b[G])!=null?U:b[0],split:m,hasTop:a,hasBottom:h,hasSide:g})}),s!=null?s:0):!A&&o&&o.length>1?A=N(o,s!=null?s:0):!A&&o&&o.length===1&&([A]=o),this.createMesh(A,_)})}addGeometries(t){const e=this.object3d,s=N([e.geometry,...t]);e.geometry=s}setTextureAnisotropic(t,e){t.anisotropy=e||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const he=r=>{const{topColor:t,sideColor:e,sideMap:s,createCanvasObjectURL:i,split:n,maxAnisotropy:o}=r;return new Promise(l=>{const c=s?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};c.onload=()=>{const m=n,a=document.createElement("canvas"),h=a.getContext("2d");a.height=c.height/(1-m),a.width=c.width,m&&t&&(h.fillStyle=t,h.fillRect(0,0,c.width,a.height*m)),s&&c instanceof HTMLImageElement?h.drawImage(c,0,a.height*m,c.width,c.height):e&&(h.fillStyle=e,h.fillRect(0,a.height*m,c.width,c.height)),i&&a.toBlob(f=>{console.log(URL.createObjectURL(f))});const g=new w.CanvasTexture(a);l(g)},s?c.src=s:c instanceof HTMLImageElement||c.onload()})};exports.Group=I.Group;exports.MeshLineMaterial=I.MeshLineMaterial;exports.getConicPolygonGeometry=I.PolygonGeometry;exports.getConicPolygonGeometryMetas=I.getMetas;Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Ot.LineSegmentsGeometry});Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>Rt.LineMaterial});exports.ConicPolygon=re;exports.ExtrudePolygon=le;exports.Light=Qt;exports.Line=ne;exports.Line2=ee;exports.MeshLineGeometry=Nt;exports.MeshLineRaycast=ie;exports.Node=Zt;exports.Pie=Kt;exports.getSplitTexture=he;
|
|
1
|
+
"use strict";var $t=Object.defineProperty,Jt=Object.defineProperties;var Xt=Object.getOwnPropertyDescriptors;var ht=Object.getOwnPropertySymbols;var Pt=Object.prototype.hasOwnProperty,Bt=Object.prototype.propertyIsEnumerable;var Gt=(r,t,e)=>t in r?$t(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,P=(r,t)=>{for(var e in t||(t={}))Pt.call(t,e)&&Gt(r,e,t[e]);if(ht)for(var e of ht(t))Bt.call(t,e)&&Gt(r,e,t[e]);return r},lt=(r,t)=>Jt(r,Xt(t));var pt=(r,t)=>{var e={};for(var s in r)Pt.call(r,s)&&t.indexOf(s)<0&&(e[s]=r[s]);if(r!=null&&ht)for(var s of ht(r))t.indexOf(s)<0&&Bt.call(r,s)&&(e[s]=r[s]);return e};var nt=(r,t,e)=>new Promise((s,i)=>{var n=c=>{try{l(e.next(c))}catch(b){i(b)}},a=c=>{try{l(e.throw(c))}catch(b){i(b)}},l=c=>c.done?s(c.value):Promise.resolve(c.value).then(n,a);l((e=e.apply(r,t)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const B=require("../index2.js"),L=require("three"),Yt=require("@tweenjs/tween.js"),Zt=require("three/examples/jsm/lights/RectAreaLightUniformsLib"),mt=require("three/examples/jsm/utils/BufferGeometryUtils"),Qt=require("three/examples/jsm/lines/LineSegments2"),Dt=require("three/examples/jsm/lines/LineSegmentsGeometry"),Ht=require("three/examples/jsm/lines/LineMaterial"),Ut=require("../uvGenerator.js"),ut=require("three-bvh-csg");function zt(r){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const e in r)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(r,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>r[e]})}}return t.default=r,Object.freeze(t)}const x=zt(L),tt=zt(Yt);class Kt extends B.BaseObject{constructor(t){super(),this.objectType="BaseObject#Node",this.onNodePointerIndex=[],this.options=P({type:"2d"},t)}create(){const{position:t,children:e}=this.options,s=document.createElement("div");this.element=s,e&&s.appendChild(e),this.options.type==="3d"?this.createCSS3DObject(s):this.options.type==="3dSprite"?this.createCSS3DSprite(s):this.createCSS2DObject(s),t&&this.object3d.position.copy(t)}setChildren(t){this.options.children=t,this.element.innerHTML="",this.element.appendChild(t)}showAndEnsureVisible(){const t=this.options.children;t&&(t.style.visibility="hidden",this.show(),setTimeout(()=>{t.style.visibility="",this.ensureVisible()}))}moveElementToViewport(){const t=this.options.children;if(!t)return;const e=t.getBoundingClientRect(),s=window.innerWidth,i=window.innerHeight;let n=0,a=0;e.left<0?n=-e.left:e.right>s&&(n=s-e.right),e.top<0?a=-e.top:e.bottom>i&&(a=i-e.bottom),e.left+n<0&&(n=-e.left),e.top+a<0&&(a=-e.top),(n!==0||a!==0)&&(t.style.transform=`translate(${n}px, ${a}px)`)}ensureVisible(){const t=this.options.children;if(!t)return;t.style.transform&&(t.style.transform="");const e=new IntersectionObserver(s=>{s.forEach(i=>{i.isIntersecting&&(this.moveElementToViewport(),e.disconnect())})});e.observe(t)}onPointerEvent(t,e){const s=this.lead.handlePickNode([this],t,e);this.onNodePointerIndex.push(s)}dispose(){this.onNodePointerIndex.forEach(t=>{this.lead.removePickNode(t)}),super.dispose()}}class te extends B.BaseObject{constructor(t){super(),this.options=P({maxDepth:10,percentDepth:!1,innerRadius:25,outRadius:42,activeIndex:-1},t)}create(){return nt(this,null,function*(){this.createGroup();const{data:t,maxDepth:e,colors:s,material:i,percentDepth:n,activeIndex:a}=this.options,l=Math.max(...t),c=t.reduce((o,u)=>o+u,0);let b=Math.PI/2;t.forEach((o,u)=>{if(o===0)return;const y=Math.PI*2*(o/c),f=s[u],w=n?e*(o/l):e,T=this.createGeometry(w,y),S=i?i.clone():new x.MeshBasicMaterial({color:f});i&&S.color.set(f);const _=new x.Mesh(T,S);_.userData.depth=w,_.userData.index=u,_.rotateZ(b),b+=y,this.add(_)}),a!==-1&&this.setActive(a)})}createGeometry(t,e){const{outRadius:s,innerRadius:i}=this.options,n=new x.Shape;return n.moveTo(s,0),n.lineTo(i,0),n.absarc(0,0,i,0,e,!1),n.absarc(0,0,s,e,0,!0),new x.ExtrudeGeometry(n,{curveSegments:48,depth:t,bevelEnabled:!1})}handlePick(t,e=1.3){const{object:s}=this.pencil.pick(t,this.object3d.children)||{},i=s?this.object3d.children.findIndex(n=>n===s):this.options.activeIndex;return this.setActive(i,e)}setActive(t,e=1.3){const s=this.object3d.children[t];if(this.object3d.children.forEach(i=>{if(!(s&&s===i)&&i.scale.z!==1){if(i.userData.levTween)return;i.userData.enTween&&(i.userData.enTween.stop(),i.userData.enTween=null);const n=new tt.Tween(i.scale).to({z:1},100);i.userData.levTween=n,n.start()}}),s){if(s.userData.enTween)return;s.userData.levTween&&(s.userData.levTween.stop(),s.userData.levTween=null);const i=new tt.Tween(s.scale).to({z:e},100);return s.userData.enTween=i,i.start(),s.userData.index}return-1}render(){this.object3d.scale.z=0,new tt.Tween(this.object3d.scale).to({z:1},1e3).easing(tt.Easing.Sinusoidal.InOut).start()}}class ee extends B.BaseObject{constructor(t){super(),this.rectAreaLightUniformsLibInit=!1,this.options=t}create(){var e,s,i,n,a,l,c,b,o,u,y,f,w,T,S,_,G;const t=this.options;if(t.type==="AmbientLight"){const A=new x.AmbientLight(t.color);A.name="环境光",this.object3d=A}else if(t.type==="DirectionalLight"){const A=new x.DirectionalLight(t.color,t.intensity);A.name="平行光",A.target.position.set(0,0,0),this.object3d=A,A.target.name="平行光目标",A.shadow.camera.name="平行光阴影相机",A.shadow.camera.userData.directionalLightShadow=!0,this.directionalLight=A}else if(t.type==="PointLight"){const A=new x.PointLight((e=t.color)!=null?e:16777215,(s=t.intensity)!=null?s:1,(i=t.distance)!=null?i:0,(n=t.decay)!=null?n:2);A.name="点光源",this.object3d=A,this.pointLight=A}else if(t.type==="SpotLight"){const A=new x.SpotLight((a=t.color)!=null?a:16777215,(l=t.intensity)!=null?l:1,(c=t.distance)!=null?c:0,(b=t.angle)!=null?b:Math.PI/3,(o=t.penumbra)!=null?o:1,(u=t.decay)!=null?u:2);A.name="聚光灯",this.object3d=A,this.spotLight=A,A.target.name="聚光灯目标"}else if(t.type==="HemisphereLight"){const A=new x.HemisphereLight((y=t.color)!=null?y:16777215,(f=t.groundColor)!=null?f:16777215,(w=t.intensity)!=null?w:1);A.name="半球光",this.object3d=A,this.hemisphereLight=A}else if(t.type==="RectAreaLight"){this.rectAreaLightUniformsLibInit||(Zt.RectAreaLightUniformsLib.init(),this.rectAreaLightUniformsLibInit=!0);const A=new x.RectAreaLight((T=t.color)!=null?T:16777215,(S=t.intensity)!=null?S:1,(_=t.width)!=null?_:10,(G=t.height)!=null?G:10);A.name="矩形区域光",this.object3d=A,this.rectAreaLight=A}}render(){const t=this.object3d;t.target&&this.pencil.scene.add(t.target);const e=this.pencil.cameraTarget;if(this.spotLight||this.directionalLight){const s=this.spotLight||this.directionalLight;s.position.copy(e),s.target.position.copy(e)}else this.pointLight&&this.pointLight.position.copy(e)}dispose(){const t=this.object3d;t.target&&this.pencil.scene.remove(t.target),super.dispose()}}function C(r,t=0){const e=r[0].index!==null,s=new Set(Object.keys(r[0].attributes)),i=new Set(Object.keys(r[0].morphAttributes)),n={},a={},l=r[0].morphTargetsRelative,c=new L.BufferGeometry;let b=0;for(let o=0;o<r.length;++o){const u=r[o];let y=0;if(e!==(u.index!==null))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". All geometries must have compatible attributes; make sure index attribute exists among all geometries, or in none of them."),null;for(const f in u.attributes){if(!s.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+'. All geometries must have compatible attributes; make sure "'+f+'" attribute exists among all geometries, or in none of them.'),null;n[f]===void 0&&(n[f]=[]),n[f].push(u.attributes[f]),y++}if(y!==s.size)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". Make sure all geometries have the same number of attributes."),null;if(l!==u.morphTargetsRelative)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". .morphTargetsRelative must be consistent throughout all geometries."),null;for(const f in u.morphAttributes){if(!i.has(f))return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". .morphAttributes must be consistent throughout all geometries."),null;a[f]===void 0&&(a[f]=[]),a[f].push(u.morphAttributes[f])}if(t){let f;if(e)f=u.index.count;else if(u.attributes.position!==void 0)f=u.attributes.position.count;else return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed with geometry at index "+o+". The geometry must have either an index or a position attribute"),null;if(t===1)c.addGroup(b,f,o);else if(t===2&&u.groups.length>0)for(let w of u.groups){let T=w.materialIndex;c.addGroup(b+w.start,Math.min(w.count,f),T)}b+=f}}if(e){let o=0;const u=[];for(let y=0;y<r.length;++y){const f=r[y].index;for(let w=0;w<f.count;++w)u.push(f.getX(w)+o);o+=r[y].attributes.position.count}c.setIndex(u)}for(const o in n){const u=mt.mergeAttributes(n[o]);if(!u)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+o+" attribute."),null;c.setAttribute(o,u)}for(const o in a){const u=a[o][0].length;if(u===0)break;c.morphAttributes=c.morphAttributes||{},c.morphAttributes[o]=[];for(let y=0;y<u;++y){const f=[];for(let T=0;T<a[o].length;++T)f.push(a[o][T][y]);const w=mt.mergeAttributes(f);if(!w)return console.error("THREE.BufferGeometryUtils: .mergeGeometries() failed while trying to merge the "+o+" morphAttribute."),null;c.morphAttributes[o].push(w)}}return t===2?mt.mergeGroups(c):c}const Ot=r=>{const{points:t}=r,e=t.reduce((i,n,a)=>(a<t.length-1&&i.push(n,t[a+1]),i),[]);return new x.BufferGeometry().setFromPoints(e)};let se=class extends B.BaseObject{constructor(t={}){super(),this.options=P({},t)}get material(){var t;return(t=this.object3d)==null?void 0:t.material}create(){return nt(this,null,function*(){const{points:t,pointsArr:e,geometry:s,geometryArr:i,material:n,useGroups:a,setPointWidth:l,lineWidthArr:c,materialParameters:b,instanceCount:o}=this.options;let u=n,y=s;!u&&b&&(u=this.getMaterial(b)),!y&&t?y=Ot({points:t}):!y&&e?y=C(e.map(w=>Ot({points:w})),a!=null?a:0):!y&&i&&i.length>1?y=C(i,a!=null?a:0):!y&&i&&i.length===1&&([y]=i);const f=new Dt.LineSegmentsGeometry().fromLineSegments(new x.LineSegments(y));if(this.pencil.options.WebGPUTHREE){o&&(f.instanceCount=o);const w=new B.LineSegments2(f,u);w.computeLineDistances(),this.object3d=w}else{const w=new Qt.LineSegments2(f,u);w.computeLineDistances(),this.object3d=w}})}getMaterial(t){return new Ht.LineMaterial(P({color:new x.Color("#ffffff")},t))}};function gt(r,t,e,s,i){let n;if(r=r.subarray||r.slice?r:r.buffer,e=e.subarray||e.slice?e:e.buffer,r=t?r.subarray?r.subarray(t,i&&t+i):r.slice(t,i&&t+i):r,e.set)e.set(r,s);else for(n=0;n<r.length;n++)e[n+s]=r[n];return e}function ie(r){return r instanceof Float32Array?r:r instanceof x.BufferGeometry?r.getAttribute("position").array:r.map(t=>{const e=Array.isArray(t);return t instanceof x.Vector3?[t.x,t.y,t.z]:t instanceof x.Vector2?[t.x,t.y,0]:e&&t.length===3?[t[0],t[1],t[2]]:e&&t.length===2?[t[0],t[1],0]:t}).flat()}class Ct extends x.BufferGeometry{constructor(){super(),this.type="MeshLine",this.isMeshLine=!0,this.positions=[],this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[],this.counters=[],this.widthCallback=null,this._points=[],this.matrixWorld=new x.Matrix4,Object.defineProperties(this,{points:{enumerable:!0,get(){return this._points},set(t){this.setPoints(t,this.widthCallback)}}})}setMatrixWorld(t){this.matrixWorld=t}setPoints(t,e){if(t=ie(t),this._points=t,this.widthCallback=e!=null?e:null,this.positions=[],this.counters=[],t.length&&t[0]instanceof x.Vector3)for(let s=0;s<t.length;s++){const i=t[s],n=s/(t.length-1);this.positions.push(i.x,i.y,i.z),this.positions.push(i.x,i.y,i.z),this.counters.push(n),this.counters.push(n)}else for(let s=0;s<t.length;s+=3){const i=s/(t.length-1);this.positions.push(t[s],t[s+1],t[s+2]),this.positions.push(t[s],t[s+1],t[s+2]),this.counters.push(i),this.counters.push(i)}this.process()}compareV3(t,e){const s=t*6,i=e*6;return this.positions[s]===this.positions[i]&&this.positions[s+1]===this.positions[i+1]&&this.positions[s+2]===this.positions[i+2]}copyV3(t){const e=t*6;return[this.positions[e],this.positions[e+1],this.positions[e+2]]}process(){const t=this.positions.length/6;this.previous=[],this.next=[],this.side=[],this.width=[],this.indices_array=[],this.uvs=[];let e,s;this.compareV3(0,t-1)?s=this.copyV3(t-2):s=this.copyV3(0),this.previous.push(s[0],s[1],s[2]),this.previous.push(s[0],s[1],s[2]);for(let i=0;i<t;i++){if(this.side.push(1),this.side.push(-1),this.widthCallback?e=this.widthCallback(i/(t-1)):e=1,this.width.push(e),this.width.push(e),this.uvs.push(i/(t-1),0),this.uvs.push(i/(t-1),1),i<t-1){s=this.copyV3(i),this.previous.push(s[0],s[1],s[2]),this.previous.push(s[0],s[1],s[2]);const n=i*2;this.indices_array.push(n,n+1,n+2),this.indices_array.push(n+2,n+1,n+3)}i>0&&(s=this.copyV3(i),this.next.push(s[0],s[1],s[2]),this.next.push(s[0],s[1],s[2]))}this.compareV3(t-1,0)?s=this.copyV3(1):s=this.copyV3(t-1),this.next.push(s[0],s[1],s[2]),this.next.push(s[0],s[1],s[2]),!this._attributes||this._attributes.position.count!==this.counters.length?this._attributes={position:new x.BufferAttribute(new Float32Array(this.positions),3),previous:new x.BufferAttribute(new Float32Array(this.previous),3),next:new x.BufferAttribute(new Float32Array(this.next),3),side:new x.BufferAttribute(new Float32Array(this.side),1),width:new x.BufferAttribute(new Float32Array(this.width),1),uv:new x.BufferAttribute(new Float32Array(this.uvs),2),index:new x.BufferAttribute(new Uint16Array(this.indices_array),1),counters:new x.BufferAttribute(new Float32Array(this.counters),1)}:(this._attributes.position.copyArray(new Float32Array(this.positions)),this._attributes.position.needsUpdate=!0,this._attributes.previous.copyArray(new Float32Array(this.previous)),this._attributes.previous.needsUpdate=!0,this._attributes.next.copyArray(new Float32Array(this.next)),this._attributes.next.needsUpdate=!0,this._attributes.side.copyArray(new Float32Array(this.side)),this._attributes.side.needsUpdate=!0,this._attributes.width.copyArray(new Float32Array(this.width)),this._attributes.width.needsUpdate=!0,this._attributes.uv.copyArray(new Float32Array(this.uvs)),this._attributes.uv.needsUpdate=!0,this._attributes.index.copyArray(new Uint16Array(this.indices_array)),this._attributes.index.needsUpdate=!0),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setAttribute("position",this._attributes.position),this.setAttribute("previous",this._attributes.previous),this.setAttribute("next",this._attributes.next),this.setAttribute("side",this._attributes.side),this.setAttribute("width",this._attributes.width),this.setAttribute("uv",this._attributes.uv),this.setAttribute("counters",this._attributes.counters),this.setIndex(this._attributes.index),this.computeBoundingSphere(),this.computeBoundingBox()}advance({x:t,y:e,z:s}){const i=this._attributes.position.array,n=this._attributes.previous.array,a=this._attributes.next.array,l=i.length;gt(i,0,n,0,l),gt(i,6,i,0,l-6),i[l-6]=t,i[l-5]=e,i[l-4]=s,i[l-3]=t,i[l-2]=e,i[l-1]=s,gt(i,6,a,0,l-6),a[l-6]=t,a[l-5]=e,a[l-4]=s,a[l-3]=t,a[l-2]=e,a[l-1]=s,this._attributes.position.needsUpdate=!0,this._attributes.previous.needsUpdate=!0,this._attributes.next.needsUpdate=!0}}function ne(r,t){const e=new x.Matrix4,s=new x.Ray,i=new x.Sphere,n=new x.Vector3,a=this.geometry;if(i.copy(a.boundingSphere),i.applyMatrix4(this.matrixWorld),!r.ray.intersectSphere(i,n))return;e.copy(this.matrixWorld).invert(),s.copy(r.ray).applyMatrix4(e);const l=new x.Vector3,c=new x.Vector3,b=new x.Vector3,o=this instanceof x.LineSegments?2:1,u=a.index,y=a.attributes;if(u!==null){const f=u.array,w=y.position.array,T=y.width.array;for(let S=0,_=f.length-1;S<_;S+=o){const G=f[S],A=f[S+1];l.fromArray(w,G*3),c.fromArray(w,A*3);const U=T[Math.floor(S/3)]!=null?T[Math.floor(S/3)]:1,Q=r.params.Line.threshold+this.material.lineWidth*U/2,N=Q*Q;if(s.distanceSqToSegment(l,c,n,b)>N)continue;n.applyMatrix4(this.matrixWorld);const H=r.ray.origin.distanceTo(n);H<r.near||H>r.far||(t.push({distance:H,point:b.clone().applyMatrix4(this.matrixWorld),index:S,face:null,faceIndex:void 0,object:this}),S=_)}}}const yt=r=>{const{setPointWidth:t,nodes:e}=r,s=new Ct;return s.setPoints(e,t),s};class re extends B.BaseObject{constructor(t={}){super(),this.options=P({},t)}get material(){var t;return(t=this.object3d)==null?void 0:t.material}create(){return nt(this,null,function*(){const{nodes:t,nodesArr:e,geometry:s,geometryArr:i,material:n,useGroups:a,setPointWidth:l,lineWidthArr:c,materialParameters:b}=this.options;let o=n,u=s;!o&&b&&(o=this.getMaterial(b)),!u&&t?u=yt({nodes:t,setPointWidth:l}):!u&&e?u=C(e.map((y,f)=>{let w=l;return!w&&c&&(w=()=>{var T;return(T=c[f])!=null?T:c[0]}),yt({nodes:y,setPointWidth:w})}),a!=null?a:0):!u&&i&&i.length>1?u=C(i,a!=null?a:0):!u&&i&&i.length===1&&([u]=i),this.createMesh(u,o)})}setGeometry(t,e){const s=yt({nodes:t,setPointWidth:e}),i=this.object3d,n=i.geometry;i.geometry=s,n.dispose()}getMaterial(t){const{width:e,height:s}=this.pencil.getSize();return new B.MeshLineMaterial(P({color:new x.Color("#ffffff"),resolution:new x.Vector2(e,s)},t))}addGeometries(t){const e=this.object3d,s=C([e.geometry,...t]);e.geometry=s}resize(t,e){var s,i;(i=(s=this.material)==null?void 0:s.uniforms)==null||i.resolution.value.set(t,e)}useMaterial(t){super.useMaterial(t);const{width:e,height:s}=this.pencil.getSize();this.resize(e,s)}animate({duration:t=1e3,delay:e=0,repeat:s=0,lineLoop:i,onRepeat:n,onUpdate:a,onComplete:l,startShow:c}={}){const{offset:b,offsetLoop:o}=this.material.uniforms;if(this.material.userData.tween)return;const u=i!=null?i:!0;b.value.x=1,o.value=u&&c?1:0;let y=0;const f=new tt.Tween(b.value).to({x:-1},t).delay(e).repeat(s).onUpdate(({x:w})=>{u&&w<=0&&o.value===0&&(o.value=1),a&&a(w)}).onRepeat(()=>{y+=1,n&&n(y)}).onComplete(()=>{l&&l()}).start();this.material.userData.tween=f}render(){const{width:t,height:e}=this.pencil.getSize();this.resize(t,e)}dispose(){this.material.userData.tween&&(this.material.userData.tween.stop(),tt.remove(this.material.userData.tween)),super.dispose()}}const It=r=>{const l=r,{coordinate:t,startHeight:e,height:s}=l,i=pt(l,["coordinate","startHeight","height"]);let n=e||0;return typeof e!="undefined"&&typeof s!="undefined"&&(n=e+s),new B.PolygonGeometry([t],lt(P({},i),{startHeight:e,endHeight:n}))};class oe extends B.BaseObject{constructor(t){super(),this.options=P({},t)}create(){const c=this.options,{geometry:t,coordinateArr:e,coordinate:s,material:i,useGroups:n}=c,a=pt(c,["geometry","coordinateArr","coordinate","material","useGroups"]);let l=t;if(!l&&s)l=It(P({coordinate:s},a));else if(!l&&e){const b=e.map(o=>It(P({coordinate:o},a)));l=C(b,n!=null?n:0)}this.createMesh(l,i)}}class et extends L.BufferGeometry{constructor(t=new L.Shape([new L.Vector2(.5,.5),new L.Vector2(-.5,.5),new L.Vector2(-.5,-.5),new L.Vector2(.5,-.5)]),e={}){super(),this.type="ExtrudeGeometry",this.parameters={shapes:t,options:e},t=Array.isArray(t)?t:[t];const s=this,i=[],n=[];for(let l=0,c=t.length;l<c;l++){const b=t[l];a(b)}this.setAttribute("position",new L.Float32BufferAttribute(i,3)),this.setAttribute("uv",new L.Float32BufferAttribute(n,2)),this.computeVertexNormals();function a(l){var St,_t,Mt;const c=[],b=e.curveSegments!==void 0?e.curveSegments:12,o=e.steps!==void 0?e.steps:1,u=e.depth!==void 0?e.depth:1;let y=e.bevelEnabled!==void 0?e.bevelEnabled:!0,f=e.bevelThickness!==void 0?e.bevelThickness:.2,w=e.bevelSize!==void 0?e.bevelSize:f-.1,T=e.bevelOffset!==void 0?e.bevelOffset:0,S=e.bevelSegments!==void 0?e.bevelSegments:3;const _=e.extrudePath,G=e.UVGenerator!==void 0?e.UVGenerator:ae,A=(St=e.hasTop)!=null?St:!0,U=(_t=e.hasBottom)!=null?_t:!0,Q=(Mt=e.hasSide)!=null?Mt:!0;let N,X=!1,H,st,it,W;_&&(N=_.getSpacedPoints(o),X=!0,y=!1,H=_.computeFrenetFrames(o,!1),st=new L.Vector3,it=new L.Vector3,W=new L.Vector3),y||(S=0,f=0,w=0,T=0);const bt=l.extractPoints(b);let D=bt.shape;const O=bt.holes;if(!L.ShapeUtils.isClockWise(D)){D=D.reverse();for(let h=0,d=O.length;h<d;h++){const p=O[h];L.ShapeUtils.isClockWise(p)&&(O[h]=p.reverse())}}function wt(h){const p=10000000000000001e-36;let g=h[0];for(let m=1;m<=h.length;m++){const M=m%h.length,v=h[M],V=v.x-g.x,E=v.y-g.y,j=V*V+E*E,I=Math.max(Math.abs(v.x),Math.abs(v.y),Math.abs(g.x),Math.abs(g.y)),Z=p*I*I;if(j<=Z){h.splice(M,1),m--;continue}g=v}}wt(D),O.forEach(wt);const dt=O.length,z=D;for(let h=0;h<dt;h++){const d=O[h];D=D.concat(d)}function K(h,d,p){return d||console.error("THREE.ExtrudeGeometry: vec does not exist"),h.clone().addScaledVector(d,p)}const k=D.length;function xt(h,d,p){let g,m,M;const v=h.x-d.x,V=h.y-d.y,E=p.x-h.x,j=p.y-h.y,I=v*v+V*V,Z=v*j-V*E;if(Math.abs(Z)>Number.EPSILON){const R=Math.sqrt(I),Lt=Math.sqrt(E*E+j*j),Tt=d.x-V/R,Vt=d.y+v/R,qt=p.x-j/Lt,Ft=p.y+E/Lt,Et=((qt-Tt)*j-(Ft-Vt)*E)/(v*j-V*E);g=Tt+v*Et-h.x,m=Vt+V*Et-h.y;const jt=g*g+m*m;if(jt<=2)return new L.Vector2(g,m);M=Math.sqrt(jt/2)}else{let R=!1;v>Number.EPSILON?E>Number.EPSILON&&(R=!0):v<-Number.EPSILON?E<-Number.EPSILON&&(R=!0):Math.sign(V)===Math.sign(j)&&(R=!0),R?(g=-V,m=v,M=Math.sqrt(I)):(g=v,m=V,M=Math.sqrt(I/2))}return new L.Vector2(g/M,m/M)}const rt=[];for(let h=0,d=z.length,p=d-1,g=h+1;h<d;h++,p++,g++)p===d&&(p=0),g===d&&(g=0),rt[h]=xt(z[h],z[p],z[g]);const ft=[];let J,ot=rt.concat();for(let h=0,d=dt;h<d;h++){const p=O[h];J=[];for(let g=0,m=p.length,M=m-1,v=g+1;g<m;g++,M++,v++)M===m&&(M=0),v===m&&(v=0),J[g]=xt(p[g],p[M],p[v]);ft.push(J),ot=ot.concat(J)}let Y;if(S===0)Y=L.ShapeUtils.triangulateShape(z,O);else{const h=[],d=[];for(let p=0;p<S;p++){const g=p/S,m=f*Math.cos(g*Math.PI/2),M=w*Math.sin(g*Math.PI/2)+T;for(let v=0,V=z.length;v<V;v++){const E=K(z[v],rt[v],M);q(E.x,E.y,-m),g===0&&h.push(E)}for(let v=0,V=dt;v<V;v++){const E=O[v];J=ft[v];const j=[];for(let I=0,Z=E.length;I<Z;I++){const R=K(E[I],J[I],M);q(R.x,R.y,-m),g===0&&j.push(R)}g===0&&d.push(j)}}Y=L.ShapeUtils.triangulateShape(h,d)}const at=Y.length,vt=w+T;for(let h=0;h<k;h++){const d=y?K(D[h],ot[h],vt):D[h];X?(it.copy(H.normals[0]).multiplyScalar(d.x),st.copy(H.binormals[0]).multiplyScalar(d.y),W.copy(N[0]).add(it).add(st),q(W.x,W.y,W.z)):q(d.x,d.y,0)}for(let h=1;h<=o;h++)for(let d=0;d<k;d++){const p=y?K(D[d],ot[d],vt):D[d];X?(it.copy(H.normals[h]).multiplyScalar(p.x),st.copy(H.binormals[h]).multiplyScalar(p.y),W.copy(N[h]).add(it).add(st),q(W.x,W.y,W.z)):q(p.x,p.y,u/o*h)}for(let h=S-1;h>=0;h--){const d=h/S,p=f*Math.cos(d*Math.PI/2),g=w*Math.sin(d*Math.PI/2)+T;for(let m=0,M=z.length;m<M;m++){const v=K(z[m],rt[m],g);q(v.x,v.y,u+p)}for(let m=0,M=O.length;m<M;m++){const v=O[m];J=ft[m];for(let V=0,E=v.length;V<E;V++){const j=K(v[V],J[V],g);X?q(j.x,j.y+N[o-1].y,N[o-1].x+p):q(j.x,j.y,u+p)}}}Nt(),Q&&Wt();function Nt(){const h=i.length/3;if(y){let d=0,p=k*d;if(U)for(let g=0;g<at;g++){const m=Y[g];ct(m[2]+p,m[1]+p,m[0]+p)}if(d=o+S*2,p=k*d,A)for(let g=0;g<at;g++){const m=Y[g];ct(m[0]+p,m[1]+p,m[2]+p)}}else{if(U)for(let d=0;d<at;d++){const p=Y[d];ct(p[2],p[1],p[0])}if(A)for(let d=0;d<at;d++){const p=Y[d];ct(p[0]+k*o,p[1]+k*o,p[2]+k*o)}}s.addGroup(h,i.length/3-h,0)}function Wt(){const h=i.length/3;let d=0;At(z,d),d+=z.length;for(let p=0,g=O.length;p<g;p++){const m=O[p];At(m,d),d+=m.length}s.addGroup(h,i.length/3-h,1)}function At(h,d){let p=h.length;for(;--p>=0;){const g=p;let m=p-1;m<0&&(m=h.length-1);for(let M=0,v=o+S*2;M<v;M++){const V=k*M,E=k*(M+1),j=d+g+V,I=d+m+V,Z=d+m+E,R=d+g+E;kt(j,I,Z,R)}}}function q(h,d,p){c.push(h),c.push(d),c.push(p)}function ct(h,d,p){F(h),F(d),F(p);const g=i.length/3,m=G.generateTopUV(s,i,g-3,g-2,g-1);$(m[0]),$(m[1]),$(m[2])}function kt(h,d,p,g){F(h),F(d),F(g),F(d),F(p),F(g);const m=i.length/3,M=G.generateSideWallUV(s,i,m-6,m-3,m-2,m-1);$(M[0]),$(M[1]),$(M[3]),$(M[1]),$(M[2]),$(M[3])}function F(h){i.push(c[h*3+0]),i.push(c[h*3+1]),i.push(c[h*3+2])}function $(h){n.push(h.x),n.push(h.y)}}}copy(t){return super.copy(t),this.parameters=Object.assign({},t.parameters),this}toJSON(){const t=super.toJSON(),e=this.parameters.shapes,s=this.parameters.options;return ce(e,s,t)}static fromJSON(t,e){const s=[];for(let n=0,a=t.shapes.length;n<a;n++){const l=e[t.shapes[n]];s.push(l)}const i=t.options.extrudePath;return i!==void 0&&(t.options.extrudePath=new x[`${i.type}Curve`]().fromJSON(i)),new et(s,t.options)}}const ae={generateTopUV:function(r,t,e,s,i){const n=t[e*3],a=t[e*3+1],l=t[s*3],c=t[s*3+1],b=t[i*3],o=t[i*3+1];return[new L.Vector2(n,a),new L.Vector2(l,c),new L.Vector2(b,o)]},generateSideWallUV:function(r,t,e,s,i,n){const a=t[e*3],l=t[e*3+1],c=t[e*3+2],b=t[s*3],o=t[s*3+1],u=t[s*3+2],y=t[i*3],f=t[i*3+1],w=t[i*3+2],T=t[n*3],S=t[n*3+1],_=t[n*3+2];return Math.abs(l-o)<Math.abs(a-b)?[new L.Vector2(a,1-c),new L.Vector2(b,1-u),new L.Vector2(y,1-w),new L.Vector2(T,1-_)]:[new L.Vector2(l,1-c),new L.Vector2(o,1-u),new L.Vector2(f,1-w),new L.Vector2(S,1-_)]}};function ce(r,t,e){if(e.shapes=[],Array.isArray(r))for(let s=0,i=r.length;s<i;s++){const n=r[s];e.shapes.push(n.uuid)}else e.shapes.push(r.uuid);return e.options=Object.assign({},t),t.extrudePath!==void 0&&(e.options.extrudePath=t.extrudePath.toJSON()),e}class he extends et{constructor(t,e){super(t,e);const s=new ut.Brush(new et(t,lt(P({},e),{hasTop:!0,hasSide:!0,hasBottom:!1})));s.updateMatrixWorld();const i=new x.Box3().setFromObject(s),n=new x.Vector3;i.getSize(n);const a=new x.Vector3(i.min.x+n.x/2,i.min.y+n.y/2,0);let l=e.topSegments,c=e.box3;if(c){c=c.union(i);const _=new x.Vector3;c.getSize(_);const G=Math.max(n.x/_.x,n.y/_.y);l=Math.ceil(e.topSegments*G)}if(l<4)return this;const b=new x.PlaneGeometry(n.x,n.y,l,l),o=new ut.Brush(b);o.position.set(a.x,a.y,a.z),o.updateMatrixWorld();const y=new ut.Evaluator().evaluate(o,s,ut.INTERSECTION),f=y.geometry.getAttribute("position"),w=new x.Float32BufferAttribute(f.count*2,2);for(let _=0;_<f.count;_++){const G=f.getZ(_);f.setZ(_,e.depth+G)}if(c){const _=c.min,G=c.max,A=new x.Vector3().subVectors(G,_);for(let U=0;U<f.count;U++){const Q=f.getX(U),N=f.getY(U),X=(Q-_.x)/A.x,H=(N-_.y)/A.y;w.setXY(U,X,H)}y.geometry.setAttribute("uv",w)}f.needsUpdate=!0;const T=new et(t,lt(P({},e),{hasTop:!1})),S=C([y.geometry,T],2);this.copy(S.toNonIndexed())}}const Rt=r=>{const{split:t,depth:e,points:s,box3:i,hasTop:n,hasBottom:a,hasSide:l,sideRepeat:c,topSegments:b}=r,o=b?he:et,u=new o(new x.Shape(s),{depth:e,bevelEnabled:!1,box3:i,UVGenerator:Ut.getUVGenerator({split:t,box3:i,sideRepeat:c}),hasTop:n,hasBottom:a,hasSide:l,topSegments:b});return Ut.claerUVGenerator(),u};class le extends B.BaseObject{constructor(t){super(),this.options=P({depth:1},t)}create(){return nt(this,null,function*(){const{points:t,pointsArr:e,useGroups:s,depth:i,geometry:n,geometryArr:a,material:l,box3:c,split:b,hasTop:o,hasBottom:u,hasSide:y}=this.options,f=Array.isArray(i)?i:[i],w=Array.isArray(c)?c:[c],T=l;let S=n;T||console.log("material is null"),!S&&t?S=Rt({points:t,depth:f[0],box3:w[0],split:b,hasTop:o,hasBottom:u,hasSide:y}):!S&&e?S=C(e.map((_,G)=>{var A,U;return Rt({points:_,depth:(A=f[G])!=null?A:f[0],box3:(U=w[G])!=null?U:w[0],split:b,hasTop:o,hasBottom:u,hasSide:y})}),s!=null?s:0):!S&&a&&a.length>1?S=C(a,s!=null?s:0):!S&&a&&a.length===1&&([S]=a),this.createMesh(S,T)})}addGeometries(t){const e=this.object3d,s=C([e.geometry,...t]);e.geometry=s}setTextureAnisotropic(t,e){t.anisotropy=e||this.pencil.renderer.capabilities.getMaxAnisotropy()}}const ue=r=>{const{topColor:t,sideColor:e,sideMap:s,createCanvasObjectURL:i,split:n,maxAnisotropy:a}=r;return new Promise(l=>{const c=s?document.createElement("img"):{src:"",onload:()=>{},width:128,height:128};c.onload=()=>{const b=n,o=document.createElement("canvas"),u=o.getContext("2d");o.height=c.height/(1-b),o.width=c.width,b&&t&&(u.fillStyle=t,u.fillRect(0,0,c.width,o.height*b)),s&&c instanceof HTMLImageElement?u.drawImage(c,0,o.height*b,c.width,c.height):e&&(u.fillStyle=e,u.fillRect(0,o.height*b,c.width,c.height)),i&&o.toBlob(f=>{console.log(URL.createObjectURL(f))});const y=new x.CanvasTexture(o);l(y)},s?c.src=s:c instanceof HTMLImageElement||c.onload()})};exports.Group=B.Group;exports.MeshLineMaterial=B.MeshLineMaterial;exports.getConicPolygonGeometry=B.PolygonGeometry;exports.getConicPolygonGeometryMetas=B.getMetas;Object.defineProperty(exports,"LineSegmentsGeometry",{enumerable:!0,get:()=>Dt.LineSegmentsGeometry});Object.defineProperty(exports,"Line2Material",{enumerable:!0,get:()=>Ht.LineMaterial});exports.ConicPolygon=oe;exports.ExtrudePolygon=le;exports.Light=ee;exports.Line=re;exports.Line2=se;exports.MeshLineGeometry=Ct;exports.MeshLineRaycast=ne;exports.Node=Kt;exports.Pie=te;exports.getSplitTexture=ue;
|