gl-draw 0.10.20 → 0.10.21
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const b=require("three"),p=require("esus-lite"),j=require("three/examples/jsm/renderers/CSS2DRenderer"),d=require("three/examples/jsm/renderers/CSS3DRenderer"),c=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");function f(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,r.get?r:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const i=f(b),u=(a,e,t)=>{e&&(c.disposeMesh(e,t),e.children.forEach(r=>{a.has(r)||u(a,r,t)}))};class m{constructor(){this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!1,this.pm=p.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 i.Mesh(...e),this}createGroup(){return this.object3d=new i.Group,this}createPoints(...e){return this.object3d=new i.Points(...e),this}createCSS2DObject(e){return this.object3d=new j.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 i.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 i.Box3().setFromObject(this.object3d);return{min:e.min,max:e.max,size:e.getSize(new i.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 r;if(this.object3d){if(this.object3d instanceof i.Sprite&&typeof e=="number"){const{size:s}=this.getSize(),n=new i.MeshBasicMaterial,o=["color","map","alphaMap","transparent","opacity","alphaTest","blending","side","depthTest","depthWrite"];for(const h of o){const l=this.object3d.material[h];l!==null&&(n[h]=l)}t.object3d=new i.Mesh(new i.PlaneGeometry(s.x,s.y,2,2),n)}else t.object3d=this.object3d.clone(!0);typeof e=="number"&&(t.object3d=new i.InstancedMesh(t.object3d.geometry,t.object3d.material,e),t.object3d.instanceMatrix.setUsage(i.DynamicDrawUsage)),t.position.set(0,0,0),t.rotation.set(0,0,0),t.setMaterialList("instantiate","clone"),t.useMaterial("instantiate"),t.object3d.userData.bloom&&((r=this.pencil.composerController)==null||r.toggleBloomSelection(t.object3d,!0)),t.object3d.userData.prefab&&(t.object3d.userData.prefab=!1)}}})}setInstancedMatrix(e){this.object3d instanceof i.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 s=r.userData;r.userData={};const n=r.clone();return r.userData=s,n});{const r=t.userData;t.userData={};const s=t.clone();return t.userData=r,s}}setMaterialList(e,t,r=!0){const s=this.object3d;if(!s||!s.material)return;if(this.materialList.origin||(this.materialList.origin=s.material),this.materialList[e])if(r){const o=this.materialList[e];c.disposeMesh({material:o})}else return this.materialList[e];const n=t==="clone"?this.cloneMaterial():t;return this.materialList[e]=n,n}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 r=this.drawController.handlePick([this],e,t);this.onPointerIndex.push(r)}dispose(e=!0){this.onPointerIndex.forEach(t=>{this.drawController.removePick(t)}),u(this.drawController.objMap,this.object3d,e),e&&Object.keys(this.materialList).forEach(t=>{if(t!==this.useMaterialType){if(this.isInstantiate&&t==="origin")return;c.disposeMesh({material:this.materialList[t]})}})}}exports.BaseObject=m;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import * as r from "three";
|
|
2
|
-
import { makePromiseCreator as
|
|
3
|
-
import { CSS2DObject as
|
|
4
|
-
import { CSS3DObject as
|
|
2
|
+
import { makePromiseCreator as b } from "esus-lite";
|
|
3
|
+
import { CSS2DObject as u } from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
4
|
+
import { CSS3DObject as p, CSS3DSprite as j } from "three/examples/jsm/renderers/CSS3DRenderer";
|
|
5
5
|
import { d as c } from "./disposeMesh.module.js";
|
|
6
6
|
import "idb-keyval";
|
|
7
7
|
import "d3-geo";
|
|
8
|
-
const
|
|
8
|
+
const d = (o, t, e) => {
|
|
9
9
|
t && (c(t, e), t.children.forEach((i) => {
|
|
10
|
-
|
|
10
|
+
o.has(i) || d(o, i, e);
|
|
11
11
|
}));
|
|
12
12
|
};
|
|
13
|
-
class
|
|
13
|
+
class D {
|
|
14
14
|
constructor() {
|
|
15
|
-
this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.isInstantiate = !1, this.pm =
|
|
15
|
+
this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.isInstantiate = !1, this.pm = b(), this.materialList = {}, this.useMaterialType = "origin", this.onPointerIndex = [];
|
|
16
16
|
}
|
|
17
17
|
get parent() {
|
|
18
18
|
const t = this.object3d.parent;
|
|
@@ -68,13 +68,13 @@ class S {
|
|
|
68
68
|
return this.object3d = new r.Points(...t), this;
|
|
69
69
|
}
|
|
70
70
|
createCSS2DObject(t) {
|
|
71
|
-
return this.object3d = new
|
|
71
|
+
return this.object3d = new u(t), this;
|
|
72
72
|
}
|
|
73
73
|
createCSS3DObject(t) {
|
|
74
|
-
return this.object3d = new
|
|
74
|
+
return this.object3d = new p(t), this;
|
|
75
75
|
}
|
|
76
76
|
createCSS3DSprite(t) {
|
|
77
|
-
return this.object3d = new
|
|
77
|
+
return this.object3d = new j(t), this;
|
|
78
78
|
}
|
|
79
79
|
createSprite(t) {
|
|
80
80
|
return this.object3d = new r.Sprite(t), this;
|
|
@@ -103,9 +103,10 @@ class S {
|
|
|
103
103
|
instantiate(t) {
|
|
104
104
|
return this.drawController.instantiate(this, {
|
|
105
105
|
create: (e) => {
|
|
106
|
+
var i;
|
|
106
107
|
if (this.object3d) {
|
|
107
108
|
if (this.object3d instanceof r.Sprite && typeof t == "number") {
|
|
108
|
-
const { size:
|
|
109
|
+
const { size: s } = this.getSize(), a = new r.MeshBasicMaterial(), n = [
|
|
109
110
|
"color",
|
|
110
111
|
"map",
|
|
111
112
|
"alphaMap",
|
|
@@ -117,13 +118,13 @@ class S {
|
|
|
117
118
|
"depthTest",
|
|
118
119
|
"depthWrite"
|
|
119
120
|
];
|
|
120
|
-
for (const
|
|
121
|
-
const
|
|
122
|
-
|
|
121
|
+
for (const h of n) {
|
|
122
|
+
const l = this.object3d.material[h];
|
|
123
|
+
l !== null && (a[h] = l);
|
|
123
124
|
}
|
|
124
125
|
e.object3d = new r.Mesh(
|
|
125
|
-
new r.PlaneGeometry(
|
|
126
|
-
|
|
126
|
+
new r.PlaneGeometry(s.x, s.y, 2, 2),
|
|
127
|
+
a
|
|
127
128
|
);
|
|
128
129
|
} else
|
|
129
130
|
e.object3d = this.object3d.clone(!0);
|
|
@@ -131,10 +132,10 @@ class S {
|
|
|
131
132
|
e.object3d.geometry,
|
|
132
133
|
e.object3d.material,
|
|
133
134
|
t
|
|
134
|
-
), 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 && this.pencil.composerController.toggleBloomSelection(
|
|
135
|
+
), 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
136
|
e.object3d,
|
|
136
137
|
!0
|
|
137
|
-
), e.object3d.userData.prefab && (e.object3d.userData.prefab = !1);
|
|
138
|
+
)), e.object3d.userData.prefab && (e.object3d.userData.prefab = !1);
|
|
138
139
|
}
|
|
139
140
|
}
|
|
140
141
|
});
|
|
@@ -175,9 +176,9 @@ class S {
|
|
|
175
176
|
return;
|
|
176
177
|
if (this.materialList.origin || (this.materialList.origin = s.material), this.materialList[t])
|
|
177
178
|
if (i) {
|
|
178
|
-
const
|
|
179
|
+
const n = this.materialList[t];
|
|
179
180
|
c({
|
|
180
|
-
material:
|
|
181
|
+
material: n
|
|
181
182
|
});
|
|
182
183
|
} else
|
|
183
184
|
return this.materialList[t];
|
|
@@ -198,7 +199,7 @@ class S {
|
|
|
198
199
|
dispose(t = !0) {
|
|
199
200
|
this.onPointerIndex.forEach((e) => {
|
|
200
201
|
this.drawController.removePick(e);
|
|
201
|
-
}),
|
|
202
|
+
}), d(
|
|
202
203
|
this.drawController.objMap,
|
|
203
204
|
this.object3d,
|
|
204
205
|
t
|
|
@@ -214,5 +215,5 @@ class S {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
export {
|
|
217
|
-
|
|
218
|
+
D as B
|
|
218
219
|
};
|
package/dist/plugins/Draw.d.ts
CHANGED
|
@@ -60,11 +60,12 @@ export default class Draw<T extends {
|
|
|
60
60
|
showPrefab(key?: string): void;
|
|
61
61
|
hidePrefab(): void;
|
|
62
62
|
eraseAll(): void;
|
|
63
|
-
private
|
|
63
|
+
private pickFunctionsMapIndex;
|
|
64
|
+
private pickFunctionsMap;
|
|
64
65
|
private pickListener;
|
|
65
66
|
private addPickListener;
|
|
66
67
|
handlePick(objArr: PickFunctionsItem['objArr'], t: PickFunctionsItem['type'], cb: PickFunctionsItem['cb']): number;
|
|
67
|
-
removePick(
|
|
68
|
+
removePick(key: number): void;
|
|
68
69
|
dispose(): void;
|
|
69
70
|
}
|
|
70
71
|
export {};
|