gl-draw 0.9.0-beta.99 → 0.9.1
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/README.md +0 -255
- package/dist/BaseObject.js +1 -1
- package/dist/BaseObject.module.js +133 -52
- package/dist/MeshLineMaterial.js +146 -0
- package/dist/MeshLineMaterial.module.js +430 -0
- package/dist/colorCorrection.js +1 -1
- package/dist/colorCorrection.module.js +9 -15
- package/dist/core/BaseObject.d.ts +23 -8
- package/dist/core/CSSRenderer/index.d.ts +1 -0
- package/dist/core/Camera.d.ts +1 -3
- package/dist/core/Composer.d.ts +35 -5
- package/dist/core/Controls.d.ts +23 -0
- package/dist/core/Helper.d.ts +16 -0
- package/dist/core/Pencil.d.ts +48 -16
- package/dist/core/Renderer.d.ts +1 -14
- package/dist/core/Scene.d.ts +3 -1
- package/dist/core/TransformControls.d.ts +18 -0
- package/dist/core/pass/CrossFadePass.d.ts +2 -2
- package/dist/disposeMesh.js +1 -1
- package/dist/disposeMesh.module.js +5 -5
- package/dist/effect/index.js +3 -4
- package/dist/effect/index.module.js +20 -22
- package/dist/events.js +1 -1
- package/dist/events.module.js +17 -24
- package/dist/getProjection.js +1 -0
- package/dist/getProjection.module.js +12 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +3 -3
- package/dist/index.module.js +609 -405
- package/dist/index.module2.js +9 -0
- package/dist/index2.js +1 -0
- package/dist/isPlainObject.module.js +2 -4
- package/dist/objects/conicPolygon/createGeometry.d.ts +8 -0
- package/dist/objects/conicPolygon/geometry/index.d.ts +12 -9
- package/dist/objects/conicPolygon/geometry/triangulate.d.ts +2 -1
- package/dist/objects/conicPolygon/index.d.ts +9 -13
- package/dist/objects/extrudePolygon/ExtrudeGeometry.d.ts +4 -4
- package/dist/objects/extrudePolygon/createGeometry.d.ts +1 -12
- package/dist/objects/extrudePolygon/index.d.ts +1 -0
- package/dist/objects/fix.d.ts +5 -2
- package/dist/objects/image/index.d.ts +8 -6
- package/dist/objects/index.d.ts +3 -0
- package/dist/objects/index.js +1 -127
- package/dist/objects/index.module.js +929 -1112
- package/dist/objects/light/index.d.ts +18 -0
- package/dist/objects/line/index.d.ts +13 -8
- package/dist/objects/line/meshLine/MeshLineMaterial.d.ts +4 -2
- package/dist/objects/node/index.d.ts +10 -10
- package/dist/objects/pie/index.d.ts +24 -0
- package/dist/objects/video/index.d.ts +2 -2
- package/dist/plugins/Cache.d.ts +1 -0
- package/dist/plugins/Data.d.ts +1 -0
- package/dist/plugins/Draw.d.ts +24 -7
- package/dist/plugins/Loader/CacheLoader.d.ts +4 -8
- package/dist/plugins/Loader/index.d.ts +31 -7
- package/dist/plugins/Worker/createGeometry.d.ts +3 -0
- package/dist/plugins/Worker/getAttributes/conicLine.d.ts +16 -0
- package/dist/plugins/Worker/getAttributes/conicPolygon.d.ts +24 -0
- package/dist/plugins/Worker/getAttributes/coords2Vector.d.ts +1 -5
- package/dist/plugins/Worker/getAttributes/extrudePolygon.d.ts +16 -29
- package/dist/plugins/Worker/getAttributes/getMessage.d.ts +9 -0
- package/dist/plugins/Worker/getAttributes/line.d.ts +8 -13
- package/dist/plugins/Worker/index.d.ts +32 -42
- package/dist/plugins/index.d.ts +0 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.module.js +556 -419
- package/dist/utils/BufferGeometryUtils.d.ts +3 -3
- package/dist/utils/colorCorrection.d.ts +0 -4
- package/dist/utils/disposeMesh.d.ts +1 -1
- package/dist/utils/getCache.d.ts +2 -2
- package/dist/utils/getProjection.d.ts +10 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.module.js +52 -48
- package/dist/utils/parseVector.d.ts +3 -0
- package/dist/utils/uvGenerator.d.ts +1 -12
- package/dist/uvGenerator.js +1 -1
- package/dist/uvGenerator.module.js +67 -73
- package/package.json +18 -25
- package/dist/core/Control.d.ts +0 -33
- package/dist/geojson/china.json +0 -1
- package/dist/geojson/countries.json +0 -27483
- package/dist/plugins/CanvasStream.d.ts +0 -15
- package/dist/worker/geo.js +0 -3555
package/README.md
CHANGED
|
@@ -2,258 +2,3 @@ gl-draw 基于 Three.js 的可视化开发框架
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/gl-draw)
|
|
4
4
|
[](https://www.npmjs.com/package/gl-draw)
|
|
5
|
-
|
|
6
|
-
gl-draw 旨在简化基于 Three.js 的可视化开发。 用户可以通过组合现有 Object 或利用 gl-draw 的可扩展架构来满足自定义需求,从而以快速获得令人印象深刻的视觉效果。
|
|
7
|
-
|
|
8
|
-
<!-- Documentation -->
|
|
9
|
-
|
|
10
|
-
## 快速开始
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
yarn add gl-draw
|
|
14
|
-
# or npm install gl-draw
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
依赖
|
|
18
|
-
|
|
19
|
-
```javascript
|
|
20
|
-
{
|
|
21
|
-
"three": ">=0.136.0"
|
|
22
|
-
}
|
|
23
|
-
```
|
|
24
|
-
使用
|
|
25
|
-
|
|
26
|
-
核心类:
|
|
27
|
-
|
|
28
|
-
- Pencil: 初始化场景,控制整个场景的渲染、更新和废除
|
|
29
|
-
- DrawController: 用于场景中元素的绘制、获取和删除
|
|
30
|
-
- BaseObject: 元素基类,封装了一些生命周期和通用方法
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```javascript
|
|
35
|
-
import {Node, Video, Image} from 'gl-draw/dist/objects'
|
|
36
|
-
class MyObject extends BaseObject {
|
|
37
|
-
create() {
|
|
38
|
-
const geo = new THREE.PlaneBufferGeometry(100, 100)
|
|
39
|
-
const mat = new THREE.MeshBasicMaterial({
|
|
40
|
-
color: new THREE.Color('#00243B'),
|
|
41
|
-
})
|
|
42
|
-
this.createMesh(geo, mat)
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
const drawController = new DrawController({
|
|
46
|
-
Node,
|
|
47
|
-
Video,
|
|
48
|
-
Image,
|
|
49
|
-
obj: MyObject,
|
|
50
|
-
});
|
|
51
|
-
const pencil = new Pencil(
|
|
52
|
-
{
|
|
53
|
-
container: document.querySelector('#container'),
|
|
54
|
-
control: true,
|
|
55
|
-
axesHelper: true,
|
|
56
|
-
stats: true,
|
|
57
|
-
}
|
|
58
|
-
);
|
|
59
|
-
pencil.use(drawController)
|
|
60
|
-
await drawController.draw('obj')
|
|
61
|
-
await Promise.all(drawController.objectsPromise);
|
|
62
|
-
pencil.start();
|
|
63
|
-
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## 参数&API
|
|
67
|
-
|
|
68
|
-
### Pencil
|
|
69
|
-
|
|
70
|
-
```js
|
|
71
|
-
// 参数
|
|
72
|
-
interface Options {
|
|
73
|
-
// 容器元素
|
|
74
|
-
container: HTMLElement;
|
|
75
|
-
// 是否为开发模式
|
|
76
|
-
isdev?: boolean;
|
|
77
|
-
// 是否创建stats
|
|
78
|
-
stats?: boolean;
|
|
79
|
-
// 是否创建gui
|
|
80
|
-
gui?: boolean;
|
|
81
|
-
// 是否显示坐标轴
|
|
82
|
-
axesHelper?: boolean;
|
|
83
|
-
// 是否开启控制器
|
|
84
|
-
control?: boolean;
|
|
85
|
-
// 如果为true则使用MapControls否则使用OrbitControls
|
|
86
|
-
mapControl?: boolean;
|
|
87
|
-
// WebGLRenderer配置,与three.js中配置相同
|
|
88
|
-
renderer?: {
|
|
89
|
-
antialias?: false | 'fxaa' | 'smaa' | 'ssaa' | 'msaa';
|
|
90
|
-
} & Omit<Partial<RendererParams>, 'antialias'>;
|
|
91
|
-
// MSAA抗锯齿采样数,默认为8
|
|
92
|
-
multisampling?: number;
|
|
93
|
-
// 按需渲染,开启后只有当相机移动时才重新渲染
|
|
94
|
-
staticRender?: boolean;
|
|
95
|
-
// 配置背景
|
|
96
|
-
scene?: {
|
|
97
|
-
background?: THREE.Scene['background'];
|
|
98
|
-
}
|
|
99
|
-
// 摄像机机相关配置
|
|
100
|
-
camera?: Partial<{
|
|
101
|
-
fov: number;
|
|
102
|
-
near: number;
|
|
103
|
-
far: number;
|
|
104
|
-
}> | THREE.PerspectiveCamera;
|
|
105
|
-
// 是否开启辉光后期处理
|
|
106
|
-
bloom?: boolean;
|
|
107
|
-
// 辉光参数
|
|
108
|
-
bloomParams?: Partial<{
|
|
109
|
-
threshold: number;
|
|
110
|
-
strength: number;
|
|
111
|
-
radius: number;
|
|
112
|
-
}>;
|
|
113
|
-
// 是否开启描边后期处理
|
|
114
|
-
outline?: boolean;
|
|
115
|
-
// 描边参数,具体可查看https://threejs.org/examples/?q=outline#webgl_postprocessing_outline
|
|
116
|
-
outlineParams?: Partial<OutlineParams>;
|
|
117
|
-
// 是否开启ssr后期处理
|
|
118
|
-
ssr?: boolean;
|
|
119
|
-
// ssr参数,具体可查看https://threejs.org/examples/?q=ssr#webgl_postprocessing_ssr
|
|
120
|
-
ssrParams?: Partial<SSRParams>;
|
|
121
|
-
// 是否加载css2DRenderer
|
|
122
|
-
css2DRenderer?: boolean;
|
|
123
|
-
// 配置css2DRenderer容器z-index
|
|
124
|
-
css2DRendererParams?: Partial<{
|
|
125
|
-
zIndex: string;
|
|
126
|
-
}>;
|
|
127
|
-
// 是否加载css3DRenderer
|
|
128
|
-
css3DRenderer?: boolean;
|
|
129
|
-
// 配置css3DRenderer容器z-index
|
|
130
|
-
css3DRendererParams?: Partial<{
|
|
131
|
-
zIndex: string;
|
|
132
|
-
}>;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// API
|
|
136
|
-
// 获取renderer
|
|
137
|
-
(getter) Pencil.renderer: THREE.WebGLRenderer | undefined
|
|
138
|
-
|
|
139
|
-
// 获取控制器
|
|
140
|
-
(getter) Pencil.control: OrbitControls | undefined
|
|
141
|
-
|
|
142
|
-
// 获取摄像机
|
|
143
|
-
(getter) Pencil.camera: THREE.PerspectiveCamera | undefined
|
|
144
|
-
|
|
145
|
-
// 获取Scene
|
|
146
|
-
(getter) Pencil.scene: THREE.Scene | undefined
|
|
147
|
-
|
|
148
|
-
// 事件处理
|
|
149
|
-
(property) Pencil.event: EventEmitter
|
|
150
|
-
|
|
151
|
-
// 射线交互
|
|
152
|
-
(method) Pencil.pick(event: MouseEvent, objects?: THREE.Object3D[], recursive?: boolean): {
|
|
153
|
-
object: THREE.Object3D<THREE.Event>;
|
|
154
|
-
intersects: THREE.Intersection<THREE.Object3D<THREE.Event>>[];
|
|
155
|
-
} | undefined
|
|
156
|
-
|
|
157
|
-
// 开启渲染循环
|
|
158
|
-
(method) Pencil.start(): void
|
|
159
|
-
|
|
160
|
-
// 废除整个场景
|
|
161
|
-
(method) Pencil.dispose(): void
|
|
162
|
-
```
|
|
163
|
-
### DrawController
|
|
164
|
-
```js
|
|
165
|
-
// 参数
|
|
166
|
-
{ [key: string]: new (...args: any[]) => IBaseObject; }
|
|
167
|
-
|
|
168
|
-
// API
|
|
169
|
-
// 所有创建元素的Promise
|
|
170
|
-
(getter) Draw.objectsPromise: Promise<any>[]
|
|
171
|
-
|
|
172
|
-
// 根据名称和key获取元素
|
|
173
|
-
(method) Draw.getObject<Y extends Extract<keyof T, string>>(nameOrigin: Y, options?: {
|
|
174
|
-
key: string;
|
|
175
|
-
} | undefined): InstanceType<T[Y]>
|
|
176
|
-
|
|
177
|
-
// 根据名称和key获取所有元素
|
|
178
|
-
(method) Draw.getAllObject<Y extends Extract<keyof T, string>>(nameOrigin: Y, options?: {
|
|
179
|
-
key: string;
|
|
180
|
-
} | undefined): InstanceType<T[Y]>[]
|
|
181
|
-
|
|
182
|
-
// 绘制元素
|
|
183
|
-
(method) Draw.draw(nameOrigin: Y, options?: ConstructorParameters<T[Y]>[0] & {
|
|
184
|
-
key?: string;
|
|
185
|
-
target?: U;
|
|
186
|
-
}, target?: U): Promise<...>
|
|
187
|
-
|
|
188
|
-
// 删除元素
|
|
189
|
-
(method) Dra.erase(...args: (KeyOf<T> | `${KeyOf<T>}#${string}` | InstanceType<T[keyof T]>)[]): void
|
|
190
|
-
```
|
|
191
|
-
### BaseObject
|
|
192
|
-
```js
|
|
193
|
-
// API
|
|
194
|
-
// 该元素唯一key
|
|
195
|
-
(property) BaseObject.key: string
|
|
196
|
-
|
|
197
|
-
// 该元素对应Pencil
|
|
198
|
-
(property) BaseObject.pencil: Pencil
|
|
199
|
-
|
|
200
|
-
// 内部保存最终加载到场景中的three对象
|
|
201
|
-
(property) BaseObject.object3d: THREE.Object3D<THREE.Event>
|
|
202
|
-
|
|
203
|
-
// 该元素Promise,在创建完成后会resolve
|
|
204
|
-
(property) BaseObject.pm: {
|
|
205
|
-
promise: Promise<any>;
|
|
206
|
-
resolve: (value?: any) => void;
|
|
207
|
-
reject: (value?: any) => void;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// 获取父元素
|
|
211
|
-
(getter) BaseObject.parent: IBaseObject | THREE.Scene
|
|
212
|
-
|
|
213
|
-
// 获取子元素
|
|
214
|
-
(getter) BaseObject.children: IBaseObject[]
|
|
215
|
-
|
|
216
|
-
// create钩子在创建时调用
|
|
217
|
-
(method) BaseObject.create(): void
|
|
218
|
-
|
|
219
|
-
// render钩子在创建完成加入到场景后调用
|
|
220
|
-
(method) BaseObject.render(): void
|
|
221
|
-
|
|
222
|
-
// update钩子在每一帧渲染时调用
|
|
223
|
-
(method) BaseObject.update(delta: number, elapsed: number): void
|
|
224
|
-
|
|
225
|
-
// 显示元素
|
|
226
|
-
(method) BaseObject.show(): this
|
|
227
|
-
|
|
228
|
-
// 隐藏元素
|
|
229
|
-
(method) BaseObject.hide(): this
|
|
230
|
-
|
|
231
|
-
// 获取该元素包围盒
|
|
232
|
-
(method) BaseObject.getSize(): {
|
|
233
|
-
min: THREE.Vector3;
|
|
234
|
-
max: THREE.Vector3;
|
|
235
|
-
size: THREE.Vector3;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
// 废除元素
|
|
239
|
-
(method) BaseObject.dispose(): void
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
## 提示
|
|
243
|
-
### @tweenjs/tween.js 使用需要注册
|
|
244
|
-
```js
|
|
245
|
-
const pencil = new Pencil({
|
|
246
|
-
...
|
|
247
|
-
})
|
|
248
|
-
pencil.use({
|
|
249
|
-
install: () => {},
|
|
250
|
-
update: () => {
|
|
251
|
-
TWEEN.update();
|
|
252
|
-
},
|
|
253
|
-
dispose: () => {
|
|
254
|
-
TWEEN.removeAll();
|
|
255
|
-
},
|
|
256
|
-
})
|
|
257
|
-
```
|
|
258
|
-
|
|
259
|
-
|
package/dist/BaseObject.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const d=require("three"),l=require("esus-lite"),u=require("three/examples/jsm/renderers/CSS2DRenderer"),n=require("three/examples/jsm/renderers/CSS3DRenderer"),o=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");function b(i){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const t in i)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(i,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>i[t]})}}return e.default=i,Object.freeze(e)}const s=b(d),h=(i,e,t)=>{e&&(o.disposeMesh(e,t),e.children.forEach(r=>{i.has(r)||h(i,r,t)}))};class j{constructor(){this.objectType="BaseObject",this.userData={},this.prefab=!1,this.pm=l.makePromiseCreator(),this.materialList={},this.useMaterialType="origin"}get parent(){const e=this.object3d.parent;return e?this.drawController.objMap.get(e)||this.pencil.scene:null}get children(){return this.object3d.children.map(e=>this.drawController.objMap.get(e)).filter(e=>!!e)}get position(){var e;return(e=this.object3d)==null?void 0:e.position}get rotation(){var e;return(e=this.object3d)==null?void 0:e.rotation}get scale(){var e;return(e=this.object3d)==null?void 0:e.scale}get add(){var e;return(e=this.object3d)==null?void 0:e.add.bind(this.object3d)}get remove(){var e;return(e=this.object3d)==null?void 0:e.remove.bind(this.object3d)}get visible(){return this.object3d?this.object3d.visible:!1}create(){}render(){}update(e,t){}resize(e,t){}show(){return this.object3d&&(this.object3d.visible=!0),this}hide(){return this.object3d&&(this.object3d.visible=!1),this}createMesh(...e){return this.object3d=new s.Mesh(...e),this}createGroup(){return this.object3d=new s.Group,this}createPoints(...e){return this.object3d=new s.Points(...e),this}createCSS2DObject(e){return this.object3d=new u.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new n.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new n.CSS3DSprite(e),this}createSprite(e){return this.object3d=new s.Sprite(e),this}attach(...e){return[...e].forEach(t=>{this.object3d.attach(t.object3d),this.drawController!==t.drawController&&(t.drawController.objects.delete(t.key),this.drawController.objects.set(t.key,t))}),this}getSize(){const e=new s.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new s.Vector3)}}traverse(e){e(this),this.children.forEach(t=>{t.traverse(e)})}clone(){return this.instantiate()}instantiate(e){return this.drawController.instantiate(this,{create:t=>{this.object3d&&(t.object3d=this.object3d.clone(!0)),typeof e=="number"&&(t.object3d=new s.InstancedMesh(t.object3d.geometry,t.object3d.material,e),t.object3d.instanceMatrix.setUsage(s.DynamicDrawUsage))}})}setInstancedMatrix(e){this.object3d instanceof s.InstancedMesh&&(Object.keys(e).forEach(t=>{this.object3d.setMatrixAt(Number(t),e[t])}),this.object3d.instanceMatrix.needsUpdate=!0,this.object3d.computeBoundingSphere())}erase(){this.drawController.erase(this)}cloneMaterial(){const e=this.object3d;if(!e||!e.material)return;const t=e.material;if(Array.isArray(t))return t.map(r=>{const a=r.userData;r.userData={};const c=r.clone();return r.userData=a,c});{const r=t.userData;t.userData={};const a=t.clone();return t.userData=r,a}}setMaterialList(e,t,r=!0){const a=this.object3d;if(!a||!a.material)return;if(this.materialList.origin||(this.materialList.origin=a.material),!r&&this.materialList[e])return this.materialList[e];const c=t==="clone"?this.cloneMaterial():t;return this.materialList[e]=c,c}useMaterial(e){const t=this.object3d;!t||!t.material||this.useMaterialType===e||!this.materialList[e]||(this.useMaterialType=e,t.material=this.materialList[e])}setTop(e){this.object3d&&(this.object3d.renderOrder=e)}dispose(e=!0){h(this.drawController.objMap,this.object3d,e),e&&Object.keys(this.materialList).forEach(t=>{t!=="origin"&&o.disposeMesh({material:this.materialList[t]})})}}exports.BaseObject=j;
|
|
@@ -1,93 +1,174 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as i from "three";
|
|
2
2
|
import { makePromiseCreator as h } from "esus-lite";
|
|
3
|
-
import { CSS2DObject as
|
|
4
|
-
import { CSS3DObject as
|
|
5
|
-
import { d as
|
|
3
|
+
import { CSS2DObject as d } from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
4
|
+
import { CSS3DObject as l, CSS3DSprite as b } from "three/examples/jsm/renderers/CSS3DRenderer";
|
|
5
|
+
import { d as c } from "./disposeMesh.module.js";
|
|
6
6
|
import "idb-keyval";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import "d3-geo";
|
|
8
|
+
const n = (o, t, e) => {
|
|
9
|
+
t && (c(t, e), t.children.forEach((r) => {
|
|
10
|
+
o.has(r) || n(o, r, e);
|
|
10
11
|
}));
|
|
11
12
|
};
|
|
12
|
-
class
|
|
13
|
+
class g {
|
|
13
14
|
constructor() {
|
|
14
|
-
this.
|
|
15
|
+
this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.pm = h(), this.materialList = {}, this.useMaterialType = "origin";
|
|
15
16
|
}
|
|
16
17
|
get parent() {
|
|
17
|
-
const
|
|
18
|
-
return
|
|
18
|
+
const t = this.object3d.parent;
|
|
19
|
+
return t ? this.drawController.objMap.get(t) || this.pencil.scene : null;
|
|
19
20
|
}
|
|
20
21
|
get children() {
|
|
21
|
-
return this.object3d.children.map((
|
|
22
|
+
return this.object3d.children.map((t) => this.drawController.objMap.get(t)).filter((t) => !!t);
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
get position() {
|
|
25
|
+
var t;
|
|
26
|
+
return (t = this.object3d) == null ? void 0 : t.position;
|
|
27
|
+
}
|
|
28
|
+
get rotation() {
|
|
29
|
+
var t;
|
|
30
|
+
return (t = this.object3d) == null ? void 0 : t.rotation;
|
|
31
|
+
}
|
|
32
|
+
get scale() {
|
|
33
|
+
var t;
|
|
34
|
+
return (t = this.object3d) == null ? void 0 : t.scale;
|
|
35
|
+
}
|
|
36
|
+
get add() {
|
|
37
|
+
var t;
|
|
38
|
+
return (t = this.object3d) == null ? void 0 : t.add.bind(this.object3d);
|
|
39
|
+
}
|
|
40
|
+
get remove() {
|
|
41
|
+
var t;
|
|
42
|
+
return (t = this.object3d) == null ? void 0 : t.remove.bind(this.object3d);
|
|
43
|
+
}
|
|
44
|
+
get visible() {
|
|
45
|
+
return this.object3d ? this.object3d.visible : !1;
|
|
24
46
|
}
|
|
25
47
|
create() {
|
|
26
48
|
}
|
|
27
49
|
render() {
|
|
28
50
|
}
|
|
29
|
-
update(
|
|
51
|
+
update(t, e) {
|
|
30
52
|
}
|
|
31
|
-
resize(
|
|
53
|
+
resize(t, e) {
|
|
32
54
|
}
|
|
33
55
|
show() {
|
|
34
|
-
return this.object3d && (this.object3d.visible = !0), this
|
|
56
|
+
return this.object3d && (this.object3d.visible = !0), this;
|
|
35
57
|
}
|
|
36
58
|
hide() {
|
|
37
|
-
return this.object3d && (this.object3d.visible = !1), this
|
|
38
|
-
}
|
|
39
|
-
isVisible() {
|
|
40
|
-
return this.visible;
|
|
59
|
+
return this.object3d && (this.object3d.visible = !1), this;
|
|
41
60
|
}
|
|
42
|
-
createMesh(...
|
|
43
|
-
return this.object3d = new
|
|
61
|
+
createMesh(...t) {
|
|
62
|
+
return this.object3d = new i.Mesh(...t), this;
|
|
44
63
|
}
|
|
45
64
|
createGroup() {
|
|
46
|
-
return this.object3d = new
|
|
65
|
+
return this.object3d = new i.Group(), this;
|
|
47
66
|
}
|
|
48
|
-
createPoints(...
|
|
49
|
-
return this.object3d = new
|
|
67
|
+
createPoints(...t) {
|
|
68
|
+
return this.object3d = new i.Points(...t), this;
|
|
50
69
|
}
|
|
51
|
-
createCSS2DObject(
|
|
52
|
-
return this.object3d = new
|
|
70
|
+
createCSS2DObject(t) {
|
|
71
|
+
return this.object3d = new d(t), this;
|
|
53
72
|
}
|
|
54
|
-
createCSS3DObject(
|
|
55
|
-
return this.object3d = new
|
|
73
|
+
createCSS3DObject(t) {
|
|
74
|
+
return this.object3d = new l(t), this;
|
|
56
75
|
}
|
|
57
|
-
createCSS3DSprite(
|
|
58
|
-
return this.object3d = new
|
|
76
|
+
createCSS3DSprite(t) {
|
|
77
|
+
return this.object3d = new b(t), this;
|
|
59
78
|
}
|
|
60
|
-
createSprite(
|
|
61
|
-
return this.object3d = new
|
|
79
|
+
createSprite(t) {
|
|
80
|
+
return this.object3d = new i.Sprite(t), this;
|
|
62
81
|
}
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
remove(...e) {
|
|
67
|
-
return this.object3d.remove(...e), this;
|
|
68
|
-
}
|
|
69
|
-
attach(...e) {
|
|
70
|
-
return [...e].forEach((i) => {
|
|
71
|
-
this.object3d.attach(i.object3d);
|
|
82
|
+
attach(...t) {
|
|
83
|
+
return [...t].forEach((e) => {
|
|
84
|
+
this.object3d.attach(e.object3d), this.drawController !== e.drawController && (e.drawController.objects.delete(e.key), this.drawController.objects.set(e.key, e));
|
|
72
85
|
}), this;
|
|
73
86
|
}
|
|
74
87
|
getSize() {
|
|
75
|
-
const
|
|
88
|
+
const t = new i.Box3().setFromObject(this.object3d);
|
|
76
89
|
return {
|
|
77
|
-
min:
|
|
78
|
-
max:
|
|
79
|
-
size:
|
|
90
|
+
min: t.min,
|
|
91
|
+
max: t.max,
|
|
92
|
+
size: t.getSize(new i.Vector3())
|
|
80
93
|
};
|
|
81
94
|
}
|
|
82
|
-
traverse(
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
traverse(t) {
|
|
96
|
+
t(this), this.children.forEach((e) => {
|
|
97
|
+
e.traverse(t);
|
|
85
98
|
});
|
|
86
99
|
}
|
|
87
|
-
|
|
88
|
-
|
|
100
|
+
clone() {
|
|
101
|
+
return this.instantiate();
|
|
102
|
+
}
|
|
103
|
+
instantiate(t) {
|
|
104
|
+
return this.drawController.instantiate(this, {
|
|
105
|
+
create: (e) => {
|
|
106
|
+
this.object3d && (e.object3d = this.object3d.clone(!0)), typeof t == "number" && (e.object3d = new i.InstancedMesh(
|
|
107
|
+
e.object3d.geometry,
|
|
108
|
+
e.object3d.material,
|
|
109
|
+
t
|
|
110
|
+
), e.object3d.instanceMatrix.setUsage(i.DynamicDrawUsage));
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
setInstancedMatrix(t) {
|
|
115
|
+
this.object3d instanceof i.InstancedMesh && (Object.keys(t).forEach((e) => {
|
|
116
|
+
this.object3d.setMatrixAt(
|
|
117
|
+
Number(e),
|
|
118
|
+
t[e]
|
|
119
|
+
);
|
|
120
|
+
}), this.object3d.instanceMatrix.needsUpdate = !0, this.object3d.computeBoundingSphere());
|
|
121
|
+
}
|
|
122
|
+
erase() {
|
|
123
|
+
this.drawController.erase(this);
|
|
124
|
+
}
|
|
125
|
+
cloneMaterial() {
|
|
126
|
+
const t = this.object3d;
|
|
127
|
+
if (!t || !t.material)
|
|
128
|
+
return;
|
|
129
|
+
const e = t.material;
|
|
130
|
+
if (Array.isArray(e))
|
|
131
|
+
return e.map((r) => {
|
|
132
|
+
const s = r.userData;
|
|
133
|
+
r.userData = {};
|
|
134
|
+
const a = r.clone();
|
|
135
|
+
return r.userData = s, a;
|
|
136
|
+
});
|
|
137
|
+
{
|
|
138
|
+
const r = e.userData;
|
|
139
|
+
e.userData = {};
|
|
140
|
+
const s = e.clone();
|
|
141
|
+
return e.userData = r, s;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
setMaterialList(t, e, r = !0) {
|
|
145
|
+
const s = this.object3d;
|
|
146
|
+
if (!s || !s.material)
|
|
147
|
+
return;
|
|
148
|
+
if (this.materialList.origin || (this.materialList.origin = s.material), !r && this.materialList[t])
|
|
149
|
+
return this.materialList[t];
|
|
150
|
+
const a = e === "clone" ? this.cloneMaterial() : e;
|
|
151
|
+
return this.materialList[t] = a, a;
|
|
152
|
+
}
|
|
153
|
+
useMaterial(t) {
|
|
154
|
+
const e = this.object3d;
|
|
155
|
+
!e || !e.material || this.useMaterialType === t || !this.materialList[t] || (this.useMaterialType = t, e.material = this.materialList[t]);
|
|
156
|
+
}
|
|
157
|
+
setTop(t) {
|
|
158
|
+
this.object3d && (this.object3d.renderOrder = t);
|
|
159
|
+
}
|
|
160
|
+
dispose(t = !0) {
|
|
161
|
+
n(
|
|
162
|
+
this.drawController.objMap,
|
|
163
|
+
this.object3d,
|
|
164
|
+
t
|
|
165
|
+
), t && Object.keys(this.materialList).forEach((e) => {
|
|
166
|
+
e !== "origin" && c({
|
|
167
|
+
material: this.materialList[e]
|
|
168
|
+
});
|
|
169
|
+
});
|
|
89
170
|
}
|
|
90
171
|
}
|
|
91
172
|
export {
|
|
92
|
-
|
|
173
|
+
g as B
|
|
93
174
|
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";var h=Object.defineProperty,v=Object.defineProperties;var m=Object.getOwnPropertyDescriptors;var n=Object.getOwnPropertySymbols;var p=Object.prototype.hasOwnProperty,c=Object.prototype.propertyIsEnumerable;var o=(i,t,e)=>t in i?h(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,u=(i,t)=>{for(var e in t||(t={}))p.call(t,e)&&o(i,e,t[e]);if(n)for(var e of n(t))c.call(t,e)&&o(i,e,t[e]);return i},l=(i,t)=>v(i,m(t));const d=require("three");function g(i){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(i){for(const e in i)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(i,e);Object.defineProperty(t,e,s.get?s:{enumerable:!0,get:()=>i[e]})}}return t.default=i,Object.freeze(t)}const r=g(d),f=["encodings_fragment","colorspace_fragment"],y=`
|
|
2
|
+
#include <common>
|
|
3
|
+
#include <logdepthbuf_pars_vertex>
|
|
4
|
+
#include <fog_pars_vertex>
|
|
5
|
+
|
|
6
|
+
attribute vec3 previous;
|
|
7
|
+
attribute vec3 next;
|
|
8
|
+
attribute float side;
|
|
9
|
+
attribute float width;
|
|
10
|
+
attribute float counters;
|
|
11
|
+
|
|
12
|
+
uniform vec2 resolution;
|
|
13
|
+
uniform float lineWidth;
|
|
14
|
+
uniform vec3 color;
|
|
15
|
+
uniform float opacity;
|
|
16
|
+
uniform float sizeAttenuation;
|
|
17
|
+
uniform vec2 offset;
|
|
18
|
+
|
|
19
|
+
uniform float time;
|
|
20
|
+
uniform vec3 lightColor;
|
|
21
|
+
uniform vec2 uCenter;
|
|
22
|
+
uniform float size;
|
|
23
|
+
uniform float speed;
|
|
24
|
+
uniform float lightWidth;
|
|
25
|
+
uniform float lineLightAnimation;
|
|
26
|
+
|
|
27
|
+
varying vec2 vUV;
|
|
28
|
+
varying vec4 vColor;
|
|
29
|
+
varying float vCounters;
|
|
30
|
+
varying vec2 vHighPrecisionZW;
|
|
31
|
+
|
|
32
|
+
vec2 fix(vec4 i, float aspect) {
|
|
33
|
+
vec2 res = i.xy / i.w;
|
|
34
|
+
res.x *= aspect;
|
|
35
|
+
vCounters = counters;
|
|
36
|
+
return res;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void main() {
|
|
40
|
+
float aspect = resolution.x / resolution.y;
|
|
41
|
+
if (lineLightAnimation == 1.0) {
|
|
42
|
+
vec2 vWorld=position.xy;
|
|
43
|
+
float r_time=mod(time/(speed*size),2.);
|
|
44
|
+
float l=distance(vWorld, uCenter)/size;
|
|
45
|
+
float r_opacity=smoothstep(r_time-lightWidth*2.,r_time-lightWidth,l)-smoothstep(r_time-lightWidth,r_time,l);
|
|
46
|
+
vColor=vec4(mix(color,lightColor,r_opacity),opacity);
|
|
47
|
+
} else {
|
|
48
|
+
vColor=vec4(color,opacity);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
vUV=uv+offset;
|
|
52
|
+
|
|
53
|
+
mat4 m = projectionMatrix * modelViewMatrix;
|
|
54
|
+
vec4 finalPosition = m * vec4(position, 1.0);
|
|
55
|
+
vec4 prevPos = m * vec4(previous, 1.0);
|
|
56
|
+
vec4 nextPos = m * vec4(next, 1.0);
|
|
57
|
+
|
|
58
|
+
vec2 currentP = fix(finalPosition, aspect);
|
|
59
|
+
vec2 prevP = fix(prevPos, aspect);
|
|
60
|
+
vec2 nextP = fix(nextPos, aspect);
|
|
61
|
+
|
|
62
|
+
float w = lineWidth * width;
|
|
63
|
+
|
|
64
|
+
vec2 dir;
|
|
65
|
+
if (nextP == currentP) dir = normalize(currentP - prevP);
|
|
66
|
+
else if (prevP == currentP) dir = normalize(nextP - currentP);
|
|
67
|
+
else {
|
|
68
|
+
vec2 dir1 = normalize(currentP - prevP);
|
|
69
|
+
vec2 dir2 = normalize(nextP - currentP);
|
|
70
|
+
dir = normalize(dir1 + dir2);
|
|
71
|
+
|
|
72
|
+
vec2 perp = vec2(-dir1.y, dir1.x);
|
|
73
|
+
vec2 miter = vec2(-dir.y, dir.x);
|
|
74
|
+
//w = clamp(w / dot(miter, perp), 0., 4. * lineWidth * width);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//vec2 normal = (cross(vec3(dir, 0.), vec3(0., 0., 1.))).xy;
|
|
78
|
+
vec4 normal = vec4(-dir.y, dir.x, 0., 1.);
|
|
79
|
+
normal.xy *= .5 * w;
|
|
80
|
+
//normal *= projectionMatrix;
|
|
81
|
+
if (sizeAttenuation == 0.) {
|
|
82
|
+
normal.xy *= finalPosition.w;
|
|
83
|
+
normal.xy /= (vec4(resolution, 0., 1.) * projectionMatrix).xy;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
finalPosition.xy += normal.xy * side;
|
|
87
|
+
gl_Position = finalPosition;
|
|
88
|
+
#include <logdepthbuf_vertex>
|
|
89
|
+
#include <fog_vertex>
|
|
90
|
+
vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
|
|
91
|
+
vHighPrecisionZW = finalPosition.zw;
|
|
92
|
+
#include <fog_vertex>
|
|
93
|
+
}
|
|
94
|
+
`,b=`
|
|
95
|
+
#include <packing>
|
|
96
|
+
#include <fog_pars_fragment>
|
|
97
|
+
#include <logdepthbuf_pars_fragment>
|
|
98
|
+
|
|
99
|
+
uniform sampler2D map;
|
|
100
|
+
uniform sampler2D alphaMap;
|
|
101
|
+
uniform float useMap;
|
|
102
|
+
uniform float useAlphaMap;
|
|
103
|
+
uniform float useDash;
|
|
104
|
+
uniform float dashArray;
|
|
105
|
+
uniform float dashOffset;
|
|
106
|
+
uniform float dashRatio;
|
|
107
|
+
uniform float visibility;
|
|
108
|
+
uniform float alphaTest;
|
|
109
|
+
uniform vec2 repeat;
|
|
110
|
+
uniform float useDepth;
|
|
111
|
+
uniform float offsetLoop;
|
|
112
|
+
|
|
113
|
+
varying vec2 vUV;
|
|
114
|
+
varying vec4 vColor;
|
|
115
|
+
varying float vCounters;
|
|
116
|
+
varying vec2 vHighPrecisionZW;
|
|
117
|
+
|
|
118
|
+
void main() {
|
|
119
|
+
#include <logdepthbuf_fragment>
|
|
120
|
+
vec4 c = vColor;
|
|
121
|
+
if (useMap == 1.) c *= texture2D(map, vUV * repeat);
|
|
122
|
+
if (useAlphaMap == 1.) c.a *= texture2D(alphaMap, vUV * repeat).a;
|
|
123
|
+
if(offsetLoop!=1.0){
|
|
124
|
+
if(vUV.x>1.0 || vUV.x<0.0){
|
|
125
|
+
c.a = 0.0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (c.a < alphaTest) discard;
|
|
130
|
+
if (useDash == 1.) {
|
|
131
|
+
c.a *= ceil(mod(vCounters + dashOffset, dashArray) - (dashArray * dashRatio));
|
|
132
|
+
}
|
|
133
|
+
if (useDepth == 1.) {
|
|
134
|
+
float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
|
|
135
|
+
gl_FragColor = packDepthToRGBA( fragCoordZ );
|
|
136
|
+
}else{
|
|
137
|
+
gl_FragColor = c;
|
|
138
|
+
gl_FragColor.a *= step(vCounters, visibility);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
#include <fog_fragment>
|
|
143
|
+
#include <tonemapping_fragment>
|
|
144
|
+
#include <${+r.REVISION<154?f[0]:f[1]}>
|
|
145
|
+
}
|
|
146
|
+
`,a=[];class x extends r.ShaderMaterial{constructor(t){super({uniforms:l(u({},r.UniformsLib.fog),{lineWidth:{value:1},map:{value:null},useMap:{value:0},alphaMap:{value:null},useAlphaMap:{value:0},color:{value:new r.Color(16777215)},opacity:{value:1},resolution:{value:new r.Vector2(1,1)},sizeAttenuation:{value:1},dashArray:{value:0},dashOffset:{value:0},dashRatio:{value:.5},useDash:{value:0},useDepth:{value:0},visibility:{value:1},alphaTest:{value:0},repeat:{value:new r.Vector2(1,1)},offset:{value:new r.Vector2(0,0)},offsetLoop:{value:1},lineLightAnimation:{value:0},time:{value:0},size:{value:300},speed:{value:.3},lightWidth:{value:.1},uCenter:{value:new r.Vector2(0,0)},lightColor:{value:new r.Color(16777215)}}),vertexShader:y,fragmentShader:b}),a.push(this),this.type="MeshLineMaterial",Object.defineProperties(this,{lineWidth:{enumerable:!0,get(){return this.uniforms.lineWidth.value},set(e){this.uniforms.lineWidth.value=e}},map:{enumerable:!0,get(){return this.uniforms.map.value},set(e){this.uniforms.map.value=e}},useMap:{enumerable:!0,get(){return this.uniforms.useMap.value},set(e){this.uniforms.useMap.value=e}},alphaMap:{enumerable:!0,get(){return this.uniforms.alphaMap.value},set(e){this.uniforms.alphaMap.value=e}},useAlphaMap:{enumerable:!0,get(){return this.uniforms.useAlphaMap.value},set(e){this.uniforms.useAlphaMap.value=e}},color:{enumerable:!0,get(){return this.uniforms.color.value},set(e){this.uniforms.color.value=e}},opacity:{enumerable:!0,get(){return this.uniforms.opacity.value},set(e){this.uniforms.opacity.value=e}},resolution:{enumerable:!0,get(){return this.uniforms.resolution.value},set(e){this.uniforms.resolution.value.copy(e)}},sizeAttenuation:{enumerable:!0,get(){return this.uniforms.sizeAttenuation.value},set(e){this.uniforms.sizeAttenuation.value=e}},dashArray:{enumerable:!0,get(){return this.uniforms.dashArray.value},set(e){this.uniforms.dashArray.value=e,this.useDash=e!==0?1:0}},dashOffset:{enumerable:!0,get(){return this.uniforms.dashOffset.value},set(e){this.uniforms.dashOffset.value=e}},dashRatio:{enumerable:!0,get(){return this.uniforms.dashRatio.value},set(e){this.uniforms.dashRatio.value=e}},useDash:{enumerable:!0,get(){return this.uniforms.useDash.value},set(e){this.uniforms.useDash.value=e}},useDepth:{enumerable:!0,get(){return this.uniforms.useDepth.value},set(e){this.uniforms.useDepth.value=e}},visibility:{enumerable:!0,get(){return this.uniforms.visibility.value},set(e){this.uniforms.visibility.value=e}},alphaTest:{enumerable:!0,get(){return this.uniforms.alphaTest.value},set(e){this.uniforms.alphaTest.value=e}},repeat:{enumerable:!0,get(){return this.uniforms.repeat.value},set(e){this.uniforms.repeat.value.copy(e)}},lineLightAnimation:{enumerable:!0,get:function(){return this.uniforms.lineLightAnimation.value},set:function(e){this.uniforms.lineLightAnimation.value=e}},time:{enumerable:!0,get:function(){return this.uniforms.time.value},set:function(e){this.uniforms.time.value=e}},size:{enumerable:!0,get:function(){return this.uniforms.size.value},set:function(e){this.uniforms.size.value=e}},speed:{enumerable:!0,get:function(){return this.uniforms.speed.value},set:function(e){this.uniforms.speed.value=e}},lightWidth:{enumerable:!0,get:function(){return this.uniforms.lightWidth.value},set:function(e){this.uniforms.lightWidth.value=e}},uCenter:{enumerable:!0,get:function(){return this.uniforms.uCenter.value},set:function(e){this.uniforms.uCenter.value=e}},lightColor:{enumerable:!0,get:function(){return this.uniforms.lightColor.value},set:function(e){e&&(this.uniforms.lightColor.value=e)}}}),this.setValues(t)}copy(t){return super.copy(t),this.lineWidth=t.lineWidth,this.map=t.map,this.useMap=t.useMap,this.alphaMap=t.alphaMap,this.useAlphaMap=t.useAlphaMap,this.color.copy(t.color),this.opacity=t.opacity,this.resolution.copy(t.resolution),this.sizeAttenuation=t.sizeAttenuation,this.dashArray=t.dashArray,this.dashOffset=t.dashOffset,this.dashRatio=t.dashRatio,this.useDash=t.useDash,this.visibility=t.visibility,this.alphaTest=t.alphaTest,this.repeat.copy(t.repeat),this}dispose(){super.dispose();const t=a.indexOf(this);t>-1&&a.splice(t,1)}}exports.MeshLineMaterial=x;exports.meshLineMaterialArr=a;
|