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.
@@ -1 +1 @@
1
- "use strict";const u=require("three"),b=require("esus-lite"),p=require("three/examples/jsm/renderers/CSS2DRenderer"),d=require("three/examples/jsm/renderers/CSS3DRenderer"),o=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");require("d3-geo-projection");function j(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const i=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,i.get?i:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const r=j(u);class f{constructor(){this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.pm=b.makePromiseCreator(),this.materialList={},this.useMaterialType="origin",this.onPointerIndex=[]}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 r.Mesh(...e),this}createGroup(){return this.object3d=new r.Group,this}createPoints(...e){return this.object3d=new r.Points(...e),this}createCSS2DObject(e){return this.object3d=new p.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new d.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new d.CSS3DSprite(e),this}createSprite(e){return this.object3d=new r.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 r.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new r.Vector3),center:e.getCenter(new r.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=>{var i;if(this.object3d){if(this.object3d instanceof r.Sprite&&typeof e=="number"){const{size:s}=this.getSize(),a=new r.MeshBasicMaterial,c=["color","map","alphaMap","transparent","opacity","alphaTest","blending","side","depthTest","depthWrite"];for(const h of c){const l=this.object3d.material[h];l!==null&&(a[h]=l)}t.object3d=new r.Mesh(new r.PlaneGeometry(s.x,s.y,2,2),a)}else t.object3d=this.object3d.clone(!0);typeof e=="number"&&(t.object3d=new r.InstancedMesh(t.object3d.geometry,t.object3d.material,e),t.object3d.instanceMatrix.setUsage(r.DynamicDrawUsage)),t.position.set(0,0,0),t.rotation.set(0,0,0),t.setMaterialList("instantiate","clone"),t.useMaterial("instantiate"),t.object3d.userData.bloom&&((i=this.pencil.composerController)==null||i.toggleBloomSelection(t.object3d,!0)),t.object3d.userData.prefab&&(t.object3d.userData.prefab=!1)}}})}setInstancedMatrix(e){if(this.object3d instanceof r.InstancedMesh||this.object3d.isInstantiate){const t=this.object3d;Object.keys(e).forEach(i=>{t.setMatrixAt(Number(i),e[i])}),t.instanceMatrix.needsUpdate=!0,t.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(i=>{const s=i.userData;i.userData={};const a=i.clone();return i.userData=s,a});{const i=t.userData;t.userData={};const s=t.clone();return t.userData=i,s}}setMaterialList(e,t,i=!0){const s=this.object3d;if(!s||!s.material)return;if(this.materialList.origin||(this.materialList.origin=s.material),this.materialList[e])if(i){const c=this.materialList[e];o.disposeMesh({material:c})}else return this.materialList[e];const a=t==="clone"?this.cloneMaterial():t;return this.materialList[e]=a,a}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)}onPointerEvent(e,t){const i=this.drawController.handlePick([this],e,t);this.onPointerIndex.push(i)}dispose(){this.onPointerIndex.forEach(e=>{this.drawController.removePick(e)}),this.object3d&&o.disposeMesh(this.object3d),Object.keys(this.materialList).forEach(e=>{if(e!==this.useMaterialType){if(this.isInstantiate&&e==="origin")return;o.disposeMesh({material:this.materialList[e]})}})}disposeWithOutMaterial(){this.onPointerIndex.forEach(e=>{this.drawController.removePick(e)}),this.object3d&&o.disposeMesh(this.object3d,!1)}}exports.BaseObject=f;
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 l } from "esus-lite";
3
- import { CSS2DObject as d } from "three/examples/jsm/renderers/CSS2DRenderer";
4
- import { CSS3DObject as b, CSS3DSprite as u } from "three/examples/jsm/renderers/CSS3DRenderer";
5
- import { d as o } from "./disposeMesh.module.js";
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 C {
9
+ class A {
10
10
  constructor() {
11
- this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.isInstantiate = !1, this.pm = l(), this.materialList = {}, this.useMaterialType = "origin", this.onPointerIndex = [];
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 d(t), this;
67
+ return this.object3d = new m(t), this;
68
68
  }
69
69
  createCSS3DObject(t) {
70
- return this.object3d = new b(t), this;
70
+ return this.object3d = new f(t), this;
71
71
  }
72
72
  createCSS3DSprite(t) {
73
- return this.object3d = new u(t), this;
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(), a = new r.MeshBasicMaterial(), n = [
107
- "color",
108
- "map",
109
- "alphaMap",
110
- "transparent",
111
- "opacity",
112
- "alphaTest",
113
- "blending",
114
- "side",
115
- "depthTest",
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
- } else
127
- e.object3d = this.object3d.clone(!0);
128
- typeof t == "number" && (e.object3d = new r.InstancedMesh(
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.instanceMatrix.setUsage(r.DynamicDrawUsage)), 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(
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.instanceMatrix.needsUpdate = !0, e.computeBoundingSphere();
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 a = i.clone();
161
- return i.userData = s, a;
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 n = this.materialList[t];
177
- o({
178
- material: n
186
+ const a = this.materialList[t];
187
+ d({
188
+ material: a
179
189
  });
180
190
  } else
181
191
  return this.materialList[t];
182
- const a = e === "clone" ? this.cloneMaterial() : e;
183
- return this.materialList[t] = a, a;
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 && o(this.object3d), Object.keys(this.materialList).forEach((t) => {
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
- o({
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 && o(this.object3d, !1);
222
+ }), this.object3d && d(this.object3d, !1);
213
223
  }
214
224
  }
215
225
  export {
216
- C as B
226
+ A as B
217
227
  };