gl-draw 0.9.23 → 0.9.24
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 +32 -22
- package/package.json +1 -1
package/dist/BaseObject.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const
|
|
1
|
+
"use strict";const u=require("three"),b=require("esus-lite"),j=require("three/examples/jsm/renderers/CSS2DRenderer"),h=require("three/examples/jsm/renderers/CSS3DRenderer"),d=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");function p(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=p(u),l=(a,e,t)=>{e&&(d.disposeMesh(e,t),e.children.forEach(r=>{a.has(r)||l(a,r,t)}))};class f{constructor(){this.objectType="BaseObject",this.userData={},this.prefab=!1,this.pm=b.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 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 h.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new h.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=>{if(this.object3d)if(this.object3d instanceof i.Sprite&&typeof e=="number"){const{size:r}=this.getSize(),s=new i.MeshBasicMaterial,n=["color","map","alphaMap","transparent","opacity","alphaTest","blending","side","depthTest","depthWrite"];for(const o of n){const c=this.object3d.material[o];c!==null&&(s[o]=c)}t.object3d=new i.Mesh(new i.PlaneGeometry(r.x,r.y,2,2),s)}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))}})}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),!r&&this.materialList[e])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)}dispose(e=!0){l(this.drawController.objMap,this.object3d,e),e&&Object.keys(this.materialList).forEach(t=>{t!=="origin"&&d.disposeMesh({material:this.materialList[t]})})}}exports.BaseObject=f;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import * as i from "three";
|
|
2
|
-
import { makePromiseCreator as
|
|
3
|
-
import { CSS2DObject as
|
|
4
|
-
import { CSS3DObject as
|
|
5
|
-
import { d as
|
|
2
|
+
import { makePromiseCreator as l } from "esus-lite";
|
|
3
|
+
import { CSS2DObject as b } from "three/examples/jsm/renderers/CSS2DRenderer";
|
|
4
|
+
import { CSS3DObject as u, CSS3DSprite as j } from "three/examples/jsm/renderers/CSS3DRenderer";
|
|
5
|
+
import { d as h } from "./disposeMesh.module.js";
|
|
6
6
|
import "idb-keyval";
|
|
7
7
|
import "d3-geo";
|
|
8
|
-
const
|
|
9
|
-
t && (
|
|
10
|
-
o.has(r) ||
|
|
8
|
+
const d = (o, t, e) => {
|
|
9
|
+
t && (h(t, e), t.children.forEach((r) => {
|
|
10
|
+
o.has(r) || d(o, r, e);
|
|
11
11
|
}));
|
|
12
12
|
};
|
|
13
|
-
class
|
|
13
|
+
class S {
|
|
14
14
|
constructor() {
|
|
15
|
-
this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.pm =
|
|
15
|
+
this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.pm = l(), this.materialList = {}, this.useMaterialType = "origin";
|
|
16
16
|
}
|
|
17
17
|
get parent() {
|
|
18
18
|
const t = this.object3d.parent;
|
|
@@ -68,13 +68,13 @@ class g {
|
|
|
68
68
|
return this.object3d = new i.Points(...t), this;
|
|
69
69
|
}
|
|
70
70
|
createCSS2DObject(t) {
|
|
71
|
-
return this.object3d = new
|
|
71
|
+
return this.object3d = new b(t), this;
|
|
72
72
|
}
|
|
73
73
|
createCSS3DObject(t) {
|
|
74
|
-
return this.object3d = new
|
|
74
|
+
return this.object3d = new u(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 i.Sprite(t), this;
|
|
@@ -105,15 +105,25 @@ class g {
|
|
|
105
105
|
create: (e) => {
|
|
106
106
|
if (this.object3d)
|
|
107
107
|
if (this.object3d instanceof i.Sprite && typeof t == "number") {
|
|
108
|
-
const { size: r } = this.getSize()
|
|
108
|
+
const { size: r } = this.getSize(), s = new i.MeshBasicMaterial(), a = [
|
|
109
|
+
"color",
|
|
110
|
+
"map",
|
|
111
|
+
"alphaMap",
|
|
112
|
+
"transparent",
|
|
113
|
+
"opacity",
|
|
114
|
+
"alphaTest",
|
|
115
|
+
"blending",
|
|
116
|
+
"side",
|
|
117
|
+
"depthTest",
|
|
118
|
+
"depthWrite"
|
|
119
|
+
];
|
|
120
|
+
for (const n of a) {
|
|
121
|
+
const c = this.object3d.material[n];
|
|
122
|
+
c !== null && (s[n] = c);
|
|
123
|
+
}
|
|
109
124
|
e.object3d = new i.Mesh(
|
|
110
125
|
new i.PlaneGeometry(r.x, r.y, 2, 2),
|
|
111
|
-
|
|
112
|
-
map: this.object3d.material.map,
|
|
113
|
-
color: this.object3d.material.color,
|
|
114
|
-
transparent: this.object3d.material.transparent,
|
|
115
|
-
alphaTest: this.object3d.material.alphaTest
|
|
116
|
-
})
|
|
126
|
+
s
|
|
117
127
|
);
|
|
118
128
|
} else
|
|
119
129
|
e.object3d = this.object3d.clone(!0);
|
|
@@ -172,17 +182,17 @@ class g {
|
|
|
172
182
|
this.object3d && (this.object3d.renderOrder = t);
|
|
173
183
|
}
|
|
174
184
|
dispose(t = !0) {
|
|
175
|
-
|
|
185
|
+
d(
|
|
176
186
|
this.drawController.objMap,
|
|
177
187
|
this.object3d,
|
|
178
188
|
t
|
|
179
189
|
), t && Object.keys(this.materialList).forEach((e) => {
|
|
180
|
-
e !== "origin" &&
|
|
190
|
+
e !== "origin" && h({
|
|
181
191
|
material: this.materialList[e]
|
|
182
192
|
});
|
|
183
193
|
});
|
|
184
194
|
}
|
|
185
195
|
}
|
|
186
196
|
export {
|
|
187
|
-
|
|
197
|
+
S as B
|
|
188
198
|
};
|