visgl / loaders.gl

Loaders for big data visualization. Website:
https://loaders.gl
Other
713 stars 193 forks source link

Loss of Textures When Converting 3D Tiles to SLPK Using Tile Converter #2693

Closed MoCongxin closed 11 months ago

MoCongxin commented 1 year ago

I was attempting to convert 3D tiles to SLPK files using the Tile Converter in a Docker container on Windows, but I encountered a problem where all the textures were missing. Additionally, running the same command occasionally fails, with a success rate of approximately 1 out of 10 attempts. Here's the command I used:

docker run  -v C:/Users/admin/Desktop/tttt:/loaders-bundle/data -v C:/Users/admin/Desktop/ScienceIslandOSGBSimple_3dtiles:/loaders-bundle/input-data visgl/tile-converter --input-type 3DTILES --tileset input-data/tileset.json --name ttt --output data --split-nodes --slpk --generate-textures

image

Furthermore, I couldn't locate any textures in the resulting SLPK file. Your assistance in resolving this issue would be greatly appreciated.

belom88 commented 1 year ago

Ideally, it would be nice if you could have shared the dataset with us. You can send it on victor.belomestnov@actionengine.com. Have you tried without --generate-textures? It creates 2nd copy of textures:

Resulting textures are located in /nodes/x/textures. There might be nodes without mesh so you need to check nodes with geometry (/nodes/x/geometries should be in place)

MoCongxin commented 1 year ago

Thank you for your help. I discovered that the issue was with my 3D Tiles file. I regenerated a new 3D Tile, but I encountered a new problem. After generating the SLPK using the following command, I couldn't view it in the frontend. It doesn't render correctly in either ArcGIS or Deck (though it did create a "textures" folder). I've sent both versions of the files to the email you provided. If possible, could you please take a look and see what might be causing this issue?

docker run  -v C:/Users/admin/Desktop/tttt:/loaders-bundle/data -v C:/Users/admin/Desktop/osgb23dtiles_test:/loaders-bundle/input-data visgl/tile-converter --input-type 3DTILES --tileset input-data/tileset.json --name qqqq --output data  --slpk

Additionally, I'd like to mention that running the same command still intermittently results in errors. It only succeeds on "lucky" occasions.

belom88 commented 1 year ago

I tried your dataset on Ubuntu: npx tile-converter --input-type 3DTILES --tileset ../tilesets/3d-tiles/osgb23dtiles_test/tileset.json --name osgb23dtiles --slpk It looks correct in ArcGIS: image You can take a look CLI manual: https://loaders.gl/docs/modules/tile-converter/cli-reference/tile-converter

We will try it on docker. Probably, the issue is related to docker.

MoCongxin commented 1 year ago

Can you tell me which version of Node.js you are using? I've tried both 16.20.2 and the latest version on Ubuntu Server 22.04 LTS, but I couldn't get it to run successfully.

Commands used:

npx tile-converter --input-type 3DTILES --tileset tiles/osgb23dtiles_test/tileset.json  --output slpk  --name linux_zzz --slpk

Node.js 16.20.2 Error:

/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:124
}`}function qB(e,t=!0,r){let i=r||new Set;if(e){if(aX(e))i.add(e);else if(aX(e.buffer))i.add(e.buffer);else if(!ArrayBuffer.isView(e)){if(t&&typeof e=="object")for(let n in e)qB(e[n],t,i)}}return r===void 0?Array.from(i):[]}function aX(e){return e?e instanceof ArrayBuffer||typeof MessagePort!="undefined"&&e instanceof MessagePort||typeof ImageBitmap!="undefined"&&e instanceof ImageBitmap||typeof OffscreenCanvas!="undefined"&&e instanceof OffscreenCanvas:!1}function UB(e){if(e===null)return{};let t=Object.assign({},e);return Object.keys(t).forEach(r=>{typeof e[r]=="object"&&!ArrayBuffer.isView(e[r])&&!(e[r]instanceof Array)?t[r]=UB(e[r]):typeof t[r]=="function"||t[r]instanceof RegExp?t[r]={}:t[r]=e[r]}),t}var GB=()=>{},bp=class{constructor(t){this.terminated=!1;this._loadableURL="";let{name:r,source:i,url:n}=t;ia(i||n),this.name=r,this.source=i,this.url=n,this.onMessage=GB,this.onError=a=>console.log(a),this.worker=Ln?this._createBrowserWorker():this._createNodeWorker()}static isSupported(){return typeof Worker!="undefined"&&Ln||typeof My!="undefined"&&!Ln}destroy(){this.onMessage=GB,this.onError=GB,this.worker.terminate(),this.terminated=!0}get isRunning(){return Boolean(this.onMessage)}postMessage(t,r){r=r||qB(t),this.worker.postMessage(t,r)}_getErrorFromErrorEvent(t){let r="Failed to load ";return r+=`worker ${this.name} from ${this.url}. `,t.message&&(r+=`${t.message} in `),t.lineno&&(r+=`:${t.lineno}:${t.colno}`),new Error(r)}_createBrowserWorker(){this._loadableURL=iX({source:this.source,url:this.url});let t=new Worker(this._loadableURL,{name:this.name});return t.onmessage=r=>{r.data?this.onMessage(r.data):this.onError(new Error("No data received"))},t.onerror=r=>{this.onError(this._getErrorFromErrorEvent(r)),this.terminated=!0},t.onmessageerror=r=>console.error(r),t}_createNodeWorker(){let t;if(this.url){let i=this.url.includes(":/")||this.url.startsWith("/")?this.url:`./${this.url}`;t=new My(i,{eval:!1})}else if(this.source)t=new My(this.source,{eval:!0});else throw new Error("no worker");return t.on("message",r=>{this.onMessage(r)}),t.on("error",r=>{this.onError(r)}),t.on("exit",r=>{}),t}};var x2=class{constructor(t){this.name="unnamed";this.maxConcurrency=1;this.maxMobileConcurrency=1;this.onDebug=()=>{};this.reuseWorkers=!0;this.props={};this.jobQueue=[];this.idleQueue=[];this.count=0;this.isDestroyed=!1;this.source=t.source,this.url=t.url,this.setProps(t)}static isSupported(){return bp.isSupported()}destroy(){this.idleQueue.forEach(t=>t.destroy()),this.isDestroyed=!0}setProps(t){this.props=ce(ce({},this.props),t),t.name!==void 0&&(this.name=t.name),t.maxConcurrency!==void 0&&(this.maxConcurrency=t.maxConcurrency),t.maxMobileConcurrency!==void 0&&(this.maxMobileConcurrency=t.maxMobileConcurrency),t.reuseWorkers!==void 0&&(this.reuseWorkers=t.reuseWorkers),t.onDebug!==void 0&&(this.onDebug=t.onDebug)}async startJob(t,r=(n,a,o)=>n.done(o),i=(n,a)=>n.error(a)){let n=new Promise(a=>(this.jobQueue.push({name:t,onMessage:r,onError:i,onStart:a}),this));return this._startQueuedJob(),await n}async _startQueuedJob(){if(!this.jobQueue.length)return;let t=this._getAvailableWorker();if(!t)return;let r=this.jobQueue.shift();if(r){this.onDebug({message:"Starting job",name:r.name,workerThread:t,backlog:this.jobQueue.length});let i=new _2(r.name,t);t.onMessage=n=>r.onMessage(i,n.type,n.payload),t.onError=n=>r.onError(i,n),r.onStart(i);try{await i.result}finally{this.returnWorkerToQueue(t)}}}returnWorkerToQueue(t){this.isDestroyed||!this.reuseWorkers||this.count>this._getMaxConcurrency()?(t.destroy(),this.count--):this.idleQueue.push(t),this.isDestroyed||this._startQueuedJob()}_getAvailableWorker(){if(this.idleQueue.length>0)return this.idleQueue.shift()||null;if(this.count<this._getMaxConcurrency()){this.count++;let t=`${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;return new bp({name:t,source:this.source,url:this.url})}return null}_getMaxConcurrency(){return eX?this.maxMobileConcurrency:this.maxConcurrency}};var gBe={maxConcurrency:3,maxMobileConcurrency:1,reuseWorkers:!0,onDebug:()=>{}},En=class{constructor(t){this.workerPools=new Map;this.props=ce({},gBe),this.setProps(t),this.workerPools=new Map}static isSupported(){return bp.isSupported()}static getWorkerFarm(t={}){return En._workerFarm=En._workerFarm||new En({}),En._workerFarm.setProps(t),En._workerFarm}destroy(){for(let t of this.workerPools.values())t.destroy();this.workerPools=new Map}setProps(t){this.props=ce(ce({},this.props),t);for(let r of this.workerPools.values())r.setProps(this._getWorkerPoolProps())}getWorkerPool(t){let{name:r,source:i,url:n}=t,a=this.workerPools.get(r);return a||(a=new x2({name:r,source:i,url:n}),a.setProps(this._getWorkerPoolProps()),this.workerPools.set(r,a)),a}_getWorkerPoolProps(){return{maxConcurrency:this.props.maxConcurrency,maxMobileConcurrency:this.props.maxMobileConcurrency,reuseWorkers:this.props.reuseWorkers,onDebug:this.props.onDebug}}};var oX="latest",sX=typeof Pf!="undefined"?Pf:oX;function uX(e){let t=e.version!==sX?` (worker-utils@${sX})`:"";return`${e.name}@${e.version}${t}`}function nu(e,t={}){let r=t[e.id]||{},i=`${e.id}-worker.js`,n=r.workerUrl;if(!n&&e.id==="compression"&&(n=t.workerUrl),t._workerType==="test"&&(n=`modules/${e.module}/dist/${i}`),!n){let a=e.version;a==="latest"&&(a=oX);let o=a?`@${a}`:"";n=`https://unpkg.com/@loaders.gl/${e.module}${o}/dist/${i}`}return ia(n),n}async function jy(e,t,r={},i={}){let n=uX(e),a=En.getWorkerFarm(r),{source:o}=r,s={name:n,source:o};o||(s.url=nu(e,r));let u=a.getWorkerPool(s),l=r.jobName||e.name,c=await u.startJob(l,vBe.bind(null,i)),f=UB(r);return c.postMessage("process",{input:t,options:f}),(await c.result).result}async function vBe(e,t,r,i){switch(r){case"done":t.done(i);break;case"error":t.error(new Error(i.error));break;case"process":let{id:n,input:a,options:o}=i;try{if(!e.process){t.postMessage("error",{id:n,error:"Worker not set up to process on main thread"});return}let s=await e.process(a,o);t.postMessage("done",{id:n,result:s})}catch(s){let u=s instanceof Error?s.message:"unknown error";t.postMessage("error",{id:n,error:u})}break;default:console.warn(`process-on-worker: unknown message ${r}`)}}function zB(e,t=Pf){ia(e,"no worker provided");let r=e.version;return!(!t||!r)}var WB={};Ao(WB,{requireFromFile:()=>VB,requireFromString:()=>w2});var HB=Le(require("module")),lX=Le(require("path"));async function VB(e){if(e.startsWith("http")){let r=await(await fetch(e)).text();return w2(r)}return e.startsWith("/")||(e=`${process.cwd()}/${e}`),require(e)}function w2(e,t="",r){if(typeof t=="object"&&(r=t,t=""),typeof e!="string")throw new Error(`code must be a string, not ${typeof e}`);let i=HB.default._nodeModulePaths(lX.default.dirname(t)),n=module.parent,a=new HB.default(t,n);return a.filename=t,a.paths=[].concat((r==null?void 0:r.prependPaths)||[]).concat(i).concat((r==null?void 0:r.appendPaths)||[]),a._compile(e,t),n&&n.children&&n.children.splice(n.children.indexOf(a),1),a.exports}var yBe="latest",bBe=typeof Pf!="undefined"?Pf:yBe,KB={};async function el(e,t=null,r={}){return t&&(e=cX(e,t,r)),KB[e]=KB[e]||_Be(e),await KB[e]}function cX(e,t,r){if(e.startsWith("http"))return e;let i=r.modules||{};return i[e]?i[e]:Ln?r.CDN?(ia(r.CDN.startsWith("http")),`${r.CDN}/${t}@${bBe}/dist/libs/${e}`):Fy?`../src/libs/${e}`:`modules/${t}/src/libs/${e}`:`modules/${t}/dist/libs/${e}`}async function _Be(e){if(e.endsWith("wasm"))return await(await fetch(e)).arrayBuffer();if(!Ln)try{return WB&&VB&&await VB(e)}catch{return null}if(Fy)return importScripts(e);let r=await(await fetch(e)).text();return xBe(r,e)}function xBe(e,t){if(!Ln)return w2&&w2(e,t);if(Fy)return eval.call(Z$,e),null;let r=document.createElement("script");r.id=t;try{r.appendChild(document.createTextNode(e))}catch{r.text=e}return document.body.appendChild(r),null}var pX=Le(require("child_process"));var fX=Le(require("child_process"));function hX(e=3e3){return new Promise(t=>{fX.default.exec("lsof -i -P -n | grep LISTEN",(r,i)=>{if(r){t(e);return}let n=[],a=/:(/d+) /(LISTEN/)/;i.split(`

Error: r is not a function
    at vBe (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:124:5776)
    at bp.t.onMessage (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:124:3320)
    at Worker.<anonymous> (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:124:2063)
    at Worker.emit (node:events:513:28)
    at MessagePort.<anonymous> (node:internal/worker:236:53)
    at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:736:20)
    at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)

Latest Node.js Version Error:

nput tileset value: tiles/osgb23dtiles_test/tileset.json
Modified tileset value: tiles/osgb23dtiles_test/tileset.json
------------------------------------------------
Starting conversion of 3DTILES
------------------------------------------------
Loading egm file...
TypeError: Failed to parse URL from /home/lihaihe/tile-converter/deps/egm2008-5.pgm
    at Object.fetch (node:internal/deps/undici/undici:11372:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async na (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:15404)
    at async ci (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:32799)
    at async Y_.convert (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:255672)
    at async eht (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:294308)
    at async Zft (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:292000) {
  [cause]: TypeError: Invalid URL
      at new URL (node:internal/url:775:36)
      at new _Request (node:internal/deps/undici/undici:5055:25)
      at fetch2 (node:internal/deps/undici/undici:9195:25)
      at Object.fetch (node:internal/deps/undici/undici:11370:18)
      at fetch (node:internal/process/pre_execution:282:25)
      at na (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:15410)
      at ci (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:32805)
      at Y_.convert (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:255678)
      at eht (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:294323)
      at Zft (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:125:292006) {
    code: 'ERR_INVALID_URL',
    input: '/home/lihaihe/tile-converter/deps/egm2008-5.pgm'
  }
}
belom88 commented 1 year ago

vbelomestnov@vbelomestnov-ubuntu:~$ node -v v16.20.2 As per https://loaders.gl/docs/modules/tile-converter/cli-reference/tile-converter, have installed dependencies?

MoCongxin commented 1 year ago

yes, have installed.

belom88 commented 1 year ago

--tileset tiles/osgb23dtiles_test/tileset.json can be wrong. Try to use absolute link:

/.../tiles/osgb23dtiles_test/tileset.json

Or relative link as I did:

../tilesets/3d-tiles/osgb23dtiles_test/tileset.json

In my case I have file structure:

/home
          /ubuntu
                      /tmp
                      /tilesets/3d-tiles/osgb23dtiles_test/tileset.json

And I ran converter from tmp folder.

MoCongxin commented 1 year ago

I believe it's not a path issue because it has already recognized the 3DTiles file. The complete log is as follows:

❯ npx tile-converter --input-type 3DTILES --tileset /home/lihaihe/tile-converter/tiles/osgb23dtiles_test/tileset.json  --output slpk  --name linux_zzz --slpk
Input tileset value: /home/lihaihe/tile-converter/tiles/osgb23dtiles_test/tileset.json
Modified tileset value: /home/lihaihe/tile-converter/tiles/osgb23dtiles_test/tileset.json
------------------------------------------------
Starting conversion of 3DTILES
------------------------------------------------
Loading egm file...
Loading egm file completed!
Loading workers source...
Loading workers source completed!
(node:31405) [DEP0147] DeprecationWarning: In future versions of Node.js, fs.rmdir(path, { recursive: true }) will be removed. Use fs.rm(path, { recursive: true }) instead
(Use `node --trace-deprecation ...` to show where the warning was created)
/home/lihaihe/tile-converter/tiles/osgb23dtiles_test/./Data/Tile_+000_+000/./Tile_+000_+000_L21_000000.b3dm
slpk/linux_zzz/SceneServer/layers/0/nodes/1/attributes/f_0/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/2/attributes/f_1/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/3/attributes/f_0/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/4/attributes/f_0/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/5/attributes/f_0/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/6/attributes/f_0/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/1/attributes/f_0/0.bin.gz compressed and saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/7/attributes/f_0/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/1/geometries/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/1/textures/0.jpg saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/1/shared/sharedResource.json saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/2/shared/sharedResource.json saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/1/attributes/f_1/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/1/attributes/f_2/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/2/attributes/f_0/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/2/attributes/f_2/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/3/textures/0.jpg saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/2/textures/0.jpg saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/2/geometries/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/3/geometries/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/3/attributes/f_1/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/3/shared/sharedResource.json saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/4/geometries/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/4/shared/sharedResource.json saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/3/attributes/f_2/0.bin saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/4/textures/0.jpg saved.
....
....
....
slpk/linux_zzz/SceneServer/layers/0/nodes/126/3dNodeIndexDocument.json saved.
slpk/linux_zzz/SceneServer/layers/0/nodes/126/3dNodeIndexDocument.json.gz compressed and saved.
/home/lihaihe/tile-converter/tiles/osgb23dtiles_test/./Data/Tile_+000_+003/./Tile_+000_+003_L22_0001300.b3dm
/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:124
}`}function qB(e,t=!0,r){let i=r||new Set;if(e){if(aX(e))i.add(e);else if(aX(e.buffer))i.add(e.buffer);else if(!ArrayBuffer.isView(e)){if(t&&typeof e=="object")for(let n in e)qB(e[n],t,i)}}return r===void 0?Array.from(i):[]}function aX(e){return e?e instanceof ArrayBuffer||typeof MessagePort!="undefined"&&e instanceof MessagePort||typeof ImageBitmap!="undefined"&&e instanceof ImageBitmap||typeof OffscreenCanvas!="undefined"&&e instanceof OffscreenCanvas:!1}function UB(e){if(e===null)return{};let t=Object.assign({},e);return Object.keys(t).forEach(r=>{typeof e[r]=="object"&&!ArrayBuffer.isView(e[r])&&!(e[r]instanceof Array)?t[r]=UB(e[r]):typeof t[r]=="function"||t[r]instanceof RegExp?t[r]={}:t[r]=e[r]}),t}var GB=()=>{},bp=class{constructor(t){this.terminated=!1;this._loadableURL="";let{name:r,source:i,url:n}=t;ia(i||n),this.name=r,this.source=i,this.url=n,this.onMessage=GB,this.onError=a=>console.log(a),this.worker=Ln?this._createBrowserWorker():this._createNodeWorker()}static isSupported(){return typeof Worker!="undefined"&&Ln||typeof My!="undefined"&&!Ln}destroy(){this.onMessage=GB,this.onError=GB,this.worker.terminate(),this.terminated=!0}get isRunning(){return Boolean(this.onMessage)}postMessage(t,r){r=r||qB(t),this.worker.postMessage(t,r)}_getErrorFromErrorEvent(t){let r="Failed to load ";return r+=`worker ${this.name} from ${this.url}. `,t.message&&(r+=`${t.message} in `),t.lineno&&(r+=`:${t.lineno}:${t.colno}`),new Error(r)}_createBrowserWorker(){this._loadableURL=iX({source:this.source,url:this.url});let t=new Worker(this._loadableURL,{name:this.name});return t.onmessage=r=>{r.data?this.onMessage(r.data):this.onError(new Error("No data received"))},t.onerror=r=>{this.onError(this._getErrorFromErrorEvent(r)),this.terminated=!0},t.onmessageerror=r=>console.error(r),t}_createNodeWorker(){let t;if(this.url){let i=this.url.includes(":/")||this.url.startsWith("/")?this.url:`./${this.url}`;t=new My(i,{eval:!1})}else if(this.source)t=new My(this.source,{eval:!0});else throw new Error("no worker");return t.on("message",r=>{this.onMessage(r)}),t.on("error",r=>{this.onError(r)}),t.on("exit",r=>{}),t}};var x2=class{constructor(t){this.name="unnamed";this.maxConcurrency=1;this.maxMobileConcurrency=1;this.onDebug=()=>{};this.reuseWorkers=!0;this.props={};this.jobQueue=[];this.idleQueue=[];this.count=0;this.isDestroyed=!1;this.source=t.source,this.url=t.url,this.setProps(t)}static isSupported(){return bp.isSupported()}destroy(){this.idleQueue.forEach(t=>t.destroy()),this.isDestroyed=!0}setProps(t){this.props=ce(ce({},this.props),t),t.name!==void 0&&(this.name=t.name),t.maxConcurrency!==void 0&&(this.maxConcurrency=t.maxConcurrency),t.maxMobileConcurrency!==void 0&&(this.maxMobileConcurrency=t.maxMobileConcurrency),t.reuseWorkers!==void 0&&(this.reuseWorkers=t.reuseWorkers),t.onDebug!==void 0&&(this.onDebug=t.onDebug)}async startJob(t,r=(n,a,o)=>n.done(o),i=(n,a)=>n.error(a)){let n=new Promise(a=>(this.jobQueue.push({name:t,onMessage:r,onError:i,onStart:a}),this));return this._startQueuedJob(),await n}async _startQueuedJob(){if(!this.jobQueue.length)return;let t=this._getAvailableWorker();if(!t)return;let r=this.jobQueue.shift();if(r){this.onDebug({message:"Starting job",name:r.name,workerThread:t,backlog:this.jobQueue.length});let i=new _2(r.name,t);t.onMessage=n=>r.onMessage(i,n.type,n.payload),t.onError=n=>r.onError(i,n),r.onStart(i);try{await i.result}finally{this.returnWorkerToQueue(t)}}}returnWorkerToQueue(t){this.isDestroyed||!this.reuseWorkers||this.count>this._getMaxConcurrency()?(t.destroy(),this.count--):this.idleQueue.push(t),this.isDestroyed||this._startQueuedJob()}_getAvailableWorker(){if(this.idleQueue.length>0)return this.idleQueue.shift()||null;if(this.count<this._getMaxConcurrency()){this.count++;let t=`${this.name.toLowerCase()} (#${this.count} of ${this.maxConcurrency})`;return new bp({name:t,source:this.source,url:this.url})}return null}_getMaxConcurrency(){return eX?this.maxMobileConcurrency:this.maxConcurrency}};var gBe={maxConcurrency:3,maxMobileConcurrency:1,reuseWorkers:!0,onDebug:()=>{}},En=class{constructor(t){this.workerPools=new Map;this.props=ce({},gBe),this.setProps(t),this.workerPools=new Map}static isSupported(){return bp.isSupported()}static getWorkerFarm(t={}){return En._workerFarm=En._workerFarm||new En({}),En._workerFarm.setProps(t),En._workerFarm}destroy(){for(let t of this.workerPools.values())t.destroy();this.workerPools=new Map}setProps(t){this.props=ce(ce({},this.props),t);for(let r of this.workerPools.values())r.setProps(this._getWorkerPoolProps())}getWorkerPool(t){let{name:r,source:i,url:n}=t,a=this.workerPools.get(r);return a||(a=new x2({name:r,source:i,url:n}),a.setProps(this._getWorkerPoolProps()),this.workerPools.set(r,a)),a}_getWorkerPoolProps(){return{maxConcurrency:this.props.maxConcurrency,maxMobileConcurrency:this.props.maxMobileConcurrency,reuseWorkers:this.props.reuseWorkers,onDebug:this.props.onDebug}}};var oX="latest",sX=typeof Pf!="undefined"?Pf:oX;function uX(e){let t=e.version!==sX?` (worker-utils@${sX})`:"";return`${e.name}@${e.version}${t}`}function nu(e,t={}){let r=t[e.id]||{},i=`${e.id}-worker.js`,n=r.workerUrl;if(!n&&e.id==="compression"&&(n=t.workerUrl),t._workerType==="test"&&(n=`modules/${e.module}/dist/${i}`),!n){let a=e.version;a==="latest"&&(a=oX);let o=a?`@${a}`:"";n=`https://unpkg.com/@loaders.gl/${e.module}${o}/dist/${i}`}return ia(n),n}async function jy(e,t,r={},i={}){let n=uX(e),a=En.getWorkerFarm(r),{source:o}=r,s={name:n,source:o};o||(s.url=nu(e,r));let u=a.getWorkerPool(s),l=r.jobName||e.name,c=await u.startJob(l,vBe.bind(null,i)),f=UB(r);return c.postMessage("process",{input:t,options:f}),(await c.result).result}async function vBe(e,t,r,i){switch(r){case"done":t.done(i);break;case"error":t.error(new Error(i.error));break;case"process":let{id:n,input:a,options:o}=i;try{if(!e.process){t.postMessage("error",{id:n,error:"Worker not set up to process on main thread"});return}let s=await e.process(a,o);t.postMessage("done",{id:n,result:s})}catch(s){let u=s instanceof Error?s.message:"unknown error";t.postMessage("error",{id:n,error:u})}break;default:console.warn(`process-on-worker: unknown message ${r}`)}}function zB(e,t=Pf){ia(e,"no worker provided");let r=e.version;return!(!t||!r)}var WB={};Ao(WB,{requireFromFile:()=>VB,requireFromString:()=>w2});var HB=Le(require("module")),lX=Le(require("path"));async function VB(e){if(e.startsWith("http")){let r=await(await fetch(e)).text();return w2(r)}return e.startsWith("/")||(e=`${process.cwd()}/${e}`),require(e)}function w2(e,t="",r){if(typeof t=="object"&&(r=t,t=""),typeof e!="string")throw new Error(`code must be a string, not ${typeof e}`);let i=HB.default._nodeModulePaths(lX.default.dirname(t)),n=module.parent,a=new HB.default(t,n);return a.filename=t,a.paths=[].concat((r==null?void 0:r.prependPaths)||[]).concat(i).concat((r==null?void 0:r.appendPaths)||[]),a._compile(e,t),n&&n.children&&n.children.splice(n.children.indexOf(a),1),a.exports}var yBe="latest",bBe=typeof Pf!="undefined"?Pf:yBe,KB={};async function el(e,t=null,r={}){return t&&(e=cX(e,t,r)),KB[e]=KB[e]||_Be(e),await KB[e]}function cX(e,t,r){if(e.startsWith("http"))return e;let i=r.modules||{};return i[e]?i[e]:Ln?r.CDN?(ia(r.CDN.startsWith("http")),`${r.CDN}/${t}@${bBe}/dist/libs/${e}`):Fy?`../src/libs/${e}`:`modules/${t}/src/libs/${e}`:`modules/${t}/dist/libs/${e}`}async function _Be(e){if(e.endsWith("wasm"))return await(await fetch(e)).arrayBuffer();if(!Ln)try{return WB&&VB&&await VB(e)}catch{return null}if(Fy)return importScripts(e);let r=await(await fetch(e)).text();return xBe(r,e)}function xBe(e,t){if(!Ln)return w2&&w2(e,t);if(Fy)return eval.call(Z$,e),null;let r=document.createElement("script");r.id=t;try{r.appendChild(document.createTextNode(e))}catch{r.text=e}return document.body.appendChild(r),null}var pX=Le(require("child_process"));var fX=Le(require("child_process"));function hX(e=3e3){return new Promise(t=>{fX.default.exec("lsof -i -P -n | grep LISTEN",(r,i)=>{if(r){t(e);return}let n=[],a=/:(\d+) \(LISTEN\)/;i.split(`

Error: r is not a function
    at vBe (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:124:5776)
    at bp.t.onMessage (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:124:3320)
    at Worker.<anonymous> (/home/lihaihe/tile-converter/node_modules/@loaders.gl/tile-converter/dist/converter.min.js:124:2063)
    at Worker.emit (node:events:513:28)
    at MessagePort.<anonymous> (node:internal/worker:236:53)
    at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:736:20)
    at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)
belom88 commented 1 year ago

Make sure you have stable internet connection all the time during conversion.