gl-draw 0.9.0-beta.76 → 0.9.0-beta.78

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.
@@ -10,17 +10,18 @@ export declare const KNOWN_ASSET_TYPES: {
10
10
  gltf: string[];
11
11
  };
12
12
  export default class Loader {
13
+ loadingManager: THREE.LoadingManager;
13
14
  textureLoader: THREE.TextureLoader;
14
15
  videoTextureLoader: VideoTextureLoader;
15
16
  gltfLoader: GLTFLoader;
16
- gltfDracoLoader: GLTFLoader;
17
+ dracoGltfLoader?: GLTFLoader;
17
18
  dracoLoader?: DRACOLoader;
18
- loadingManager?: THREE.LoadingManager;
19
+ dracoPath?: string;
19
20
  loadObj: {
20
21
  texture: string[];
21
22
  videoTexture: string[];
22
23
  gltf: string[];
23
- dracGltf: string[];
24
+ dracoGltf: string[];
24
25
  };
25
26
  assets: Map<string, THREE.Texture>;
26
27
  gltfAssets: Map<string, THREE.Object3D<THREE.Event>>;
@@ -34,14 +35,14 @@ export default class Loader {
34
35
  resolve: (value?: any) => void;
35
36
  reject: (value?: any) => void;
36
37
  };
37
- setDecoderPath(path: string): void;
38
38
  setItem(src: string | string[], options?: {
39
- dracoPath: string;
39
+ dracoPath?: string;
40
40
  }): void;
41
41
  load(): Promise<any>;
42
42
  loadTexture(srcArr: string[]): void;
43
43
  colorCorrection(): void;
44
44
  loadVideoTexture(srcArr: string[]): void;
45
- loadGltf(srcArr: string[], draco?: boolean): void;
45
+ loadGltf(srcArr: string[]): void;
46
+ loadDracoGltf(srcArr: string[]): void;
46
47
  dispose(): void;
47
48
  }
@@ -1 +1 @@
1
- "use strict";var T=Object.defineProperty;var v=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable;var j=(r,e,t)=>e in r?T(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,L=(r,e)=>{for(var t in e||(e={}))k.call(e,t)&&j(r,t,e[t]);if(v)for(var t of v(e))O.call(e,t)&&j(r,t,e[t]);return r};var u=(r,e,t)=>new Promise((s,o)=>{var a=n=>{try{c(t.next(n))}catch(h){o(h)}},i=n=>{try{c(t.throw(n))}catch(h){o(h)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(a,i);c((t=t.apply(r,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("esus-lite"),M=require("three"),p=require("idb-keyval"),x=require("../events.js"),y=require("three/examples/jsm/loaders/GLTFLoader"),D=require("three/examples/jsm/loaders/DRACOLoader"),b=require("../colorCorrection.js");function C(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const l=C(M);class R{constructor(){this.cache=new Map}install(){}init(e){const t=E.makePromiseCreator();this.cache.set(e,t)}get(e,t){return u(this,null,function*(){if(!this.cache.get(e)&&t){this.init(e);const s=yield t();this.set(e,s)}if(this.cache.get(e))return yield this.cache.get(e).promise})}set(e,t){const s=this.cache.get(e);s?s.resolve(t):console.warn("init cache first")}dispose(){this.cache.forEach((e,t)=>{e.reject(`stop set cache:${t}`)}),this.cache.clear()}}class S{constructor(e){this.onTopBase=new Map,this.objectNamesToFactories=new Map,this.objects=new Map,this.objects_=e}get objectsPromise(){const e=[];return this.objects.forEach(t=>{e.push(t.pm.promise)}),e}install(e){this.pencil=e,this.initObjectFactories()}initObjectFactories(){const{objects_:e}=this;Object.keys(e).forEach(t=>{const s=class{create(a={}){return new e[t](a)}};this.objectNamesToFactories.set(t,s)})}getObject(e,t){e.includes("#")&&console.warn("getObject:err:不支持 #",e);const{key:s}=t||{},o=`${e}${s?`#${s}`:""}`;return this.objects.get(o)}getAllObject(e,t){e.includes("#")&&console.warn("getAllObject:err:不支持 #",e);const{key:s}=t||{},o=`${e}${s?`#${s}`:""}`,a=[];return this.objects.forEach((i,c)=>{(c.startsWith(`${o}#`)||c===o)&&a.push(i)}),a}draw(e,t,s){return u(this,null,function*(){const o=this.objectNamesToFactories.get(e);if(o){const{key:a}=t||{};let i=`${e}${a?`#${a}`:""}`;if(this.objects.has(i)){const f=l.MathUtils.generateUUID();i+=`#${f}`}const c=(t==null?void 0:t.target)||s,n=(t==null?void 0:t.onTop)||0;let h;typeof c=="string"?h=this.objects.get(c):(c==null?void 0:c.objecttype__)==="BaseObject"?h=c:this.group?h=this.group:h=this.pencil.scene;const d=new o().create(t);return d.pencil=this.pencil,d.key=i,this.objects.set(i,d),yield this.addMesh(d,h,n),d}throw new Error(`Unrecognized:${e}`)})}addMesh(e,t,s){return u(this,null,function*(){if(yield e.create(),e.object3d){if(e.object3d.userData.BaseObject_=e,s)if(e.type_==="node")e.object3d.renderOrder=s;else{const o=1e3+s*2,a=`${o-1}`;if(!this.onTopBase.has(a)){const i=new l.Points(void 0,new l.PointsMaterial({transparent:!0,opacity:0}));i.renderOrder=o-1,i.onBeforeRender=()=>{this.pencil.renderer.clearDepth()},i.frustumCulled=!1,this.onTopBase.set(a,!0),this.pencil.scene.add(i)}e.object3d.renderOrder=o}t.add(e.object3d)}e.visible=!0,e.render(),e.pm.resolve()})}erase(...e){[...e].forEach(t=>{const s=[];if(typeof t=="string"){const[o,a]=t.split("#");s.push(...this.getAllObject(o,{key:a}))}else s.push(t);s.forEach(o=>{this.removeMesh(o)})})}removeMesh(e){const{parent:t}=e;e.object3d&&t.remove(e.object3d),e.traverse(s=>{s.visible=!1,s.dispose(),this.objects.delete(s.key)})}update(e,t){this.objects.forEach(s=>{s.update(e,t)})}setSize(e,t){this.objects.forEach(s=>{s.resize(e,t)})}show(){var e;(e=this.group)==null||e.show()}hide(){var e;(e=this.group)==null||e.hide()}dispose(){this.group=void 0,this.objects.forEach((e,t)=>{e.dispose(),e.pm.reject(`stop draw:${t}`)}),this.objects.clear(),this.onTopBase.clear(),this.objectNamesToFactories.clear()}}class U{constructor(){this.data={}}install(){}setData(e,t){var s;this.data[e]=t,(s=this.cb)==null||s.call(this,e)}runAll(){Object.keys(this.data).forEach(e=>{var t;(t=this.cb)==null||t.call(this,e)})}runType(e){var t;this.data[e]!==void 0&&((t=this.cb)==null||t.call(this,e))}dispose(){this.data={},this.cb=void 0}}class ${constructor(e={}){this.messageList=[],this.options=L({cache:!1,cacheVersion:"1"},e)}install(e,t){if(!t)return;const{scriptURL:s,length:o}=t;this.init(s,o)}init(e,t){let{cache:s,cacheVersion:o}=this.options;this.workerList=Array.from({length:t},(a,i)=>{const c=typeof e=="string"?new Worker(e):e();return c.onmessage=({data:{res:n,uuid:h}})=>{var f,w;const d=this.messageList.find(({uuid:g})=>h===g);if(d==null||d.options.cb(n),this.workerList[i].inUse=!1,this.checkMessage(),s=(f=d==null?void 0:d.options.cache)!=null?f:s,o=(w=d==null?void 0:d.options.cacheVersion)!=null?w:o,s){const g=o;p.set(h,{[g]:n})}},{worker:c,inUse:!1}})}postMessage(e,t){var i,c;let{cache:s,cacheVersion:o}=this.options;if(s=(i=t.cache)!=null?i:s,o=(c=t.cacheVersion)!=null?c:o,s&&!e.workerKey){console.warn("worker cache need workerKey");return}if(s&&e.workerKey&&e.delCache){console.warn(`worker cache del: ${e.workerKey}`),p.del(e.workerKey);return}const a=e.workerKey||l.MathUtils.generateUUID();(s?p.get(a):Promise.resolve()).then(n=>{const h=o;n&&n[h]?t.cb(n[h]):(this.messageList.push({req:e,options:t,uuid:a,inUse:!1}),this.checkMessage())}).catch(()=>{console.warn("err:worker cache"),this.messageList.push({req:e,options:t,uuid:a,inUse:!1}),this.checkMessage()})}checkMessage(){const e=this.workerList.find(({inUse:t})=>!t);if(e){const t=this.messageList.find(({inUse:s})=>!s);t&&(t.inUse=!0,e.inUse=!0,e.worker.postMessage({req:t.req,uuid:t.uuid}))}}dispose(){this.workerList.forEach(({worker:e})=>{e.terminate()}),this.workerList=[],this.messageList=[]}}class P{constructor(){this.chunks=[]}install(e){this.pencil=e,this.canvas=e.renderer.domElement}init({frameRequestRate:e=60}={}){const t=this.canvas.captureStream(e),s=new MediaRecorder(t,{mimeType:"video/webm; codecs=vp9"});this.mediaRecorder=s,s.ondataavailable=o=>{this.chunks.push(o.data)},s.onstop=()=>{this.handleStop()}}handleStop(){const e=new Blob(this.chunks,{type:"video/webm"}),t=URL.createObjectURL(e),s=document.createElement("a");s.style.display="none",s.href=t,s.download="video.webm",document.body.appendChild(s),s.click(),setTimeout(()=>{URL.revokeObjectURL(t),document.body.removeChild(s)},0)}start(e){this.mediaRecorder.start(e)}stop(){this.mediaRecorder.stop()}dispose(){this.chunks=[]}}class A extends l.Loader{constructor(e){super(e)}load(e,t,s,o){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const a=document.createElement("video"),i=new l.VideoTexture(a);i.needsUpdate=!0;const c=()=>{h(),t&&t(i),this.manager.itemEnd(e)},n=d=>{h(),o&&o(d),this.manager.itemEnd(e),this.manager.itemError(e)},h=()=>{a.removeEventListener("canplaythrough",c,!1),a.removeEventListener("error",n,!1)};return a.addEventListener("canplaythrough",c,!1),a.addEventListener("error",n,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(a.crossOrigin=this.crossOrigin),this.manager.itemStart(e),a.src=e,a.preload="auto",a.autoplay=!1,a.loop=!1,a.muted=!0,a.load(),a.setAttribute("webkit-playsinline","webkit-playsinline"),a.setAttribute("playsinline",""),i}}const m={images:["png","jpg","jpeg","gif","svg","ico","webp","avif"],media:["mp4","webm","ogg","mp3","wav","flac","aac"],gltf:["gltf","glb"]};class _{constructor(){this.textureLoader=new l.TextureLoader,this.videoTextureLoader=new A,this.gltfLoader=new y.GLTFLoader,this.gltfDracoLoader=new y.GLTFLoader,this.loadObj={texture:[],videoTexture:[],gltf:[],dracGltf:[]},this.assets=new Map,this.gltfAssets=new Map,this.event=new x.eventsExports.EventEmitter}emit(e,...t){this.event.emit(e,...t)}on(e,t){this.event.on(e,t)}install(e){this.pencil=e,this.colorCorrection()}initLoadingManager(){const e=E.makePromiseCreator(!0);return this.loadingManager=new l.LoadingManager,this.textureLoader.manager=this.loadingManager,this.videoTextureLoader.manager=this.loadingManager,this.gltfLoader.manager=this.loadingManager,this.gltfDracoLoader.manager=this.loadingManager,this.loadingManager.onProgress=(t,s,o)=>{s===o&&e.resolve(),this.emit("progress",s,o,t)},this.loadingManager.onError=t=>{console.log("There was an error loading "+t),e.reject()},e}setDecoderPath(e){this.dracoLoader=new D.DRACOLoader,this.dracoLoader.setDecoderPath(e),this.gltfDracoLoader.setDRACOLoader(this.dracoLoader)}setItem(e,t){typeof e=="string"&&(e=[e]);const{dracoPath:s}=t||{};s&&this.setDecoderPath(s),e.forEach(o=>{const a=o.split(".").pop();m.images.includes(a)?this.loadObj.texture.push(o):m.media.includes(a)?this.loadObj.videoTexture.push(o):m.gltf.includes(a)&&(s?this.loadObj.dracGltf.push(o):this.loadObj.gltf.push(o))})}load(){const e=this.initLoadingManager();return this.loadTexture(this.loadObj.texture),this.loadVideoTexture(this.loadObj.videoTexture),this.loadGltf(this.loadObj.gltf),this.loadGltf(this.loadObj.dracGltf,!0),e.promise}loadTexture(e){this.loadObj.texture.push(...e),e.forEach(t=>u(this,null,function*(){const s=yield this.textureLoader.loadAsync(t);this.assets.set(t,s)}))}colorCorrection(){(+l.REVISION<152&&this.pencil.options.renderer.outputEncoding===b.TextureEncoding.sRGB||+l.REVISION>=152&&this.pencil.options.renderer.outputColorSpace===b.ColorSpace.sRGB)&&this.assets.forEach(e=>{b.colorCorrection({texture:e})})}loadVideoTexture(e){this.loadObj.videoTexture.push(...e),e.forEach(t=>u(this,null,function*(){this.videoTextureLoader.load(t,s=>{this.assets.set(t,s)})}))}loadGltf(e,t){this.loadObj[t?"dracGltf":"gltf"].push(...e),e.forEach(s=>u(this,null,function*(){const o=yield this[t?"gltfDracoLoader":"gltfLoader"].loadAsync(s);this.gltfAssets.set(s,o.scene)}))}dispose(){var e;this.assets.clear(),this.gltfAssets.clear(),(e=this.dracoLoader)==null||e.dispose()}}exports.Cache=R;exports.CanvasStream=P;exports.Data=U;exports.Draw=S;exports.Loader=_;exports.Wk=$;
1
+ "use strict";var k=Object.defineProperty;var v=Object.getOwnPropertySymbols;var T=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var j=(a,e,t)=>e in a?k(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,L=(a,e)=>{for(var t in e||(e={}))T.call(e,t)&&j(a,t,e[t]);if(v)for(var t of v(e))M.call(e,t)&&j(a,t,e[t]);return a};var f=(a,e,t)=>new Promise((s,o)=>{var r=n=>{try{c(t.next(n))}catch(h){o(h)}},i=n=>{try{c(t.throw(n))}catch(h){o(h)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(r,i);c((t=t.apply(a,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("esus-lite"),O=require("three"),g=require("idb-keyval"),x=require("../events.js"),y=require("three/examples/jsm/loaders/GLTFLoader"),A=require("three/examples/jsm/loaders/DRACOLoader"),b=require("../colorCorrection.js");function C(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const l=C(O);class R{constructor(){this.cache=new Map}install(){}init(e){const t=E.makePromiseCreator();this.cache.set(e,t)}get(e,t){return f(this,null,function*(){if(!this.cache.get(e)&&t){this.init(e);const s=yield t();this.set(e,s)}if(this.cache.get(e))return yield this.cache.get(e).promise})}set(e,t){const s=this.cache.get(e);s?s.resolve(t):console.warn("init cache first")}dispose(){this.cache.forEach((e,t)=>{e.reject(`stop set cache:${t}`)}),this.cache.clear()}}class P{constructor(e){this.onTopBase=new Map,this.objectNamesToFactories=new Map,this.objects=new Map,this.objects_=e}get objectsPromise(){const e=[];return this.objects.forEach(t=>{e.push(t.pm.promise)}),e}install(e){this.pencil=e,this.initObjectFactories()}initObjectFactories(){const{objects_:e}=this;Object.keys(e).forEach(t=>{const s=class{create(r={}){return new e[t](r)}};this.objectNamesToFactories.set(t,s)})}getObject(e,t){e.includes("#")&&console.warn("getObject:err:不支持 #",e);const{key:s}=t||{},o=`${e}${s?`#${s}`:""}`;return this.objects.get(o)}getAllObject(e,t){e.includes("#")&&console.warn("getAllObject:err:不支持 #",e);const{key:s}=t||{},o=`${e}${s?`#${s}`:""}`,r=[];return this.objects.forEach((i,c)=>{(c.startsWith(`${o}#`)||c===o)&&r.push(i)}),r}draw(e,t,s){return f(this,null,function*(){const o=this.objectNamesToFactories.get(e);if(o){const{key:r}=t||{};let i=`${e}${r?`#${r}`:""}`;if(this.objects.has(i)){const u=l.MathUtils.generateUUID();i+=`#${u}`}const c=(t==null?void 0:t.target)||s,n=(t==null?void 0:t.onTop)||0;let h;typeof c=="string"?h=this.objects.get(c):(c==null?void 0:c.objecttype__)==="BaseObject"?h=c:this.group?h=this.group:h=this.pencil.scene;const d=new o().create(t);return d.pencil=this.pencil,d.key=i,this.objects.set(i,d),yield this.addMesh(d,h,n),d}throw new Error(`Unrecognized:${e}`)})}addMesh(e,t,s){return f(this,null,function*(){if(yield e.create(),e.object3d){if(e.object3d.userData.BaseObject_=e,s)if(e.type_==="node")e.object3d.renderOrder=s;else{const o=1e3+s*2,r=`${o-1}`;if(!this.onTopBase.has(r)){const i=new l.Points(void 0,new l.PointsMaterial({transparent:!0,opacity:0}));i.renderOrder=o-1,i.onBeforeRender=()=>{this.pencil.renderer.clearDepth()},i.frustumCulled=!1,this.onTopBase.set(r,!0),this.pencil.scene.add(i)}e.object3d.renderOrder=o}t.add(e.object3d)}e.visible=!0,e.render(),e.pm.resolve()})}erase(...e){[...e].forEach(t=>{const s=[];if(typeof t=="string"){const[o,r]=t.split("#");s.push(...this.getAllObject(o,{key:r}))}else s.push(t);s.forEach(o=>{this.removeMesh(o)})})}removeMesh(e){const{parent:t}=e;e.object3d&&t.remove(e.object3d),e.traverse(s=>{s.visible=!1,s.dispose(),this.objects.delete(s.key)})}update(e,t){this.objects.forEach(s=>{s.update(e,t)})}setSize(e,t){this.objects.forEach(s=>{s.resize(e,t)})}show(){var e;(e=this.group)==null||e.show()}hide(){var e;(e=this.group)==null||e.hide()}dispose(){this.group=void 0,this.objects.forEach((e,t)=>{e.dispose(),e.pm.reject(`stop draw:${t}`)}),this.objects.clear(),this.onTopBase.clear(),this.objectNamesToFactories.clear()}}class S{constructor(){this.data={}}install(){}setData(e,t){var s;this.data[e]=t,(s=this.cb)==null||s.call(this,e)}runAll(){Object.keys(this.data).forEach(e=>{var t;(t=this.cb)==null||t.call(this,e)})}runType(e){var t;this.data[e]!==void 0&&((t=this.cb)==null||t.call(this,e))}dispose(){this.data={},this.cb=void 0}}class U{constructor(e={}){this.messageList=[],this.options=L({cache:!1,cacheVersion:"1"},e)}install(e,t){if(!t)return;const{scriptURL:s,length:o}=t;this.init(s,o)}init(e,t){let{cache:s,cacheVersion:o}=this.options;this.workerList=Array.from({length:t},(r,i)=>{const c=typeof e=="string"?new Worker(e):e();return c.onmessage=({data:{res:n,uuid:h}})=>{var u,m;const d=this.messageList.find(({uuid:p})=>h===p);if(d==null||d.options.cb(n),this.workerList[i].inUse=!1,this.checkMessage(),s=(u=d==null?void 0:d.options.cache)!=null?u:s,o=(m=d==null?void 0:d.options.cacheVersion)!=null?m:o,s){const p=o;g.set(h,{[p]:n})}},{worker:c,inUse:!1}})}postMessage(e,t){var i,c;let{cache:s,cacheVersion:o}=this.options;if(s=(i=t.cache)!=null?i:s,o=(c=t.cacheVersion)!=null?c:o,s&&!e.workerKey){console.warn("worker cache need workerKey");return}if(s&&e.workerKey&&e.delCache){console.warn(`worker cache del: ${e.workerKey}`),g.del(e.workerKey);return}const r=e.workerKey||l.MathUtils.generateUUID();(s?g.get(r):Promise.resolve()).then(n=>{const h=o;n&&n[h]?t.cb(n[h]):(this.messageList.push({req:e,options:t,uuid:r,inUse:!1}),this.checkMessage())}).catch(()=>{console.warn("err:worker cache"),this.messageList.push({req:e,options:t,uuid:r,inUse:!1}),this.checkMessage()})}checkMessage(){const e=this.workerList.find(({inUse:t})=>!t);if(e){const t=this.messageList.find(({inUse:s})=>!s);t&&(t.inUse=!0,e.inUse=!0,e.worker.postMessage({req:t.req,uuid:t.uuid}))}}dispose(){this.workerList.forEach(({worker:e})=>{e.terminate()}),this.workerList=[],this.messageList=[]}}class D{constructor(){this.chunks=[]}install(e){this.pencil=e,this.canvas=e.renderer.domElement}init({frameRequestRate:e=60}={}){const t=this.canvas.captureStream(e),s=new MediaRecorder(t,{mimeType:"video/webm; codecs=vp9"});this.mediaRecorder=s,s.ondataavailable=o=>{this.chunks.push(o.data)},s.onstop=()=>{this.handleStop()}}handleStop(){const e=new Blob(this.chunks,{type:"video/webm"}),t=URL.createObjectURL(e),s=document.createElement("a");s.style.display="none",s.href=t,s.download="video.webm",document.body.appendChild(s),s.click(),setTimeout(()=>{URL.revokeObjectURL(t),document.body.removeChild(s)},0)}start(e){this.mediaRecorder.start(e)}stop(){this.mediaRecorder.stop()}dispose(){this.chunks=[]}}class $ extends l.Loader{constructor(e){super(e)}load(e,t,s,o){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const r=document.createElement("video"),i=new l.VideoTexture(r);i.needsUpdate=!0;const c=()=>{h(),t&&t(i),this.manager.itemEnd(e)},n=d=>{h(),o&&o(d),this.manager.itemEnd(e),this.manager.itemError(e)},h=()=>{r.removeEventListener("canplaythrough",c,!1),r.removeEventListener("error",n,!1)};return r.addEventListener("canplaythrough",c,!1),r.addEventListener("error",n,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(r.crossOrigin=this.crossOrigin),this.manager.itemStart(e),r.src=e,r.preload="auto",r.autoplay=!1,r.loop=!1,r.muted=!0,r.load(),r.setAttribute("webkit-playsinline","webkit-playsinline"),r.setAttribute("playsinline",""),i}}const w={images:["png","jpg","jpeg","gif","svg","ico","webp","avif"],media:["mp4","webm","ogg","mp3","wav","flac","aac"],gltf:["gltf","glb"]};class G{constructor(){this.loadObj={texture:[],videoTexture:[],gltf:[],dracoGltf:[]},this.assets=new Map,this.gltfAssets=new Map,this.event=new x.eventsExports.EventEmitter}emit(e,...t){this.event.emit(e,...t)}on(e,t){this.event.on(e,t)}install(e){this.pencil=e,this.colorCorrection()}initLoadingManager(){const e=E.makePromiseCreator(!0);return this.loadingManager=new l.LoadingManager,this.textureLoader=new l.TextureLoader(this.loadingManager),this.videoTextureLoader=new $(this.loadingManager),this.gltfLoader=new y.GLTFLoader(this.loadingManager),this.dracoPath&&(this.dracoGltfLoader=new y.GLTFLoader(this.loadingManager),this.dracoLoader=new A.DRACOLoader,this.dracoLoader.setDecoderPath(this.dracoPath),this.dracoGltfLoader.setDRACOLoader(this.dracoLoader)),this.loadingManager.onProgress=(t,s,o)=>{s===o&&e.resolve(),this.emit("progress",s,o,t)},this.loadingManager.onError=t=>{console.log("There was an error loading "+t),e.reject()},e}setItem(e,t){typeof e=="string"&&(e=[e]);const{dracoPath:s}=t||{};s&&(this.dracoPath=s),e.forEach(o=>{const r=o.split(".").pop();w.images.includes(r)?this.loadObj.texture.push(o):w.media.includes(r)?this.loadObj.videoTexture.push(o):w.gltf.includes(r)&&(s?this.loadObj.dracoGltf.push(o):this.loadObj.gltf.push(o))})}load(){const e=this.initLoadingManager();return this.loadTexture(this.loadObj.texture),this.loadVideoTexture(this.loadObj.videoTexture),this.loadGltf(this.loadObj.gltf),this.dracoPath&&this.loadDracoGltf(this.loadObj.dracoGltf),e.promise}loadTexture(e){e.forEach(t=>f(this,null,function*(){const s=yield this.textureLoader.loadAsync(t);this.assets.set(t,s)}))}colorCorrection(){(+l.REVISION<152&&this.pencil.options.renderer.outputEncoding===b.TextureEncoding.sRGB||+l.REVISION>=152&&this.pencil.options.renderer.outputColorSpace===b.ColorSpace.sRGB)&&this.assets.forEach(e=>{b.colorCorrection({texture:e})})}loadVideoTexture(e){e.forEach(t=>f(this,null,function*(){this.videoTextureLoader.load(t,s=>{this.assets.set(t,s)})}))}loadGltf(e){e.forEach(t=>f(this,null,function*(){const s=yield this.gltfLoader.loadAsync(t);this.gltfAssets.set(t,s.scene)}))}loadDracoGltf(e){e.forEach(t=>f(this,null,function*(){if(!this.dracoGltfLoader)return;const s=yield this.dracoGltfLoader.loadAsync(t);this.gltfAssets.set(t,s.scene)}))}dispose(){var e;this.assets.clear(),this.gltfAssets.clear(),(e=this.dracoLoader)==null||e.dispose(),this.event.removeAllListeners()}}exports.Cache=R;exports.CanvasStream=D;exports.Data=S;exports.Draw=P;exports.Loader=G;exports.Wk=U;
@@ -27,11 +27,11 @@ var f = (d, e, t) => new Promise((s, o) => {
27
27
  });
28
28
  import { makePromiseCreator as L } from "esus-lite";
29
29
  import * as l from "three";
30
- import { set as T, del as M, get as x } from "idb-keyval";
31
- import { e as O } from "../events.module.js";
30
+ import { set as T, del as M, get as O } from "idb-keyval";
31
+ import { e as x } from "../events.module.js";
32
32
  import { GLTFLoader as j } from "three/examples/jsm/loaders/GLTFLoader";
33
- import { DRACOLoader as U } from "three/examples/jsm/loaders/DRACOLoader";
34
- import { T as D, C as R, c as $ } from "../colorCorrection.module.js";
33
+ import { DRACOLoader as A } from "three/examples/jsm/loaders/DRACOLoader";
34
+ import { T as U, C as R, c as $ } from "../colorCorrection.module.js";
35
35
  class _ {
36
36
  constructor() {
37
37
  this.cache = /* @__PURE__ */ new Map();
@@ -253,7 +253,7 @@ class W {
253
253
  return;
254
254
  }
255
255
  const a = e.workerKey || l.MathUtils.generateUUID();
256
- (s ? x(a) : Promise.resolve()).then((c) => {
256
+ (s ? O(a) : Promise.resolve()).then((c) => {
257
257
  const n = o;
258
258
  c && c[n] ? t.cb(c[n]) : (this.messageList.push({
259
259
  req: e,
@@ -341,12 +341,12 @@ const g = {
341
341
  };
342
342
  class H {
343
343
  constructor() {
344
- this.textureLoader = new l.TextureLoader(), this.videoTextureLoader = new C(), this.gltfLoader = new j(), this.gltfDracoLoader = new j(), this.loadObj = {
344
+ this.loadObj = {
345
345
  texture: [],
346
346
  videoTexture: [],
347
347
  gltf: [],
348
- dracGltf: []
349
- }, this.assets = /* @__PURE__ */ new Map(), this.gltfAssets = /* @__PURE__ */ new Map(), this.event = new O.EventEmitter();
348
+ dracoGltf: []
349
+ }, this.assets = /* @__PURE__ */ new Map(), this.gltfAssets = /* @__PURE__ */ new Map(), this.event = new x.EventEmitter();
350
350
  }
351
351
  emit(e, ...t) {
352
352
  this.event.emit(e, ...t);
@@ -359,54 +359,59 @@ class H {
359
359
  }
360
360
  initLoadingManager() {
361
361
  const e = L(!0);
362
- return this.loadingManager = new l.LoadingManager(), this.textureLoader.manager = this.loadingManager, this.videoTextureLoader.manager = this.loadingManager, this.gltfLoader.manager = this.loadingManager, this.gltfDracoLoader.manager = this.loadingManager, this.loadingManager.onProgress = (t, s, o) => {
362
+ return this.loadingManager = new l.LoadingManager(), this.textureLoader = new l.TextureLoader(this.loadingManager), this.videoTextureLoader = new C(this.loadingManager), this.gltfLoader = new j(this.loadingManager), this.dracoPath && (this.dracoGltfLoader = new j(this.loadingManager), this.dracoLoader = new A(), this.dracoLoader.setDecoderPath(this.dracoPath), this.dracoGltfLoader.setDRACOLoader(this.dracoLoader)), this.loadingManager.onProgress = (t, s, o) => {
363
363
  s === o && e.resolve(), this.emit("progress", s, o, t);
364
364
  }, this.loadingManager.onError = (t) => {
365
365
  console.log("There was an error loading " + t), e.reject();
366
366
  }, e;
367
367
  }
368
- setDecoderPath(e) {
369
- this.dracoLoader = new U(), this.dracoLoader.setDecoderPath(e), this.gltfDracoLoader.setDRACOLoader(this.dracoLoader);
370
- }
371
368
  setItem(e, t) {
372
369
  typeof e == "string" && (e = [e]);
373
370
  const { dracoPath: s } = t || {};
374
- s && this.setDecoderPath(s), e.forEach((o) => {
371
+ s && (this.dracoPath = s), e.forEach((o) => {
375
372
  const a = o.split(".").pop();
376
- g.images.includes(a) ? this.loadObj.texture.push(o) : g.media.includes(a) ? this.loadObj.videoTexture.push(o) : g.gltf.includes(a) && (s ? this.loadObj.dracGltf.push(o) : this.loadObj.gltf.push(o));
373
+ g.images.includes(a) ? this.loadObj.texture.push(o) : g.media.includes(a) ? this.loadObj.videoTexture.push(o) : g.gltf.includes(a) && (s ? this.loadObj.dracoGltf.push(o) : this.loadObj.gltf.push(o));
377
374
  });
378
375
  }
379
376
  load() {
380
377
  const e = this.initLoadingManager();
381
- return this.loadTexture(this.loadObj.texture), this.loadVideoTexture(this.loadObj.videoTexture), this.loadGltf(this.loadObj.gltf), this.loadGltf(this.loadObj.dracGltf, !0), e.promise;
378
+ return this.loadTexture(this.loadObj.texture), this.loadVideoTexture(this.loadObj.videoTexture), this.loadGltf(this.loadObj.gltf), this.dracoPath && this.loadDracoGltf(this.loadObj.dracoGltf), e.promise;
382
379
  }
383
380
  loadTexture(e) {
384
- this.loadObj.texture.push(...e), e.forEach((t) => f(this, null, function* () {
381
+ e.forEach((t) => f(this, null, function* () {
385
382
  const s = yield this.textureLoader.loadAsync(t);
386
383
  this.assets.set(t, s);
387
384
  }));
388
385
  }
389
386
  colorCorrection() {
390
- (+l.REVISION < 152 && this.pencil.options.renderer.outputEncoding === D.sRGB || +l.REVISION >= 152 && this.pencil.options.renderer.outputColorSpace === R.sRGB) && this.assets.forEach((e) => {
387
+ (+l.REVISION < 152 && this.pencil.options.renderer.outputEncoding === U.sRGB || +l.REVISION >= 152 && this.pencil.options.renderer.outputColorSpace === R.sRGB) && this.assets.forEach((e) => {
391
388
  $({ texture: e });
392
389
  });
393
390
  }
394
391
  loadVideoTexture(e) {
395
- this.loadObj.videoTexture.push(...e), e.forEach((t) => f(this, null, function* () {
392
+ e.forEach((t) => f(this, null, function* () {
396
393
  this.videoTextureLoader.load(t, (s) => {
397
394
  this.assets.set(t, s);
398
395
  });
399
396
  }));
400
397
  }
401
- loadGltf(e, t) {
402
- this.loadObj[t ? "dracGltf" : "gltf"].push(...e), e.forEach((s) => f(this, null, function* () {
403
- const o = yield this[t ? "gltfDracoLoader" : "gltfLoader"].loadAsync(s);
404
- this.gltfAssets.set(s, o.scene);
398
+ loadGltf(e) {
399
+ e.forEach((t) => f(this, null, function* () {
400
+ const s = yield this.gltfLoader.loadAsync(t);
401
+ this.gltfAssets.set(t, s.scene);
402
+ }));
403
+ }
404
+ loadDracoGltf(e) {
405
+ e.forEach((t) => f(this, null, function* () {
406
+ if (!this.dracoGltfLoader)
407
+ return;
408
+ const s = yield this.dracoGltfLoader.loadAsync(t);
409
+ this.gltfAssets.set(t, s.scene);
405
410
  }));
406
411
  }
407
412
  dispose() {
408
413
  var e;
409
- this.assets.clear(), this.gltfAssets.clear(), (e = this.dracoLoader) == null || e.dispose();
414
+ this.assets.clear(), this.gltfAssets.clear(), (e = this.dracoLoader) == null || e.dispose(), this.event.removeAllListeners();
410
415
  }
411
416
  }
412
417
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-draw",
3
- "version": "0.9.0-beta.76",
3
+ "version": "0.9.0-beta.78",
4
4
  "author": "gitplus <hstits@gmail.com>",
5
5
  "scripts": {
6
6
  "start": "bundler-dev",