소스 검색

fix: splatter 7z 压缩

xzw 1 개월 전
부모
커밋
246e72faef
3개의 변경된 파일4293개의 추가작업 그리고 103개의 파일을 삭제
  1. 0 0
      build/potree/workers/7za.wasm.gz
  2. 4243 65
      src/custom/objects/3dgs/splatter/7zCps.js
  3. 50 38
      src/custom/objects/3dgs/splatter/SplatterThree.js

build/potree/workers/7za.wasm → build/potree/workers/7za.wasm.gz


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 4243 - 65
src/custom/objects/3dgs/splatter/7zCps.js


+ 50 - 38
src/custom/objects/3dgs/splatter/SplatterThree.js

@@ -324,27 +324,28 @@ var Decoder7z = class {//7z解压
         this.tree1Byte8 = tree1Byte8
         const max = 1
         const wasmUrl = Potree.scriptPath + '/workers/'
+        
+        let this_ = this
         for (let g = 0; g < max; g++) {
-            //let worker = new Worker(Potree.scriptPath + '/src/custom/objects/3dgs/splatter/7z/worker.js');   
             let worker = inlineWorker(getWorker7z)
-            
+            worker.index = g
             worker.postMessage({
                 t: 'init',
                 wasmUrl  
-            }) 
-            
-            worker.onmessage = function({data,t:type}){ 
-                let w = this 
+            })  
+            worker.onmessage = function({data}){ 
+                console.log('worker'+ this.index+'onmessage', data )
+                let type = data.t
                 if(type == 'opened'){
                     var curr = data.data.fileList[0]
-                    w.postMessage({
+                    this.postMessage({
                         t: 'extract',
                         idx: curr.idx,
                         name: curr.name,
-                        id: data.id //标识
+                        id: data.data.id //标识
                     })
                 }else{
-                    this[type](data)
+                    this_[type](data, this)
                 }
             }
             ,
@@ -353,27 +354,13 @@ var Decoder7z = class {//7z解压
         
     } 
     decode(blob ) {//请求
-        return new Promise((resolve => {
+        return new Promise((resolve => { 
             let id = this.version++;
+            console.log('请求decode', id)
             this.promiseList.set(id, {blob,resolve})  
             this.decodeNext() 
         }))
-    }
-    extracted({id, data}){ 
-        if (!this.promiseList.has(id))
-            throw Error("decode: internal error");
-        let ab = data.blob.arrayBuffer()
-        let result = getData(r, this.tree1Byte8)
-         
-        this.promiseList.get(id).resolve(result)  
-        this.promiseList.delete(id)
-        this.decodeNext() 
-    }
-    
-    ready(){
-        this.wasmReady = true
-        this.decodeNext()
-    }
+    } 
     decodeNext(){
         if(!this.wasmReady)return
         let waitDecode = this.promiseList.entries().next().value
@@ -381,15 +368,39 @@ var Decoder7z = class {//7z解压
             let id = waitDecode[0]
             let worker = this.workers.find(e=>!e.inUse)
             if(worker){
+                console.log('begin decode', id, 'worker index:', worker.index)
+                worker.inUse = true
                 worker.postMessage({
                     t: 'open',
-                    blob: blob,
+                    blob: waitDecode[1].blob,
                     id
                 });
             } 
         }
     }
-     
+    extracted({id, blob}, worker){ 
+        if (!this.promiseList.has(id))
+            throw Error("decode: internal error");
+        blob.arrayBuffer().then((ab)=>{
+            let result = getData(ab, this.tree1Byte8)
+             
+            this.promiseList.get(id).resolve(result)  
+            this.promiseList.delete(id)
+            console.log('decoded!', id)
+            setTimeout(()=>{
+                worker.inUse = false 
+                this.decodeNext() 
+            },1000) //"FS error  <generic error, no stack>"
+            
+        }) 
+        
+    }
+    
+    ready(){
+        this.wasmReady = true
+        this.decodeNext()
+    }
+    
 }
   
 
@@ -656,8 +667,8 @@ var maxTexSize = isMobile() ? 4096 : 8192
         this.ready = ((A.root || A.level_0) ? Promise.resolve(A) : this.loadMeta(`${this.path}/data.json`)).then((A => {
            
             this.originGsData = A.originGsData
-            this.cps7z = A.cps7z
-            this.suffix = A.suffix == void 0 ? (A.originGsData ? '' : '.gs' ) : A.suffix
+            this.cps7z = A.cps7z || browser.urlHasValue('7z')//需http-server ./ -c0 -g
+            this.suffix = A.suffix == void 0 ? (A.originGsData ? '' : this.cps7z ? '.7z' : '.gs' ) : A.suffix
             this.tree1Byte8 = A.tree1Byte8
             this.size = A.size|| A.files*65536,
             this.ratio = A.ratio,
@@ -682,9 +693,7 @@ var maxTexSize = isMobile() ? 4096 : 8192
                 this.decoder = new Decoder(this.texWidth,this.blockHeight,4)
             }else if(this.cps7z){
                 this.decoder = new Decoder7z(this.tree1Byte8)
-            }
-            
-        
+            } 
         } ))
     }
     loadMeta(A) {
@@ -751,9 +760,9 @@ var maxTexSize = isMobile() ? 4096 : 8192
                     //console.log('fileRecord count: '+ this.fileRecord.size)
                     //console.log('fileRecord '+ this.fileRecord.size+'个:'+ Array.from(this.fileRecord.keys()) )
                 }
-                )).catch((g => {
-                    this.loading.delete(fileName),
-                    console.error(`Error downloading block ${fileName}: ${g}`),
+                )).catch((err => {
+                    //this.loading.delete(fileName),
+                    console.error(`Error downloading block ${fileName}: ${err}`),
                     this.loadQueue()
                 }
             )) }
@@ -761,11 +770,14 @@ var maxTexSize = isMobile() ? 4096 : 8192
     }
     
     
-    load(fileName) {
+    load(fileName) { 
+        let max = browser.urlHasValue('maxBlock',true)  
+        if( max !== '' && fileName > max || window.pauseLoad)fileName += '_'
+        
         let url = `${this.path}/${fileName}${this.suffix}?m=${this.dataVersion}`
         return fetch(url).then((A => {
             if (!A.ok)
-                throw Error(`Error fetching ${g}: ${A.status} ${A.statusText}`);
+                throw Error(`Error fetching ${fileName}: ${A.status} ${A.statusText}`);
             return this.cps7z ? A.blob() : A.arrayBuffer()
         })).then((A => {