gl-draw 0.10.5 → 0.10.6

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"),l=require("three/examples/jsm/renderers/CSS3DRenderer"),c=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");function j(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=j(u),d=(a,e,t)=>{e&&(c.disposeMesh(e,t),e.children.forEach(r=>{a.has(r)||d(a,r,t)}))};class f{constructor(){this.objectType="BaseObject",this.userData={},this.prefab=!1,this.isInstantiate=!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 p.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new l.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new l.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 h=this.object3d.material[o];h!==null&&(s[o]=h)}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)),t.position.set(0,0,0),t.rotation.set(0,0,0),t.setMaterialList("instantiate","clone"),t.useMaterial("instantiate"),t.object3d.userData.bloom&&this.pencil.composerController.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)}dispose(e=!0){d(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=f;
1
+ "use strict";const u=require("three"),b=require("esus-lite"),p=require("three/examples/jsm/renderers/CSS2DRenderer"),l=require("three/examples/jsm/renderers/CSS3DRenderer"),c=require("./disposeMesh.js");require("idb-keyval");require("d3-geo");function j(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=j(u),d=(a,e,t)=>{e&&(c.disposeMesh(e,t),e.children.forEach(r=>{a.has(r)||d(a,r,t)}))};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 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 p.CSS2DObject(e),this}createCSS3DObject(e){return this.object3d=new l.CSS3DObject(e),this}createCSS3DSprite(e){return this.object3d=new l.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 h=this.object3d.material[o];h!==null&&(s[o]=h)}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)),t.position.set(0,0,0),t.rotation.set(0,0,0),t.setMaterialList("instantiate","clone"),t.useMaterial("instantiate"),t.object3d.userData.bloom&&this.pencil.composerController.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)}),d(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=f;
@@ -12,7 +12,7 @@ const l = (n, t, e) => {
12
12
  };
13
13
  class S {
14
14
  constructor() {
15
- this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.isInstantiate = !1, this.pm = d(), this.materialList = {}, this.useMaterialType = "origin";
15
+ this.objectType = "BaseObject", this.userData = {}, this.prefab = !1, this.isInstantiate = !1, this.pm = d(), this.materialList = {}, this.useMaterialType = "origin", this.onPointerIndex = [];
16
16
  }
17
17
  get parent() {
18
18
  const t = this.object3d.parent;
@@ -191,8 +191,14 @@ class S {
191
191
  setTop(t) {
192
192
  this.object3d && (this.object3d.renderOrder = t);
193
193
  }
194
+ onPointerEvent(t, e) {
195
+ const i = this.drawController.handlePick([this], t, e);
196
+ this.onPointerIndex.push(i);
197
+ }
194
198
  dispose(t = !0) {
195
- l(
199
+ this.onPointerIndex.forEach((e) => {
200
+ this.drawController.removePick(e);
201
+ }), l(
196
202
  this.drawController.objMap,
197
203
  this.object3d,
198
204
  t
@@ -56,6 +56,8 @@ export default class BaseObject {
56
56
  useMaterialType: string;
57
57
  useMaterial(name: string): void;
58
58
  setTop(onTop: number): void;
59
+ private onPointerIndex;
60
+ onPointerEvent(type: Draw<any>['pickFunctionsArr'][0]['type'], cb: Draw<any>['pickFunctionsArr'][0]['cb']): void;
59
61
  dispose(disposeWithMaterial?: boolean): void;
60
62
  }
61
63
  export interface IBaseObject extends BaseObject {
package/dist/index.js CHANGED
@@ -11,4 +11,4 @@
11
11
  void main() {
12
12
  gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0 ) * texture2D( bloomTexture, vUv ) );
13
13
  }
14
- `,defines:{}}),"baseTexture");l.needsSwap=!0,this.bloomComposer=a,this.finalComposer.addPass(l),this.mixPass=l,this.bloomLayer.set(ut)}addBloomGui(t){if(!this.bloomComposer)return;new ft({bloom:{threshold:{min:0,max:1,step:.01,target:()=>this.bloomPass},radius:{min:0,max:1,step:.001,target:()=>this.bloomPass},strength:{min:0,max:10,step:.001,target:()=>this.bloomPass}}}).showGui(t)}toggleBloomSelection(t,e){if(!this.bloomComposer){console.warn("err:pencil.options.bloom");return}const{object3d:s}=t;if(!s)return;let i=e;e===void 0&&(i=!this.bloomSelection.has(s)),i?(this.bloomSelection.add(s),s.layers.enable(ut)):(this.bloomSelection.delete(s),s.layers.disable(ut)),this.bloomSelection.size===0?this.bloomComposerActive=!1:this.bloomComposerActive=!0}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(t,e){var s;(s=this.bloomComposer)==null||s.setSize(t,e),this.finalComposer.setSize(t,e)}render(){this.active&&(this.bloomComposerActive&&this.bloomComposer?(this.mixPass.enabled=!0,this.scene.traverse(t=>{const e=t;e.isMesh&&this.bloomLayer.test(e.layers)===!1&&(this.bloomMaterials[e.uuid]=e.material,e.material=Ce)}),this.bloomComposer.render(),this.scene.traverse(t=>{const e=t;this.bloomMaterials[e.uuid]&&(e.material=this.bloomMaterials[e.uuid],delete this.bloomMaterials[e.uuid])})):this.mixPass&&(this.mixPass.enabled=!1),this.finalComposer.render())}render2(){this.active}dispose(){var t;this.bloomMaterials={},this.bloomSelection.clear(),this.finalComposer.dispose(),(t=this.bloomComposer)==null||t.dispose()}}const nt=class nt{constructor(t,e){this.raycaster=new x.Raycaster,this.installPlugins=new Map,this.event=new bt.eventsExports.EventEmitter,this.clock=new x.Clock,this.userData={},this.pipViewportState=!1,this.options=Nt(nt.options,t,{isMergeableObject:ie.isPlainObject}),this.event.setMaxListeners(1/0);const{container:s,stats:i,gui:o,resizeObserver:r}=this.options;if(o){const a=new jt;a.open(!1),this.gui=a}if(this.init(),i){const a=new qt({horizontal:!1});a.init(this.renderer),s.appendChild(a.dom),this.stats=a}this.options.WebGPUTHREE||this.initComposer(),this.initCSSRenderer(),this.initControls(),r&&this.initResizeObserver(),this.clock.getDelta(),this.clock.getElapsedTime(),e&&(Array.isArray(e)||(e=[e]),e.forEach(a=>{Array.isArray(a)||(a=[a]),this.use(a[0],a[1])}))}getPlugin(t){return this.installPlugins.get(t)}get renderer(){return this.rendererController.renderer}get maxAnisotropy(){return this.options.WebGPUTHREE?0:this.renderer.capabilities.getMaxAnisotropy()}get cameraControls(){return this.controlsController.cameraControls}get cameraPositon(){return this.cameraControls.getPosition(new x.Vector3,!1)}get cameraTarget(){return this.cameraControls.getTarget(new x.Vector3,!1)}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}use(t,...e){this.installPlugins.has(t.pluginName)?console.log("plugin already installed"):typeof t.install=="function"&&(t.install(this,...e),this.installPlugins.set(t.pluginName,t))}init(){const{container:t,isdev:e,WebGPUTHREE:s,helper:i,renderer:o,scene:r,camera:a,control:l}=this.options,{width:c,height:g}=this.getSize(),_=new me({isdev:e,width:c,height:g,cameraParams:a,cameraControls:l===!0});this.gui&&_.setGui(this.gui);const C=_.camera,p=new pe({camera:C,sceneParams:r}),P=p.scene,f=s?new ce({width:c,height:g,scene:P,camera:C,isdev:e,renderer:s.WebGPURenderer,rendererParams:le}):new he({width:c,height:g,scene:P,camera:C,isdev:e,rendererParams:ht(j({},o),{antialias:!1})});if(i){const D=new ue({scene:P});D.add(P),this.helperController=D}this.sceneController=p,this.rendererController=f,this.cameraController=_,t.appendChild(f.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,multisampling:s}=this.options,i=new Oe({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:{multisampling:s}});this.composerController=i,t&&(i.addBloomPass(e),this.gui&&i.addBloomGui(this.gui)),i.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:s,css2DRendererParams:i,css3DRendererParams:o}=this.options;if(e||s){const r=new ye(t);e&&r.addRenderer("css2d",i),s&&r.addRenderer("css3d",o),this.cssRendererController=r}}initControls(){const{control:t,controlParams:e,transformControls:s}=this.options;if(t){const i=new fe({camera:this.camera,controlsParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControl:typeof t=="boolean"?void 0:t});this.controlsController=i}if(s){const i=new ge({camera:this.camera,renderer:this.renderer,scene:this.scene});i.event.on("mouseDown",()=>{var o;(o=this.controlsController)==null||o.disable()}),i.event.on("mouseUp",()=>{var o;(o=this.controlsController)==null||o.enable()}),this.transformController=i}}getSize(){const{container:t}=this.options;return{width:t.offsetWidth,height:t.offsetHeight}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=this.getSize(),s=new ResizeObserver(i=>{for(const o of i){const r=o.contentRect;(r.width!==e.width||r.height!==e.height)&&(e.width=r.width,e.height=r.height,this.handeleResize(r.width,r.height),this.render())}});s.observe(t),this.resizeObserver=s}handeleResize(t,e,s=!0){const{rendererController:i,cameraController:o,composerController:r,cssRendererController:a}=this;o==null||o.setSize(t,e),i==null||i.setSize(t,e),r==null||r.setSize(t,e),a==null||a.setSize(t,e),this.installPlugins.forEach(l=>{var c;(c=l.setSize)==null||c.call(l,t,e)}),s&&this.event.emit("resize",{width:t,height:e})}pick(t,e,s=!1){const{raycaster:i,options:o}=this,{container:r}=o,a=new x.Vector2,l=r.getBoundingClientRect();if(a.x=(t.clientX-l.left)/(l.right-l.left)*2-1,a.y=-((t.clientY-l.top)/(l.bottom-l.top))*2+1,this.camera&&this.scene){i.setFromCamera(a,this.camera);const c=i.intersectObjects(e||this.scene.children,s);if(c.length)return{object:c[0].object,intersects:c}}}render(){var r,a,l,c,g,_;const{scene:t,camera:e,clock:s}=this,i=s.getDelta(),o=s.getElapsedTime();Et.update(),(r=this.controlsController)==null||r.update(i),this.installPlugins.forEach(C=>{var p;(p=C.update)==null||p.call(C,i,o)}),(a=this.helperController)==null||a.update(),this.cameraController.syncCamera&&!(this.camera.matrixWorld.equals(this.cameraController.syncCamera.matrixWorld)&&this.camera.far===this.cameraController.syncCamera.far&&this.camera.near===this.cameraController.syncCamera.near&&this.camera.fov===this.cameraController.syncCamera.fov&&this.camera.aspect===this.cameraController.syncCamera.aspect)&&this.camera.copy(this.cameraController.syncCamera),(l=this.composerController)!=null&&l.active?this.cameraController.camera2?(this.composerController.resetRenderPassCamera(),this.setViewportFull(),this.composerController.render(),this.pipViewportState&&(this.setViewportPip(),this.composerController.setRenderPassCamera(this.cameraController.camera2),this.composerController.render())):this.composerController.render():(c=this.rendererController)==null||c.render(),(g=this.cssRendererController)==null||g.render(t,e),(_=this.stats)==null||_.update(),this.event.emit("render",{delta:i,elapsed:o})}start(){this.renderer.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){this.renderer.setAnimationLoop(null),this.event.emit("stop")}autoRotate(t){this.controlsController.autoRotateSpeed=t}showPipViewport(t){if(t===!0){const e=this.getSize(),s=240,i=s/e.width,o=s/e.height,r=1-i,a=1-o;t={left:r,top:a,width:i,height:o}}if(this.pipViewportState=t,t){if(this.controlsController.cameraControls2)this.controlsController.cameraControls2.enabled=!0,this.cameraController.camera2.position.copy(this.cameraController.camera.position);else{const e=this.cameraController.addCamera2();this.controlsController.addCameraControls2(e)}this.controlsController.cameraControls2.interactiveArea=new DOMRect(t.left,t.top,t.width,t.height)}else this.controlsController.cameraControls2&&(this.controlsController.cameraControls2.enabled=!1)}setViewportFull(){const t=this.getSize(),e=0,s=0,i=t.width,o=t.height,r=i/o;this.camera.aspect!==r&&(this.camera.aspect=r,this.camera.updateProjectionMatrix()),this.renderer.setViewport(e,s,i,o),this.renderer.setScissor(e,s,i,o),this.renderer.setScissorTest(!0)}setViewportPip(){if(!this.pipViewportState)return;const t=this.pipViewportState,e=this.getSize(),s=e.width*t.left,i=(1-(t.top+t.height))*e.height,o=e.width*t.width,r=e.height*t.height,a=o/r,l=this.cameraController.camera2;l&&l.aspect!==a&&(l.aspect=a,l.updateProjectionMatrix()),this.renderer.setViewport(s,i,o,r),this.renderer.setScissor(s,i,o,r),this.renderer.setScissorTest(!0)}dispose(){var t,e,s,i,o,r,a,l,c,g,_;this.stop(),Et.removeAll(),this.event.removeAllListeners(),(t=this.resizeObserver)==null||t.unobserve(this.options.container),this.installPlugins.forEach(C=>{var p;(p=C.dispose)==null||p.call(C)}),(e=this.controlsController)==null||e.dispose(),(s=this.transformController)==null||s.dispose(),(i=this.cssRendererController)==null||i.dispose(),(o=this.sceneController)==null||o.dispose(),(r=this.helperController)==null||r.dispose(),(a=this.composerController)==null||a.dispose(),(l=this.rendererController)==null||l.dispose(),this.cssRendererController=void 0,(c=this.gui)==null||c.destroy(),this.installPlugins.clear(),(g=this.stats)==null||g.dom.remove(),(_=this.renderer)==null||_.domElement.remove()}};nt.options={isdev:J,stats:J,gui:J,helper:J,control:!0,transformControls:J,resizeObserver:!0,renderer:ae,multisampling:4,scene:_e,camera:de,bloom:!1,bloomParams:Ee,css2DRenderer:!1,css2DRendererParams:j({},Ut),css3DRenderer:!1,css3DRendererParams:j({},Ut)};let rt=nt;const Te=Y.ACTION;exports.BaseObject=oe.BaseObject;exports.GUIObject=ft;exports.Pencil=rt;exports.cameraControlsAction=Te;exports.default=rt;
14
+ `,defines:{}}),"baseTexture");l.needsSwap=!0,this.bloomComposer=a,this.finalComposer.addPass(l),this.mixPass=l,this.bloomLayer.set(ut)}addBloomGui(t){if(!this.bloomComposer)return;new ft({bloom:{threshold:{min:0,max:1,step:.01,target:()=>this.bloomPass},radius:{min:0,max:1,step:.001,target:()=>this.bloomPass},strength:{min:0,max:10,step:.001,target:()=>this.bloomPass}}}).showGui(t)}toggleBloomSelection(t,e){if(!this.bloomComposer){console.warn("err:pencil.options.bloom");return}const{object3d:s}=t;if(!s)return;let i=e;e===void 0&&(i=!this.bloomSelection.has(s)),i?(this.bloomSelection.add(s),s.layers.enable(ut)):(this.bloomSelection.delete(s),s.layers.disable(ut)),this.bloomSelection.size===0?this.bloomComposerActive=!1:this.bloomComposerActive=!0}enable(){this.active||(this.active=!0)}disable(){this.active&&(this.active=!1)}setSize(t,e){var s;(s=this.bloomComposer)==null||s.setSize(t,e),this.finalComposer.setSize(t,e)}render(){this.active&&(this.bloomComposerActive&&this.bloomComposer?(this.mixPass.enabled=!0,this.scene.traverse(t=>{const e=t;e.isMesh&&this.bloomLayer.test(e.layers)===!1&&(this.bloomMaterials[e.uuid]=e.material,e.material=Ce)}),this.bloomComposer.render(),this.scene.traverse(t=>{const e=t;this.bloomMaterials[e.uuid]&&(e.material=this.bloomMaterials[e.uuid],delete this.bloomMaterials[e.uuid])})):this.mixPass&&(this.mixPass.enabled=!1),this.finalComposer.render())}render2(){this.active}dispose(){var t;this.bloomMaterials={},this.bloomSelection.clear(),this.finalComposer.dispose(),(t=this.bloomComposer)==null||t.dispose()}}const nt=class nt{constructor(t,e){this.raycaster=new x.Raycaster,this.installPlugins=new Map,this.event=new bt.eventsExports.EventEmitter,this.clock=new x.Clock,this.userData={},this.pipViewportState=!1,this.options=Nt(nt.options,t,{isMergeableObject:ie.isPlainObject}),this.event.setMaxListeners(1/0);const{container:s,stats:i,gui:o,resizeObserver:r}=this.options;if(o){const a=new jt;a.open(!1),this.gui=a}if(this.init(),i){const a=new qt({horizontal:!1});a.init(this.renderer),s.appendChild(a.dom),this.stats=a}this.options.WebGPUTHREE||this.initComposer(),this.initCSSRenderer(),this.initControls(),r&&this.initResizeObserver(),this.clock.getDelta(),this.clock.getElapsedTime(),e&&(Array.isArray(e)||(e=[e]),e.forEach(a=>{Array.isArray(a)||(a=[a]),this.use(a[0],a[1])}))}getPlugin(t){return this.installPlugins.get(t)}get renderer(){return this.rendererController.renderer}get maxAnisotropy(){return this.options.WebGPUTHREE?0:this.renderer.capabilities.getMaxAnisotropy()}get cameraControls(){return this.controlsController.cameraControls}get cameraPositon(){return this.cameraControls.getPosition(new x.Vector3,!1)}get cameraTarget(){return this.cameraControls.getTarget(new x.Vector3,!1)}get camera(){return this.cameraController.camera}get scene(){return this.sceneController.scene}use(t,...e){this.installPlugins.has(t.pluginName)?console.log("plugin already installed"):typeof t.install=="function"&&(t.install(this,...e),this.installPlugins.set(t.pluginName,t))}init(){const{container:t,isdev:e,WebGPUTHREE:s,helper:i,renderer:o,scene:r,camera:a,control:l}=this.options,{width:c,height:g}=this.getSize(),_=new me({isdev:e,width:c,height:g,cameraParams:a,cameraControls:l===!0});this.gui&&_.setGui(this.gui);const C=_.camera,p=new pe({camera:C,sceneParams:r}),P=p.scene,f=s?new ce({width:c,height:g,scene:P,camera:C,isdev:e,renderer:s.WebGPURenderer,rendererParams:le}):new he({width:c,height:g,scene:P,camera:C,isdev:e,rendererParams:ht(j({},o),{antialias:!1})});if(i){const D=new ue({scene:P});D.add(P),this.helperController=D}this.sceneController=p,this.rendererController=f,this.cameraController=_,t.appendChild(f.renderer.domElement)}initComposer(){const{bloom:t,bloomParams:e,multisampling:s}=this.options,i=new Oe({renderer:this.renderer,scene:this.scene,camera:this.camera,composerParams:{multisampling:s}});this.composerController=i,t&&(i.addBloomPass(e),this.gui&&i.addBloomGui(this.gui)),i.addOutputPass()}initCSSRenderer(){const{container:t,css2DRenderer:e,css3DRenderer:s,css2DRendererParams:i,css3DRendererParams:o}=this.options;if(e||s){const r=new ye(t);e&&r.addRenderer("css2d",i),s&&r.addRenderer("css3d",o),this.cssRendererController=r}}initControls(){const{control:t,controlParams:e,transformControls:s}=this.options;if(t){const i=new fe({camera:this.camera,controlsParams:{domElement:(e==null?void 0:e.domElement)||this.renderer.domElement},customControl:typeof t=="boolean"?void 0:t});this.controlsController=i}if(s){const i=new ge({camera:this.camera,renderer:this.renderer,scene:this.scene});i.event.on("mouseDown",()=>{var o;(o=this.controlsController)==null||o.disable()}),i.event.on("mouseUp",()=>{var o;(o=this.controlsController)==null||o.enable()}),this.transformController=i}}getSize(){const{container:t}=this.options;return{width:t.offsetWidth,height:t.offsetHeight}}initResizeObserver(){const{container:t}=this.options;if(this.resizeObserver)return;const e=this.getSize(),s=new ResizeObserver(i=>{for(const o of i){const r=o.contentRect;(r.width!==e.width||r.height!==e.height)&&(e.width=r.width,e.height=r.height,this.handeleResize(r.width,r.height),this.render())}});s.observe(t),this.resizeObserver=s}handeleResize(t,e,s=!0){const{rendererController:i,cameraController:o,composerController:r,cssRendererController:a}=this;o==null||o.setSize(t,e),i==null||i.setSize(t,e),r==null||r.setSize(t,e),a==null||a.setSize(t,e),this.installPlugins.forEach(l=>{var c;(c=l.setSize)==null||c.call(l,t,e)}),s&&this.event.emit("resize",{width:t,height:e})}pick(t,e,s=!0){const{raycaster:i,options:o}=this,{container:r}=o,a=new x.Vector2,l=r.getBoundingClientRect();if(a.x=(t.clientX-l.left)/(l.right-l.left)*2-1,a.y=-((t.clientY-l.top)/(l.bottom-l.top))*2+1,this.camera&&this.scene){i.setFromCamera(a,this.camera);const c=i.intersectObjects(e||this.scene.children,s);if(c.length)return{object:c[0].object,intersects:c}}}render(){var r,a,l,c,g,_;const{scene:t,camera:e,clock:s}=this,i=s.getDelta(),o=s.getElapsedTime();Et.update(),(r=this.controlsController)==null||r.update(i),this.installPlugins.forEach(C=>{var p;(p=C.update)==null||p.call(C,i,o)}),(a=this.helperController)==null||a.update(),this.cameraController.syncCamera&&!(this.camera.matrixWorld.equals(this.cameraController.syncCamera.matrixWorld)&&this.camera.far===this.cameraController.syncCamera.far&&this.camera.near===this.cameraController.syncCamera.near&&this.camera.fov===this.cameraController.syncCamera.fov&&this.camera.aspect===this.cameraController.syncCamera.aspect)&&this.camera.copy(this.cameraController.syncCamera),(l=this.composerController)!=null&&l.active?this.cameraController.camera2?(this.composerController.resetRenderPassCamera(),this.setViewportFull(),this.composerController.render(),this.pipViewportState&&(this.setViewportPip(),this.composerController.setRenderPassCamera(this.cameraController.camera2),this.composerController.render())):this.composerController.render():(c=this.rendererController)==null||c.render(),(g=this.cssRendererController)==null||g.render(t,e),(_=this.stats)==null||_.update(),this.event.emit("render",{delta:i,elapsed:o})}start(){this.renderer.setAnimationLoop(this.render.bind(this)),this.event.emit("start")}stop(){this.renderer.setAnimationLoop(null),this.event.emit("stop")}autoRotate(t){this.controlsController.autoRotateSpeed=t}showPipViewport(t){if(t===!0){const e=this.getSize(),s=240,i=s/e.width,o=s/e.height,r=1-i,a=1-o;t={left:r,top:a,width:i,height:o}}if(this.pipViewportState=t,t){if(this.controlsController.cameraControls2)this.controlsController.cameraControls2.enabled=!0,this.cameraController.camera2.position.copy(this.cameraController.camera.position);else{const e=this.cameraController.addCamera2();this.controlsController.addCameraControls2(e)}this.controlsController.cameraControls2.interactiveArea=new DOMRect(t.left,t.top,t.width,t.height)}else this.controlsController.cameraControls2&&(this.controlsController.cameraControls2.enabled=!1)}setViewportFull(){const t=this.getSize(),e=0,s=0,i=t.width,o=t.height,r=i/o;this.camera.aspect!==r&&(this.camera.aspect=r,this.camera.updateProjectionMatrix()),this.renderer.setViewport(e,s,i,o),this.renderer.setScissor(e,s,i,o),this.renderer.setScissorTest(!0)}setViewportPip(){if(!this.pipViewportState)return;const t=this.pipViewportState,e=this.getSize(),s=e.width*t.left,i=(1-(t.top+t.height))*e.height,o=e.width*t.width,r=e.height*t.height,a=o/r,l=this.cameraController.camera2;l&&l.aspect!==a&&(l.aspect=a,l.updateProjectionMatrix()),this.renderer.setViewport(s,i,o,r),this.renderer.setScissor(s,i,o,r),this.renderer.setScissorTest(!0)}dispose(){var t,e,s,i,o,r,a,l,c,g,_;this.stop(),Et.removeAll(),this.event.removeAllListeners(),(t=this.resizeObserver)==null||t.unobserve(this.options.container),this.installPlugins.forEach(C=>{var p;(p=C.dispose)==null||p.call(C)}),(e=this.controlsController)==null||e.dispose(),(s=this.transformController)==null||s.dispose(),(i=this.cssRendererController)==null||i.dispose(),(o=this.sceneController)==null||o.dispose(),(r=this.helperController)==null||r.dispose(),(a=this.composerController)==null||a.dispose(),(l=this.rendererController)==null||l.dispose(),this.cssRendererController=void 0,(c=this.gui)==null||c.destroy(),this.installPlugins.clear(),(g=this.stats)==null||g.dom.remove(),(_=this.renderer)==null||_.domElement.remove()}};nt.options={isdev:J,stats:J,gui:J,helper:J,control:!0,transformControls:J,resizeObserver:!0,renderer:ae,multisampling:4,scene:_e,camera:de,bloom:!1,bloomParams:Ee,css2DRenderer:!1,css2DRendererParams:j({},Ut),css3DRenderer:!1,css3DRendererParams:j({},Ut)};let rt=nt;const Te=Y.ACTION;exports.BaseObject=oe.BaseObject;exports.GUIObject=ft;exports.Pencil=rt;exports.cameraControlsAction=Te;exports.default=rt;
@@ -2433,7 +2433,7 @@ const rt = class rt {
2433
2433
  (c = l.setSize) == null || c.call(l, t, e);
2434
2434
  }), s && this.event.emit("resize", { width: t, height: e });
2435
2435
  }
2436
- pick(t, e, s = !1) {
2436
+ pick(t, e, s = !0) {
2437
2437
  const { raycaster: i, options: o } = this, { container: r } = o, a = new x.Vector2(), l = r.getBoundingClientRect();
2438
2438
  if (a.x = (t.clientX - l.left) / (l.right - l.left) * 2 - 1, a.y = -((t.clientY - l.top) / (l.bottom - l.top)) * 2 + 1, this.camera && this.scene) {
2439
2439
  i.setFromCamera(a, this.camera);
@@ -55,6 +55,11 @@ export default class Draw<T extends {
55
55
  showPrefab(key?: string): void;
56
56
  hidePrefab(): void;
57
57
  eraseAll(): void;
58
+ private pickFunctionsArr;
59
+ private pickListener;
60
+ private addPickListener;
61
+ handlePick(objArr: Draw<any>['pickFunctionsArr'][0]['objArr'], t: Draw<any>['pickFunctionsArr'][0]['type'], cb: Draw<any>['pickFunctionsArr'][0]['cb']): number;
62
+ removePick(index: number): void;
58
63
  dispose(): void;
59
64
  }
60
65
  export {};