gl-draw 0.12.3 → 0.12.4
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 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"
|
|
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 if(typeof t=="number"){const s=this.object3d;e.object3d=new r.InstancedMesh(s.geometry,s.material,t),e.setMaterialList("instantiate","clone"),e.useMaterial("instantiate")}else 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;
|
|
@@ -128,11 +128,15 @@ class A {
|
|
|
128
128
|
sizeAttenuation: a.sizeAttenuation
|
|
129
129
|
});
|
|
130
130
|
e.object3d = new r.Points(o, c);
|
|
131
|
-
} else typeof t == "number"
|
|
132
|
-
|
|
133
|
-
e.object3d.
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
} else if (typeof t == "number") {
|
|
132
|
+
const s = this.object3d;
|
|
133
|
+
e.object3d = new r.InstancedMesh(
|
|
134
|
+
s.geometry,
|
|
135
|
+
s.material,
|
|
136
|
+
t
|
|
137
|
+
), e.setMaterialList("instantiate", "clone"), e.useMaterial("instantiate");
|
|
138
|
+
} else
|
|
139
|
+
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
140
|
e.object3d.userData.bloom && ((i = this.pencil.composerController) == null || i.toggleBloomSelection(
|
|
137
141
|
e.object3d,
|
|
138
142
|
!0
|