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

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,5 +1,5 @@
1
1
  import * as THREE from 'three';
2
2
  export default class extends THREE.Loader {
3
- constructor(manager: THREE.LoadingManager);
3
+ constructor(manager?: THREE.LoadingManager);
4
4
  load(url: string, onLoad?: (texture: THREE.VideoTexture) => void, onProgress?: any, onError?: any): THREE.VideoTexture;
5
5
  }
@@ -2,32 +2,46 @@ import * as THREE from 'three';
2
2
  import { EventEmitter } from 'events';
3
3
  import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
4
4
  import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
5
- import { makePromiseCreator } from 'esus-lite';
6
5
  import VideoTextureLoader from './VideoTextureLoader';
7
6
  import Pencil from "../../core/Pencil";
7
+ export declare const KNOWN_ASSET_TYPES: {
8
+ images: string[];
9
+ media: string[];
10
+ gltf: string[];
11
+ };
8
12
  export default class Loader {
9
13
  textureLoader: THREE.TextureLoader;
10
14
  videoTextureLoader: VideoTextureLoader;
11
15
  gltfLoader: GLTFLoader;
12
16
  gltfDracoLoader: GLTFLoader;
13
17
  dracoLoader?: DRACOLoader;
18
+ loadingManager?: THREE.LoadingManager;
19
+ loadObj: {
20
+ texture: string[];
21
+ videoTexture: string[];
22
+ gltf: string[];
23
+ dracGltf: string[];
24
+ };
14
25
  assets: Map<string, THREE.Texture>;
15
26
  gltfAssets: Map<string, THREE.Object3D<THREE.Event>>;
16
- loadingManager: THREE.LoadingManager;
17
- progress: number;
18
- pm: ReturnType<typeof makePromiseCreator>;
19
27
  event: EventEmitter;
20
28
  pencil: Pencil;
21
29
  emit(eventName: string, ...args: any[]): void;
22
30
  on(eventName: string, listener: (...args: any[]) => void): void;
23
31
  install(pencil: Pencil): void;
24
- init(options?: {
25
- progressLog?: boolean;
32
+ initLoadingManager(): {
33
+ promise: Promise<any>;
34
+ resolve: (value?: any) => void;
35
+ reject: (value?: any) => void;
36
+ };
37
+ setDecoderPath(path: string): void;
38
+ setItem(src: string | string[], options?: {
39
+ dracoPath: string;
26
40
  }): void;
41
+ load(): Promise<any>;
27
42
  loadTexture(srcArr: string[]): void;
28
43
  colorCorrection(): void;
29
44
  loadVideoTexture(srcArr: string[]): void;
30
- setDecoderPath(path: string): void;
31
45
  loadGltf(srcArr: string[], draco?: boolean): void;
32
46
  dispose(): void;
33
47
  }
@@ -1 +1 @@
1
- "use strict";var E=Object.defineProperty;var m=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;var v=(a,e,t)=>e in a?E(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,L=(a,e)=>{for(var t in e||(e={}))k.call(e,t)&&v(a,t,e[t]);if(m)for(var t of m(e))M.call(e,t)&&v(a,t,e[t]);return a};var u=(a,e,t)=>new Promise((s,r)=>{var o=n=>{try{c(t.next(n))}catch(h){r(h)}},i=n=>{try{c(t.throw(n))}catch(h){r(h)}},c=n=>n.done?s(n.value):Promise.resolve(n.value).then(o,i);c((t=t.apply(a,e)).next())});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("esus-lite"),T=require("three"),g=require("idb-keyval"),O=require("../events.js"),j=require("three/examples/jsm/loaders/GLTFLoader"),C=require("three/examples/jsm/loaders/DRACOLoader"),b=require("../colorCorrection.js");function D(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=D(T);class R{constructor(){this.cache=new Map}install(){}init(e){const t=y.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 U{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(o={}){return new e[t](o)}};this.objectNamesToFactories.set(t,s)})}getObject(e,t){e.includes("#")&&console.warn("getObject:err:不支持 #",e);const{key:s}=t||{},r=`${e}${s?`#${s}`:""}`;return this.objects.get(r)}getAllObject(e,t){e.includes("#")&&console.warn("getAllObject:err:不支持 #",e);const{key:s}=t||{},r=`${e}${s?`#${s}`:""}`,o=[];return this.objects.forEach((i,c)=>{(c.startsWith(`${r}#`)||c===r)&&o.push(i)}),o}draw(e,t,s){return u(this,null,function*(){const r=this.objectNamesToFactories.get(e);if(r){const{key:o}=t||{};let i=`${e}${o?`#${o}`:""}`;if(this.objects.has(i)){const p=l.MathUtils.generateUUID();i+=`#${p}`}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 r().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 r=1e3+s*2,o=`${r-1}`;if(!this.onTopBase.has(o)){const i=new l.Points(void 0,new l.PointsMaterial({transparent:!0,opacity:0}));i.renderOrder=r-1,i.onBeforeRender=()=>{this.pencil.renderer.clearDepth()},i.frustumCulled=!1,this.onTopBase.set(o,!0),this.pencil.scene.add(i)}e.object3d.renderOrder=r}t.add(e.object3d)}e.visible=!0,e.render(),e.pm.resolve()})}erase(...e){[...e].forEach(t=>{const s=[];if(typeof t=="string"){const[r,o]=t.split("#");s.push(...this.getAllObject(r,{key:o}))}else s.push(t);s.forEach(r=>{this.removeMesh(r)})})}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 ${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 A{constructor(e={}){this.messageList=[],this.options=L({cache:!1,cacheVersion:"1"},e)}install(e,t){if(!t)return;const{scriptURL:s,length:r}=t;this.init(s,r)}init(e,t){let{cache:s,cacheVersion:r}=this.options;this.workerList=Array.from({length:t},(o,i)=>{const c=typeof e=="string"?new Worker(e):e();return c.onmessage=({data:{res:n,uuid:h}})=>{var p,w;const d=this.messageList.find(({uuid:f})=>h===f);if(d==null||d.options.cb(n),this.workerList[i].inUse=!1,this.checkMessage(),s=(p=d==null?void 0:d.options.cache)!=null?p:s,r=(w=d==null?void 0:d.options.cacheVersion)!=null?w:r,s){const f=r;g.set(h,{[f]:n})}},{worker:c,inUse:!1}})}postMessage(e,t){var i,c;let{cache:s,cacheVersion:r}=this.options;if(s=(i=t.cache)!=null?i:s,r=(c=t.cacheVersion)!=null?c:r,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 o=e.workerKey||l.MathUtils.generateUUID();(s?g.get(o):Promise.resolve()).then(n=>{const h=r;n&&n[h]?t.cb(n[h]):(this.messageList.push({req:e,options:t,uuid:o,inUse:!1}),this.checkMessage())}).catch(()=>{console.warn("err:worker cache"),this.messageList.push({req:e,options:t,uuid:o,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 S{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=r=>{this.chunks.push(r.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 x extends l.Loader{constructor(e){super(e)}load(e,t,s,r){e===void 0&&(e=""),this.path!==void 0&&(e=this.path+e),e=this.manager.resolveURL(e);const o=document.createElement("video"),i=new l.VideoTexture(o);i.needsUpdate=!0;const c=()=>{h(),t&&t(i),this.manager.itemEnd(e)},n=d=>{h(),r&&r(d),this.manager.itemEnd(e),this.manager.itemError(e)},h=()=>{o.removeEventListener("canplaythrough",c,!1),o.removeEventListener("error",n,!1)};return o.addEventListener("canplaythrough",c,!1),o.addEventListener("error",n,!1),e.slice(0,5)!=="data:"&&this.crossOrigin!==void 0&&(o.crossOrigin=this.crossOrigin),this.manager.itemStart(e),o.src=e,o.preload="auto",o.autoplay=!1,o.loop=!1,o.muted=!0,o.load(),o.setAttribute("webkit-playsinline","webkit-playsinline"),o.setAttribute("playsinline",""),i}}class P{constructor(){this.assets=new Map,this.gltfAssets=new Map,this.progress=0,this.event=new O.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()}init(e={}){this.pm=y.makePromiseCreator(!0),this.loadingManager=new l.LoadingManager,this.textureLoader=new l.TextureLoader(this.loadingManager),this.videoTextureLoader=new x(this.loadingManager),this.gltfLoader=new j.GLTFLoader(this.loadingManager),this.gltfDracoLoader=new j.GLTFLoader(this.loadingManager),this.loadingManager.onProgress=(t,s,r)=>{const o=s,i=r;this.progress=o/i,e.progressLog&&console.log("onProgress",t,o,i),this.progress===1&&this.pm.resolve(),this.emit("progress",this.progress)},this.loadingManager.onError=t=>console.log("There was an error loading "+t)}loadTexture(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){e.forEach(t=>u(this,null,function*(){this.videoTextureLoader.load(t,s=>{this.assets.set(t,s)})}))}setDecoderPath(e){this.dracoLoader=new C.DRACOLoader,this.dracoLoader.setDecoderPath(e),this.gltfDracoLoader.setDRACOLoader(this.dracoLoader)}loadGltf(e,t){e.forEach(s=>u(this,null,function*(){const r=yield this[t?"gltfDracoLoader":"gltfLoader"].loadAsync(s);this.gltfAssets.set(s,r.scene)}))}dispose(){var e;this.assets.clear(),this.gltfAssets.clear(),(e=this.dracoLoader)==null||e.dispose()}}exports.Cache=R;exports.CanvasStream=S;exports.Data=$;exports.Draw=U;exports.Loader=P;exports.Wk=A;
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,37 +1,37 @@
1
- var j = Object.defineProperty;
2
- var m = Object.getOwnPropertySymbols;
3
- var y = Object.prototype.hasOwnProperty, E = Object.prototype.propertyIsEnumerable;
4
- var w = (d, e, t) => e in d ? j(d, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[e] = t, b = (d, e) => {
1
+ var y = Object.defineProperty;
2
+ var b = Object.getOwnPropertySymbols;
3
+ var E = Object.prototype.hasOwnProperty, k = Object.prototype.propertyIsEnumerable;
4
+ var w = (d, e, t) => e in d ? y(d, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[e] = t, v = (d, e) => {
5
5
  for (var t in e || (e = {}))
6
- y.call(e, t) && w(d, t, e[t]);
7
- if (m)
8
- for (var t of m(e))
9
- E.call(e, t) && w(d, t, e[t]);
6
+ E.call(e, t) && w(d, t, e[t]);
7
+ if (b)
8
+ for (var t of b(e))
9
+ k.call(e, t) && w(d, t, e[t]);
10
10
  return d;
11
11
  };
12
- var p = (d, e, t) => new Promise((s, o) => {
13
- var r = (c) => {
12
+ var f = (d, e, t) => new Promise((s, o) => {
13
+ var a = (c) => {
14
14
  try {
15
- a(t.next(c));
15
+ r(t.next(c));
16
16
  } catch (n) {
17
17
  o(n);
18
18
  }
19
19
  }, i = (c) => {
20
20
  try {
21
- a(t.throw(c));
21
+ r(t.throw(c));
22
22
  } catch (n) {
23
23
  o(n);
24
24
  }
25
- }, a = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(r, i);
26
- a((t = t.apply(d, e)).next());
25
+ }, r = (c) => c.done ? s(c.value) : Promise.resolve(c.value).then(a, i);
26
+ r((t = t.apply(d, e)).next());
27
27
  });
28
28
  import { makePromiseCreator as L } from "esus-lite";
29
29
  import * as l from "three";
30
- import { set as k, del as M, get as T } from "idb-keyval";
31
- import { e as U } from "../events.module.js";
32
- import { GLTFLoader as v } from "three/examples/jsm/loaders/GLTFLoader";
33
- import { DRACOLoader as R } from "three/examples/jsm/loaders/DRACOLoader";
34
- import { T as $, C, c as x } from "../colorCorrection.module.js";
30
+ import { set as T, del as M, get as x } from "idb-keyval";
31
+ import { e as O } from "../events.module.js";
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";
35
35
  class _ {
36
36
  constructor() {
37
37
  this.cache = /* @__PURE__ */ new Map();
@@ -43,7 +43,7 @@ class _ {
43
43
  this.cache.set(e, t);
44
44
  }
45
45
  get(e, t) {
46
- return p(this, null, function* () {
46
+ return f(this, null, function* () {
47
47
  if (!this.cache.get(e) && t) {
48
48
  this.init(e);
49
49
  const s = yield t();
@@ -80,8 +80,8 @@ class K {
80
80
  const { objects_: e } = this;
81
81
  Object.keys(e).forEach((t) => {
82
82
  const s = class {
83
- create(r = {}) {
84
- return new e[t](r);
83
+ create(a = {}) {
84
+ return new e[t](a);
85
85
  }
86
86
  };
87
87
  this.objectNamesToFactories.set(t, s);
@@ -94,24 +94,24 @@ class K {
94
94
  }
95
95
  getAllObject(e, t) {
96
96
  e.includes("#") && console.warn("getAllObject:err:不支持 #", e);
97
- const { key: s } = t || {}, o = `${e}${s ? `#${s}` : ""}`, r = [];
98
- return this.objects.forEach((i, a) => {
99
- (a.startsWith(`${o}#`) || a === o) && r.push(i);
100
- }), r;
97
+ const { key: s } = t || {}, o = `${e}${s ? `#${s}` : ""}`, a = [];
98
+ return this.objects.forEach((i, r) => {
99
+ (r.startsWith(`${o}#`) || r === o) && a.push(i);
100
+ }), a;
101
101
  }
102
102
  draw(e, t, s) {
103
- return p(this, null, function* () {
103
+ return f(this, null, function* () {
104
104
  const o = this.objectNamesToFactories.get(e);
105
105
  if (o) {
106
- const { key: r } = t || {};
107
- let i = `${e}${r ? `#${r}` : ""}`;
106
+ const { key: a } = t || {};
107
+ let i = `${e}${a ? `#${a}` : ""}`;
108
108
  if (this.objects.has(i)) {
109
- const f = l.MathUtils.generateUUID();
110
- i += `#${f}`;
109
+ const p = l.MathUtils.generateUUID();
110
+ i += `#${p}`;
111
111
  }
112
- const a = (t == null ? void 0 : t.target) || s, c = (t == null ? void 0 : t.onTop) || 0;
112
+ const r = (t == null ? void 0 : t.target) || s, c = (t == null ? void 0 : t.onTop) || 0;
113
113
  let n;
114
- typeof a == "string" ? n = this.objects.get(a) : (a == null ? void 0 : a.objecttype__) === "BaseObject" ? n = a : this.group ? n = this.group : n = this.pencil.scene;
114
+ typeof r == "string" ? n = this.objects.get(r) : (r == null ? void 0 : r.objecttype__) === "BaseObject" ? n = r : this.group ? n = this.group : n = this.pencil.scene;
115
115
  const h = new o().create(t);
116
116
  return h.pencil = this.pencil, h.key = i, this.objects.set(i, h), yield this.addMesh(h, n, c), h;
117
117
  }
@@ -119,14 +119,14 @@ class K {
119
119
  });
120
120
  }
121
121
  addMesh(e, t, s) {
122
- return p(this, null, function* () {
122
+ return f(this, null, function* () {
123
123
  if (yield e.create(), e.object3d) {
124
124
  if (e.object3d.userData.BaseObject_ = e, s)
125
125
  if (e.type_ === "node")
126
126
  e.object3d.renderOrder = s;
127
127
  else {
128
- const o = 1e3 + s * 2, r = `${o - 1}`;
129
- if (!this.onTopBase.has(r)) {
128
+ const o = 1e3 + s * 2, a = `${o - 1}`;
129
+ if (!this.onTopBase.has(a)) {
130
130
  const i = new l.Points(
131
131
  void 0,
132
132
  new l.PointsMaterial({
@@ -136,7 +136,7 @@ class K {
136
136
  );
137
137
  i.renderOrder = o - 1, i.onBeforeRender = () => {
138
138
  this.pencil.renderer.clearDepth();
139
- }, i.frustumCulled = !1, this.onTopBase.set(r, !0), this.pencil.scene.add(i);
139
+ }, i.frustumCulled = !1, this.onTopBase.set(a, !0), this.pencil.scene.add(i);
140
140
  }
141
141
  e.object3d.renderOrder = o;
142
142
  }
@@ -149,8 +149,8 @@ class K {
149
149
  [...e].forEach((t) => {
150
150
  const s = [];
151
151
  if (typeof t == "string") {
152
- const [o, r] = t.split("#");
153
- s.push(...this.getAllObject(o, { key: r }));
152
+ const [o, a] = t.split("#");
153
+ s.push(...this.getAllObject(o, { key: a }));
154
154
  } else
155
155
  s.push(t);
156
156
  s.forEach((o) => {
@@ -188,7 +188,7 @@ class K {
188
188
  }), this.objects.clear(), this.onTopBase.clear(), this.objectNamesToFactories.clear();
189
189
  }
190
190
  }
191
- class N {
191
+ class I {
192
192
  constructor() {
193
193
  this.data = {};
194
194
  }
@@ -212,9 +212,9 @@ class N {
212
212
  this.data = {}, this.cb = void 0;
213
213
  }
214
214
  }
215
- class G {
215
+ class W {
216
216
  constructor(e = {}) {
217
- this.messageList = [], this.options = b({
217
+ this.messageList = [], this.options = v({
218
218
  cache: !1,
219
219
  cacheVersion: "1"
220
220
  }, e);
@@ -227,24 +227,24 @@ class G {
227
227
  }
228
228
  init(e, t) {
229
229
  let { cache: s, cacheVersion: o } = this.options;
230
- this.workerList = Array.from({ length: t }, (r, i) => {
231
- const a = typeof e == "string" ? new Worker(e) : e();
232
- return a.onmessage = ({ data: { res: c, uuid: n } }) => {
233
- var f, g;
234
- const h = this.messageList.find(({ uuid: u }) => n === u);
235
- h == null || h.options.cb(c), this.workerList[i].inUse = !1, this.checkMessage(), s = (f = h == null ? void 0 : h.options.cache) != null ? f : s, o = (g = h == null ? void 0 : h.options.cacheVersion) != null ? g : o, s && k(n, {
230
+ this.workerList = Array.from({ length: t }, (a, i) => {
231
+ const r = typeof e == "string" ? new Worker(e) : e();
232
+ return r.onmessage = ({ data: { res: c, uuid: n } }) => {
233
+ var p, u;
234
+ const h = this.messageList.find(({ uuid: m }) => n === m);
235
+ h == null || h.options.cb(c), this.workerList[i].inUse = !1, this.checkMessage(), s = (p = h == null ? void 0 : h.options.cache) != null ? p : s, o = (u = h == null ? void 0 : h.options.cacheVersion) != null ? u : o, s && T(n, {
236
236
  [o]: c
237
237
  });
238
238
  }, {
239
- worker: a,
239
+ worker: r,
240
240
  inUse: !1
241
241
  };
242
242
  });
243
243
  }
244
244
  postMessage(e, t) {
245
- var i, a;
245
+ var i, r;
246
246
  let { cache: s, cacheVersion: o } = this.options;
247
- if (s = (i = t.cache) != null ? i : s, o = (a = t.cacheVersion) != null ? a : o, s && !e.workerKey) {
247
+ if (s = (i = t.cache) != null ? i : s, o = (r = t.cacheVersion) != null ? r : o, s && !e.workerKey) {
248
248
  console.warn("worker cache need workerKey");
249
249
  return;
250
250
  }
@@ -252,20 +252,20 @@ class G {
252
252
  console.warn(`worker cache del: ${e.workerKey}`), M(e.workerKey);
253
253
  return;
254
254
  }
255
- const r = e.workerKey || l.MathUtils.generateUUID();
256
- (s ? T(r) : Promise.resolve()).then((c) => {
255
+ const a = e.workerKey || l.MathUtils.generateUUID();
256
+ (s ? x(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,
260
260
  options: t,
261
- uuid: r,
261
+ uuid: a,
262
262
  inUse: !1
263
263
  }), this.checkMessage());
264
264
  }).catch(() => {
265
265
  console.warn("err:worker cache"), this.messageList.push({
266
266
  req: e,
267
267
  options: t,
268
- uuid: r,
268
+ uuid: a,
269
269
  inUse: !1
270
270
  }), this.checkMessage();
271
271
  });
@@ -283,7 +283,7 @@ class G {
283
283
  }), this.workerList = [], this.messageList = [];
284
284
  }
285
285
  }
286
- class W {
286
+ class z {
287
287
  constructor() {
288
288
  this.chunks = [];
289
289
  }
@@ -316,27 +316,37 @@ class W {
316
316
  this.chunks = [];
317
317
  }
318
318
  }
319
- class D extends l.Loader {
319
+ class C extends l.Loader {
320
320
  constructor(e) {
321
321
  super(e);
322
322
  }
323
323
  load(e, t, s, o) {
324
324
  e === void 0 && (e = ""), this.path !== void 0 && (e = this.path + e), e = this.manager.resolveURL(e);
325
- const r = document.createElement("video"), i = new l.VideoTexture(r);
325
+ const a = document.createElement("video"), i = new l.VideoTexture(a);
326
326
  i.needsUpdate = !0;
327
- const a = () => {
327
+ const r = () => {
328
328
  n(), t && t(i), this.manager.itemEnd(e);
329
329
  }, c = (h) => {
330
330
  n(), o && o(h), this.manager.itemEnd(e), this.manager.itemError(e);
331
331
  }, n = () => {
332
- r.removeEventListener("canplaythrough", a, !1), r.removeEventListener("error", c, !1);
332
+ a.removeEventListener("canplaythrough", r, !1), a.removeEventListener("error", c, !1);
333
333
  };
334
- return r.addEventListener("canplaythrough", a, !1), r.addEventListener("error", c, !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;
334
+ return a.addEventListener("canplaythrough", r, !1), a.addEventListener("error", c, !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;
335
335
  }
336
336
  }
337
- class z {
337
+ const g = {
338
+ images: ["png", "jpg", "jpeg", "gif", "svg", "ico", "webp", "avif"],
339
+ media: ["mp4", "webm", "ogg", "mp3", "wav", "flac", "aac"],
340
+ gltf: ["gltf", "glb"]
341
+ };
342
+ class H {
338
343
  constructor() {
339
- this.assets = /* @__PURE__ */ new Map(), this.gltfAssets = /* @__PURE__ */ new Map(), this.progress = 0, this.event = new U.EventEmitter();
344
+ this.textureLoader = new l.TextureLoader(), this.videoTextureLoader = new C(), this.gltfLoader = new j(), this.gltfDracoLoader = new j(), this.loadObj = {
345
+ texture: [],
346
+ videoTexture: [],
347
+ gltf: [],
348
+ dracGltf: []
349
+ }, this.assets = /* @__PURE__ */ new Map(), this.gltfAssets = /* @__PURE__ */ new Map(), this.event = new O.EventEmitter();
340
350
  }
341
351
  emit(e, ...t) {
342
352
  this.event.emit(e, ...t);
@@ -347,35 +357,49 @@ class z {
347
357
  install(e) {
348
358
  this.pencil = e, this.colorCorrection();
349
359
  }
350
- init(e = {}) {
351
- this.pm = L(!0), this.loadingManager = new l.LoadingManager(), this.textureLoader = new l.TextureLoader(this.loadingManager), this.videoTextureLoader = new D(this.loadingManager), this.gltfLoader = new v(this.loadingManager), this.gltfDracoLoader = new v(this.loadingManager), this.loadingManager.onProgress = (t, s, o) => {
352
- const r = s, i = o;
353
- this.progress = r / i, e.progressLog && console.log("onProgress", t, r, i), this.progress === 1 && this.pm.resolve(), this.emit("progress", this.progress);
354
- }, this.loadingManager.onError = (t) => console.log("There was an error loading " + t);
360
+ initLoadingManager() {
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) => {
363
+ s === o && e.resolve(), this.emit("progress", s, o, t);
364
+ }, this.loadingManager.onError = (t) => {
365
+ console.log("There was an error loading " + t), e.reject();
366
+ }, e;
367
+ }
368
+ setDecoderPath(e) {
369
+ this.dracoLoader = new U(), this.dracoLoader.setDecoderPath(e), this.gltfDracoLoader.setDRACOLoader(this.dracoLoader);
370
+ }
371
+ setItem(e, t) {
372
+ typeof e == "string" && (e = [e]);
373
+ const { dracoPath: s } = t || {};
374
+ s && this.setDecoderPath(s), e.forEach((o) => {
375
+ 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));
377
+ });
378
+ }
379
+ load() {
380
+ 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;
355
382
  }
356
383
  loadTexture(e) {
357
- e.forEach((t) => p(this, null, function* () {
384
+ this.loadObj.texture.push(...e), e.forEach((t) => f(this, null, function* () {
358
385
  const s = yield this.textureLoader.loadAsync(t);
359
386
  this.assets.set(t, s);
360
387
  }));
361
388
  }
362
389
  colorCorrection() {
363
- (+l.REVISION < 152 && this.pencil.options.renderer.outputEncoding === $.sRGB || +l.REVISION >= 152 && this.pencil.options.renderer.outputColorSpace === C.sRGB) && this.assets.forEach((e) => {
364
- x({ texture: e });
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) => {
391
+ $({ texture: e });
365
392
  });
366
393
  }
367
394
  loadVideoTexture(e) {
368
- e.forEach((t) => p(this, null, function* () {
395
+ this.loadObj.videoTexture.push(...e), e.forEach((t) => f(this, null, function* () {
369
396
  this.videoTextureLoader.load(t, (s) => {
370
397
  this.assets.set(t, s);
371
398
  });
372
399
  }));
373
400
  }
374
- setDecoderPath(e) {
375
- this.dracoLoader = new R(), this.dracoLoader.setDecoderPath(e), this.gltfDracoLoader.setDRACOLoader(this.dracoLoader);
376
- }
377
401
  loadGltf(e, t) {
378
- e.forEach((s) => p(this, null, function* () {
402
+ this.loadObj[t ? "dracGltf" : "gltf"].push(...e), e.forEach((s) => f(this, null, function* () {
379
403
  const o = yield this[t ? "gltfDracoLoader" : "gltfLoader"].loadAsync(s);
380
404
  this.gltfAssets.set(s, o.scene);
381
405
  }));
@@ -387,9 +411,9 @@ class z {
387
411
  }
388
412
  export {
389
413
  _ as Cache,
390
- W as CanvasStream,
391
- N as Data,
414
+ z as CanvasStream,
415
+ I as Data,
392
416
  K as Draw,
393
- z as Loader,
394
- G as Wk
417
+ H as Loader,
418
+ W as Wk
395
419
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gl-draw",
3
- "version": "0.9.0-beta.74",
3
+ "version": "0.9.0-beta.76",
4
4
  "author": "gitplus <hstits@gmail.com>",
5
5
  "scripts": {
6
6
  "start": "bundler-dev",