|
|
@@ -2,8 +2,12 @@
|
|
|
import * as THREE from "../../../../../libs/three.js/build/three.module.js";
|
|
|
|
|
|
import browser from '../../../utils/browser.js'
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ let worker = new Worker(Potree.scriptPath + '/workers/testWorker.js')
|
|
|
|
|
|
-import getWorker7z from './7zCps.js'
|
|
|
|
|
|
//2025.11 下载 Ver2
|
|
|
let lastLodTime = 0 , lastCanSort = 0, lastRender = 0, lastHit = 0
|
|
|
@@ -316,7 +320,7 @@ function inlineWorker(A) {
|
|
|
|
|
|
|
|
|
|
|
|
-var Decoder7z = class {//7z解压
|
|
|
+/* var Decoder7z = class {//7z解压
|
|
|
constructor(tree1Byte8) {
|
|
|
this.workers = []
|
|
|
this.promiseList = new Map
|
|
|
@@ -324,27 +328,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 +358,108 @@ 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()
|
|
|
}))
|
|
|
+ }
|
|
|
+ decodeNext(){
|
|
|
+ if(!this.wasmReady)return
|
|
|
+ let waitDecode = this.promiseList.entries().next().value
|
|
|
+ if(waitDecode){
|
|
|
+ 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: waitDecode[1].blob,
|
|
|
+ id
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- extracted({id, data}){
|
|
|
+ extracted({id, blob}, worker){
|
|
|
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()
|
|
|
+ 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()
|
|
|
}
|
|
|
+
|
|
|
+} */
|
|
|
+
|
|
|
+var Decoder7z = class {//7z解压
|
|
|
+ constructor(tree1Byte8) {
|
|
|
+ this.workers = []
|
|
|
+ this.promiseList = new Map
|
|
|
+ this.version = 0
|
|
|
+ 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(new URL("./7z-worker.js", import.meta.url), {
|
|
|
+ type: "module",
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ //let worker = inlineWorker(getWorker7z)
|
|
|
+ worker.index = g
|
|
|
+ worker.postMessage({
|
|
|
+ t: 'init',
|
|
|
+ wasmUrl
|
|
|
+ })
|
|
|
+ worker.onmessage = function({data}){
|
|
|
+ console.log('worker'+ this.index+'onmessage', data )
|
|
|
+ let type = data.t
|
|
|
+ if(type == 'opened'){
|
|
|
+ var curr = data.data.fileList[0]
|
|
|
+ this.postMessage({
|
|
|
+ t: 'extract',
|
|
|
+ idx: curr.idx,
|
|
|
+ name: curr.name,
|
|
|
+ id: data.data.id //标识
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ this_[type](data, this)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ,
|
|
|
+ this.workers.push(worker)
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ decode(blob ) {//请求
|
|
|
+ return new Promise((resolve => {
|
|
|
+ let id = this.version++;
|
|
|
+ console.log('请求decode', id)
|
|
|
+ this.promiseList.set(id, {blob,resolve})
|
|
|
+ this.decodeNext()
|
|
|
+ }))
|
|
|
+ }
|
|
|
decodeNext(){
|
|
|
if(!this.wasmReady)return
|
|
|
let waitDecode = this.promiseList.entries().next().value
|
|
|
@@ -381,18 +467,40 @@ 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()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
|
|
|
|
|
|
var Decoder = class {
|
|
|
@@ -656,8 +764,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 +790,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 +857,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 +867,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 => {
|
|
|
|