gl-draw 0.12.1 → 0.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseObject.js +1 -1
- package/dist/BaseObject.module.js +54 -44
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/index.module.js +1 -1
- package/package.json +1 -1
package/dist/BaseObject.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const j=require("three"),m=require("esus-lite"),w=require("three/examples/jsm/renderers/CSS2DRenderer"),p=require("three/examples/jsm/renderers/CSS3DRenderer"),u=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");require("d3-geo-projection");function g(c){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const e in c)if(e!=="default"){const i=Object.getOwnPropertyDescriptor(c,e);Object.defineProperty(t,e,i.get?i:{enumerable:!0,get:()=>c[e]})}}return t.default=c,Object.freeze(t)}const r=g(j);class M{constructor(){this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.pm=m.makePromiseCreator(),this.materialList={},this.useMaterialType="origin",this.onPointerIndex=[]}get parent(){const t=this.object3d.parent;return t?this.drawController.objMap.get(t)||this.pencil.scene:null}get children(){return this.object3d.children.map(t=>this.drawController.objMap.get(t)).filter(t=>!!t)}get position(){var t;return(t=this.object3d)==null?void 0:t.position}get rotation(){var t;return(t=this.object3d)==null?void 0:t.rotation}get scale(){var t;return(t=this.object3d)==null?void 0:t.scale}get add(){var t;return(t=this.object3d)==null?void 0:t.add.bind(this.object3d)}get remove(){var t;return(t=this.object3d)==null?void 0:t.remove.bind(this.object3d)}get visible(){return this.object3d?this.object3d.visible:!1}create(){}render(){}update(t,e){}resize(t,e){}show(){return this.object3d&&(this.object3d.visible=!0),this}hide(){return this.object3d&&(this.object3d.visible=!1),this}createMesh(...t){return this.object3d=new r.Mesh(...t),this}createGroup(){return this.object3d=new r.Group,this}createPoints(...t){return this.object3d=new r.Points(...t),this}createCSS2DObject(t){return this.object3d=new w.CSS2DObject(t),this}createCSS3DObject(t){return this.object3d=new p.CSS3DObject(t),this}createCSS3DSprite(t){return this.object3d=new p.CSS3DSprite(t),this}createSprite(t){return this.object3d=new r.Sprite(t),this}attach(...t){return[...t].forEach(e=>{this.object3d.attach(e.object3d),this.drawController!==e.drawController&&(e.drawController.objects.delete(e.key),this.drawController.objects.set(e.key,e))}),this}getSize(){const t=new r.Box3().setFromObject(this.object3d);return{min:t.min,max:t.max,size:t.getSize(new r.Vector3),center:t.getCenter(new r.Vector3)}}traverse(t){t(this),this.children.forEach(e=>{e.traverse(t)})}clone(){return this.instantiate()}instantiate(t){return this.drawController.instantiate(this,{create:e=>{var i;if(this.object3d){if(this.object3d instanceof r.Sprite&&typeof t=="number"){const{size:s}=this.getSize(),n=new r.BufferGeometry;n.setAttribute("position",new r.Float32BufferAttribute(new Array(t*3).fill(0),3)),n.setAttribute("scale",new r.Float32BufferAttribute(new Array(t*3).fill(1),3)),n.setAttribute("quaternion",new r.Float32BufferAttribute(new Array(t*4).fill(0),4));const a=this.object3d.material,l=new r.PointsMaterial({size:Math.max(s.x,s.y,s.z),map:a.map,alphaMap:a.alphaMap,color:a.color,blending:a.blending,depthTest:a.depthTest,depthWrite:a.depthWrite,opacity:a.opacity,transparent:!0,alphaTest:a.alphaTest,sizeAttenuation:a.sizeAttenuation});e.object3d=new r.Points(n,l)}else typeof t=="number"?(e.object3d=new r.InstancedMesh(e.object3d.geometry,e.object3d.material,t),e.setMaterialList("instantiate","clone"),e.useMaterial("instantiate")):(e.object3d=this.object3d.clone(!0),e.position.set(0,0,0),e.rotation.set(0,0,0),e.setMaterialList("instantiate","clone"),e.useMaterial("instantiate"));e.object3d.userData.bloom&&((i=this.pencil.composerController)==null||i.toggleBloomSelection(e.object3d,!0)),e.object3d.userData.prefab&&(e.object3d.userData.prefab=!1)}}})}setInstancedMatrix(t){if(this.object3d instanceof r.InstancedMesh||this.object3d.isInstantiate){const e=this.object3d;Object.keys(t).forEach(i=>{e.setMatrixAt(Number(i),t[i])}),e.computeBoundingSphere()}else if(this.object3d instanceof r.Points){const i=this.object3d.geometry,s=i.attributes.position.array,n=i.attributes.scale.array,a=i.attributes.quaternion.array,l=new r.Vector3,h=new r.Vector3,d=new r.Quaternion;Object.keys(t).forEach(b=>{const f=t[b],o=Number(b)*3;f.decompose(l,d,h),s[o]=l.x,s[o+1]=l.y,s[o+2]=l.z,n[o]=h.x,n[o+1]=h.y,n[o+2]=h.z,a[o]=d.x,a[o+1]=d.y,a[o+2]=d.z}),i.attributes.position.needsUpdate=!0,i.attributes.scale.needsUpdate=!0,i.attributes.quaternion.needsUpdate=!0,i.computeBoundingSphere()}}erase(){this.drawController.erase(this)}cloneMaterial(){const t=this.object3d;if(!t||!t.material)return;const e=t.material;if(Array.isArray(e))return e.map(i=>{const s=i.userData;i.userData={};const n=i.clone();return i.userData=s,n});{const i=e.userData;e.userData={};const s=e.clone();return e.userData=i,s}}setMaterialList(t,e,i=!0){const s=this.object3d;if(!s||!s.material)return;if(this.materialList.origin||(this.materialList.origin=s.material),this.materialList[t])if(i){const a=this.materialList[t];u.disposeMesh({material:a})}else return this.materialList[t];const n=e==="clone"?this.cloneMaterial():e;return this.materialList[t]=n,n}useMaterial(t){const e=this.object3d;!e||!e.material||this.useMaterialType===t||!this.materialList[t]||(this.useMaterialType=t,e.material=this.materialList[t])}setTop(t){this.object3d&&(this.object3d.renderOrder=t)}onPointerEvent(t,e){const i=this.drawController.handlePick([this],t,e);this.onPointerIndex.push(i)}dispose(){this.onPointerIndex.forEach(t=>{this.drawController.removePick(t)}),this.object3d&&u.disposeMesh(this.object3d),Object.keys(this.materialList).forEach(t=>{if(t!==this.useMaterialType){if(this.isInstantiate&&t==="origin")return;u.disposeMesh({material:this.materialList[t]})}})}disposeWithOutMaterial(){this.onPointerIndex.forEach(t=>{this.drawController.removePick(t)}),this.object3d&&u.disposeMesh(this.object3d,!1)}}exports.BaseObject=M;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as r from "three";
|
|
2
|
-
import { makePromiseCreator as
|
|
3
|
-
import { CSS2DObject as
|
|
4
|
-
import { CSS3DObject as
|
|
5
|
-
import { d
|
|
2
|
+
import { makePromiseCreator as p } from "esus-lite";
|
|
3
|
+
import { CSS2DObject as m } from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
4
|
+
import { CSS3DObject as f, CSS3DSprite as j } from "three/examples/jsm/renderers/CSS3DRenderer";
|
|
5
|
+
import { d } from "./disposeMesh.module.js";
|
|
6
6
|
import "idb-keyval";
|
|
7
7
|
import "d3-geo";
|
|
8
8
|
import "d3-geo-projection";
|
|
9
|
-
class
|
|
9
|
+
class A {
|
|
10
10
|
constructor() {
|
|
11
|
-
this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.isInstantiate = !1, this.pm =
|
|
11
|
+
this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.isInstantiate = !1, this.pm = p(), this.materialList = {}, this.useMaterialType = "origin", this.onPointerIndex = [];
|
|
12
12
|
}
|
|
13
13
|
get parent() {
|
|
14
14
|
const t = this.object3d.parent;
|
|
@@ -64,13 +64,13 @@ class C {
|
|
|
64
64
|
return this.object3d = new r.Points(...t), this;
|
|
65
65
|
}
|
|
66
66
|
createCSS2DObject(t) {
|
|
67
|
-
return this.object3d = new
|
|
67
|
+
return this.object3d = new m(t), this;
|
|
68
68
|
}
|
|
69
69
|
createCSS3DObject(t) {
|
|
70
|
-
return this.object3d = new
|
|
70
|
+
return this.object3d = new f(t), this;
|
|
71
71
|
}
|
|
72
72
|
createCSS3DSprite(t) {
|
|
73
|
-
return this.object3d = new
|
|
73
|
+
return this.object3d = new j(t), this;
|
|
74
74
|
}
|
|
75
75
|
createSprite(t) {
|
|
76
76
|
return this.object3d = new r.Sprite(t), this;
|
|
@@ -103,33 +103,37 @@ class C {
|
|
|
103
103
|
var i;
|
|
104
104
|
if (this.object3d) {
|
|
105
105
|
if (this.object3d instanceof r.Sprite && typeof t == "number") {
|
|
106
|
-
const { size: s } = this.getSize(),
|
|
107
|
-
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
"
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
"
|
|
115
|
-
|
|
116
|
-
"depthWrite"
|
|
117
|
-
];
|
|
118
|
-
for (const c of n) {
|
|
119
|
-
const h = this.object3d.material[c];
|
|
120
|
-
h !== null && (a[c] = h);
|
|
121
|
-
}
|
|
122
|
-
e.object3d = new r.Mesh(
|
|
123
|
-
new r.PlaneGeometry(s.x, s.y, 2, 2),
|
|
124
|
-
a
|
|
106
|
+
const { size: s } = this.getSize(), o = new r.BufferGeometry();
|
|
107
|
+
o.setAttribute(
|
|
108
|
+
"position",
|
|
109
|
+
new r.Float32BufferAttribute(new Array(t * 3).fill(0), 3)
|
|
110
|
+
), o.setAttribute(
|
|
111
|
+
"scale",
|
|
112
|
+
new r.Float32BufferAttribute(new Array(t * 3).fill(1), 3)
|
|
113
|
+
), o.setAttribute(
|
|
114
|
+
"quaternion",
|
|
115
|
+
new r.Float32BufferAttribute(new Array(t * 4).fill(0), 4)
|
|
125
116
|
);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
117
|
+
const a = this.object3d.material, c = new r.PointsMaterial({
|
|
118
|
+
size: Math.max(s.x, s.y, s.z),
|
|
119
|
+
map: a.map,
|
|
120
|
+
alphaMap: a.alphaMap,
|
|
121
|
+
color: a.color,
|
|
122
|
+
blending: a.blending,
|
|
123
|
+
depthTest: a.depthTest,
|
|
124
|
+
depthWrite: a.depthWrite,
|
|
125
|
+
opacity: a.opacity,
|
|
126
|
+
transparent: !0,
|
|
127
|
+
alphaTest: a.alphaTest,
|
|
128
|
+
sizeAttenuation: a.sizeAttenuation
|
|
129
|
+
});
|
|
130
|
+
e.object3d = new r.Points(o, c);
|
|
131
|
+
} else typeof t == "number" ? (e.object3d = new r.InstancedMesh(
|
|
129
132
|
e.object3d.geometry,
|
|
130
133
|
e.object3d.material,
|
|
131
134
|
t
|
|
132
|
-
), e.object3d.
|
|
135
|
+
), e.setMaterialList("instantiate", "clone"), e.useMaterial("instantiate")) : (e.object3d = this.object3d.clone(!0), e.position.set(0, 0, 0), e.rotation.set(0, 0, 0), e.setMaterialList("instantiate", "clone"), e.useMaterial("instantiate"));
|
|
136
|
+
e.object3d.userData.bloom && ((i = this.pencil.composerController) == null || i.toggleBloomSelection(
|
|
133
137
|
e.object3d,
|
|
134
138
|
!0
|
|
135
139
|
)), e.object3d.userData.prefab && (e.object3d.userData.prefab = !1);
|
|
@@ -142,7 +146,13 @@ class C {
|
|
|
142
146
|
const e = this.object3d;
|
|
143
147
|
Object.keys(t).forEach((i) => {
|
|
144
148
|
e.setMatrixAt(Number(i), t[i]);
|
|
145
|
-
}), e.
|
|
149
|
+
}), e.computeBoundingSphere();
|
|
150
|
+
} else if (this.object3d instanceof r.Points) {
|
|
151
|
+
const i = this.object3d.geometry, s = i.attributes.position.array, o = i.attributes.scale.array, a = i.attributes.quaternion.array, c = new r.Vector3(), h = new r.Vector3(), l = new r.Quaternion();
|
|
152
|
+
Object.keys(t).forEach((u) => {
|
|
153
|
+
const b = t[u], n = Number(u) * 3;
|
|
154
|
+
b.decompose(c, l, h), s[n] = c.x, s[n + 1] = c.y, s[n + 2] = c.z, o[n] = h.x, o[n + 1] = h.y, o[n + 2] = h.z, a[n] = l.x, a[n + 1] = l.y, a[n + 2] = l.z;
|
|
155
|
+
}), i.attributes.position.needsUpdate = !0, i.attributes.scale.needsUpdate = !0, i.attributes.quaternion.needsUpdate = !0, i.computeBoundingSphere();
|
|
146
156
|
}
|
|
147
157
|
}
|
|
148
158
|
erase() {
|
|
@@ -157,8 +167,8 @@ class C {
|
|
|
157
167
|
return e.map((i) => {
|
|
158
168
|
const s = i.userData;
|
|
159
169
|
i.userData = {};
|
|
160
|
-
const
|
|
161
|
-
return i.userData = s,
|
|
170
|
+
const o = i.clone();
|
|
171
|
+
return i.userData = s, o;
|
|
162
172
|
});
|
|
163
173
|
{
|
|
164
174
|
const i = e.userData;
|
|
@@ -173,14 +183,14 @@ class C {
|
|
|
173
183
|
return;
|
|
174
184
|
if (this.materialList.origin || (this.materialList.origin = s.material), this.materialList[t])
|
|
175
185
|
if (i) {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
material:
|
|
186
|
+
const a = this.materialList[t];
|
|
187
|
+
d({
|
|
188
|
+
material: a
|
|
179
189
|
});
|
|
180
190
|
} else
|
|
181
191
|
return this.materialList[t];
|
|
182
|
-
const
|
|
183
|
-
return this.materialList[t] =
|
|
192
|
+
const o = e === "clone" ? this.cloneMaterial() : e;
|
|
193
|
+
return this.materialList[t] = o, o;
|
|
184
194
|
}
|
|
185
195
|
useMaterial(t) {
|
|
186
196
|
const e = this.object3d;
|
|
@@ -196,11 +206,11 @@ class C {
|
|
|
196
206
|
dispose() {
|
|
197
207
|
this.onPointerIndex.forEach((t) => {
|
|
198
208
|
this.drawController.removePick(t);
|
|
199
|
-
}), this.object3d &&
|
|
209
|
+
}), this.object3d && d(this.object3d), Object.keys(this.materialList).forEach((t) => {
|
|
200
210
|
if (t !== this.useMaterialType) {
|
|
201
211
|
if (this.isInstantiate && t === "origin")
|
|
202
212
|
return;
|
|
203
|
-
|
|
213
|
+
d({
|
|
204
214
|
material: this.materialList[t]
|
|
205
215
|
});
|
|
206
216
|
}
|
|
@@ -209,9 +219,9 @@ class C {
|
|
|
209
219
|
disposeWithOutMaterial() {
|
|
210
220
|
this.onPointerIndex.forEach((t) => {
|
|
211
221
|
this.drawController.removePick(t);
|
|
212
|
-
}), this.object3d &&
|
|
222
|
+
}), this.object3d && d(this.object3d, !1);
|
|
213
223
|
}
|
|
214
224
|
}
|
|
215
225
|
export {
|
|
216
|
-
|
|
226
|
+
A as B
|
|
217
227
|
};
|