viral-viewer-2 2.1.7 → 2.1.9
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.
- package/dist/components/worker/test-worker-pool.d.ts +6 -0
- package/dist/components/worker/test-worker-pool.js +21 -0
- package/dist/components/worker/test-worker-pool.js.map +1 -0
- package/dist/components/worker/viral-viewer-2.worker.d.ts +2 -1
- package/dist/components/worker/viral-viewer-2.worker.js +6 -7
- package/dist/components/worker/viral-viewer-2.worker.js.map +1 -1
- package/dist/components/worker/viral-viewer.worker-pool.d.ts +0 -0
- package/dist/components/worker/viral-viewer.worker-pool.js +61 -0
- package/dist/components/worker/viral-viewer.worker-pool.js.map +1 -0
- package/dist/components/worker/worker-pool.d.ts +21 -0
- package/dist/components/worker/worker-pool.js +48 -0
- package/dist/components/worker/worker-pool.js.map +1 -0
- package/dist/components/worker/worker-thread.d.ts +9 -0
- package/dist/components/worker/worker-thread.js +30 -0
- package/dist/components/worker/worker-thread.js.map +1 -0
- package/dist/components/worker-script/test-worker-pool.script.d.ts +1 -0
- package/dist/components/worker-script/test-worker-pool.script.js +12 -0
- package/dist/components/worker-script/test-worker-pool.script.js.map +1 -0
- package/dist/viral-viewer-api.js +2 -0
- package/dist/viral-viewer-api.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TestWorkerPool = void 0;
|
|
4
|
+
const worker_pool_1 = require("./worker-pool");
|
|
5
|
+
const test_worker_pool_script_1 = require("../worker-script/test-worker-pool.script");
|
|
6
|
+
class TestWorkerPool {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.workerPool = null;
|
|
9
|
+
const blob = new Blob([`(${test_worker_pool_script_1.workerCode})()`]);
|
|
10
|
+
const workerPath = URL.createObjectURL(blob);
|
|
11
|
+
this.workerPool = new worker_pool_1.WorkerThreadPool(4, workerPath);
|
|
12
|
+
}
|
|
13
|
+
execute() {
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = this.workerPool) === null || _a === void 0 ? void 0 : _a.Enqueue(1, (result) => {
|
|
16
|
+
console.log('receive from worker', result);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.TestWorkerPool = TestWorkerPool;
|
|
21
|
+
//# sourceMappingURL=test-worker-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-worker-pool.js","sourceRoot":"","sources":["../../../src/components/worker/test-worker-pool.ts"],"names":[],"mappings":";;;AAAA,+CAAiD;AACjD,sFAAsE;AAEtE,MAAa,cAAc;IAEvB;QADO,eAAU,GAA4B,IAAI,CAAC;QAE9C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,oCAAU,KAAK,CAAC,CAAC,CAAC;QAC7C,MAAM,UAAU,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,UAAU,GAAG,IAAI,8BAAgB,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;IAEM,OAAO;;QAEV,MAAA,IAAI,CAAC,UAAU,0CAAE,OAAO,CAAgB,CAAC,EAAC,CAAC,MAAa,EAAC,EAAE;YACvD,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAC,MAAM,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AAdD,wCAcC"}
|
|
@@ -2,9 +2,10 @@ import { ViralViewerApi } from "../../viral-viewer-api";
|
|
|
2
2
|
import { RenderMaterial, ViralViewerRevitNoneStructuralGeometry, ViralViewerRevitStructuralGeometry } from "../../types";
|
|
3
3
|
import { Mesh, MeshPhongMaterial } from "three";
|
|
4
4
|
import { Dictionary } from "../../models/dictionary.model";
|
|
5
|
+
import { WorkerThreadPool } from "./worker-pool";
|
|
5
6
|
export declare class ViralViewerWorker2 {
|
|
6
7
|
viralViewerApi: ViralViewerApi;
|
|
7
|
-
|
|
8
|
+
workerPool: WorkerThreadPool;
|
|
8
9
|
materials: RenderMaterial[];
|
|
9
10
|
mainModel: Mesh | null;
|
|
10
11
|
threejsMaterials: Dictionary<number, MeshPhongMaterial>;
|
|
@@ -4,6 +4,7 @@ exports.ViralViewerWorker2 = void 0;
|
|
|
4
4
|
const three_1 = require("three");
|
|
5
5
|
const load_model_worker_2_script_1 = require("../worker-script/load-model-worker-2.script");
|
|
6
6
|
const dictionary_model_1 = require("../../models/dictionary.model");
|
|
7
|
+
const worker_pool_1 = require("./worker-pool");
|
|
7
8
|
class ViralViewerWorker2 {
|
|
8
9
|
constructor(viralViewerApi, scriptUrl = "../worker-script/load-model-worker-2.script.js") {
|
|
9
10
|
this.viralViewerApi = viralViewerApi;
|
|
@@ -14,7 +15,7 @@ class ViralViewerWorker2 {
|
|
|
14
15
|
const blob = new Blob([`(${load_model_worker_2_script_1.workerCode})()`]);
|
|
15
16
|
const workerPath = URL.createObjectURL(blob);
|
|
16
17
|
// Create a new Worker from the Blob
|
|
17
|
-
this.
|
|
18
|
+
this.workerPool = new worker_pool_1.WorkerThreadPool(4, workerPath);
|
|
18
19
|
}
|
|
19
20
|
initial(materials) {
|
|
20
21
|
this.materials = materials;
|
|
@@ -35,7 +36,7 @@ class ViralViewerWorker2 {
|
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
loadStructuralGeometry(model, callbackOnSuccess = () => { }) {
|
|
38
|
-
this.
|
|
39
|
+
this.workerPool.Enqueue({ type: 1, data: model, materials: this.materials }, (m) => {
|
|
39
40
|
switch (m.data.type) {
|
|
40
41
|
case 1:
|
|
41
42
|
console.log('load structure');
|
|
@@ -56,11 +57,10 @@ class ViralViewerWorker2 {
|
|
|
56
57
|
default:
|
|
57
58
|
break;
|
|
58
59
|
}
|
|
59
|
-
};
|
|
60
|
-
this.worker.postMessage({ type: 1, data: model, materials: this.materials });
|
|
60
|
+
});
|
|
61
61
|
}
|
|
62
62
|
loadNoneStructuralGeometry(model, callbackOnSuccess = () => { }) {
|
|
63
|
-
this.
|
|
63
|
+
this.workerPool.Enqueue({ type: 2, data: model, materials: this.materials }, (m) => {
|
|
64
64
|
switch (m.data.type) {
|
|
65
65
|
case 1:
|
|
66
66
|
console.log('load none structure');
|
|
@@ -81,8 +81,7 @@ class ViralViewerWorker2 {
|
|
|
81
81
|
default:
|
|
82
82
|
break;
|
|
83
83
|
}
|
|
84
|
-
};
|
|
85
|
-
this.worker.postMessage({ type: 2, data: model, materials: this.materials });
|
|
84
|
+
});
|
|
86
85
|
}
|
|
87
86
|
rgbToHex(r, g, b) {
|
|
88
87
|
return "#" + this.componentToHex(r) + this.componentToHex(g) + this.componentToHex(b);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viral-viewer-2.worker.js","sourceRoot":"","sources":["../../../src/components/worker/viral-viewer-2.worker.ts"],"names":[],"mappings":";;;AAEA,iCAA0I;AAC1I,4FAAyE;AACzE,oEAA2D;
|
|
1
|
+
{"version":3,"file":"viral-viewer-2.worker.js","sourceRoot":"","sources":["../../../src/components/worker/viral-viewer-2.worker.ts"],"names":[],"mappings":";;;AAEA,iCAA0I;AAC1I,4FAAyE;AACzE,oEAA2D;AAC3D,+CAAiD;AAEjD,MAAa,kBAAkB;IAK3B,YAAmB,cAA8B,EAAE,YAAoB,gDAAgD;QAApG,mBAAc,GAAd,cAAc,CAAgB;QAH1C,cAAS,GAAqB,EAAE,CAAC;QACjC,cAAS,GAAgB,IAAI,CAAC;QAC9B,qBAAgB,GAA0C,IAAI,6BAAU,EAA6B,CAAC;QAGzG,+CAA+C;QAC/C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,uCAAU,KAAK,CAAC,CAAC,CAAC;QAC7C,MAAM,UAAU,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC7C,oCAAoC;QACpC,IAAI,CAAC,UAAU,GAAG,IAAI,8BAAgB,C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G,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACzB,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7C,CAAC;CACJ;AA/FD,gDA+FC"}
|
|
File without changes
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// class WorkerThreadPool
|
|
2
|
+
// {
|
|
3
|
+
// constructor(sz,entry)
|
|
4
|
+
// {
|
|
5
|
+
// this._workers = [...Array(sr)].map(_=> new WorkerThread(entry));
|
|
6
|
+
// this._free = [...this._workers];
|
|
7
|
+
// this._busy = {};
|
|
8
|
+
// this._queue = [];
|
|
9
|
+
// }
|
|
10
|
+
// get length()
|
|
11
|
+
// {
|
|
12
|
+
// return this._workers.length;
|
|
13
|
+
// }
|
|
14
|
+
// get busy()
|
|
15
|
+
// {
|
|
16
|
+
// return this._queue.length > 0 || Object.keys(this._busy).length > 0;
|
|
17
|
+
// }
|
|
18
|
+
// Enqueue(workItem, resolve){
|
|
19
|
+
// this._queue.push([workItem,resolve]);
|
|
20
|
+
// this._PumpQueue();
|
|
21
|
+
// }
|
|
22
|
+
// _PumpQueue()
|
|
23
|
+
// {
|
|
24
|
+
// while (this._free.length > 0 && this._queue.length>0)
|
|
25
|
+
// {
|
|
26
|
+
// const w = this._free.pop();
|
|
27
|
+
// this._busy[w.id] = w;
|
|
28
|
+
// const [workItem,workResolve] = this._queue.shift();
|
|
29
|
+
// w.postMessage(workItem, (v)=>{
|
|
30
|
+
// delete this._busy[w.id];
|
|
31
|
+
// this._free.push(w);
|
|
32
|
+
// workResolve(v);
|
|
33
|
+
// this._PumpQueue();
|
|
34
|
+
// })
|
|
35
|
+
// }
|
|
36
|
+
// }
|
|
37
|
+
// }
|
|
38
|
+
// class WorkerThread{
|
|
39
|
+
// constructor(s)
|
|
40
|
+
// {
|
|
41
|
+
// this._worker = new Worker (s, type:'module');
|
|
42
|
+
// this._worker.onmessage = (e)=>{
|
|
43
|
+
// this._OnMessage(e);
|
|
44
|
+
// }
|
|
45
|
+
// this._resolve = null;
|
|
46
|
+
// this._id = _IDs++;
|
|
47
|
+
// }
|
|
48
|
+
// _OnMessage(e){
|
|
49
|
+
// const resolve = this._resolve;
|
|
50
|
+
// this._resolve = null;
|
|
51
|
+
// resolve(e.data);
|
|
52
|
+
// }
|
|
53
|
+
// get id(){
|
|
54
|
+
// return this._id;
|
|
55
|
+
// }
|
|
56
|
+
// postMessage(s,resolve){
|
|
57
|
+
// this._resolve = resolve;
|
|
58
|
+
// this._worker.postMessage(s);
|
|
59
|
+
// }
|
|
60
|
+
// }
|
|
61
|
+
//# sourceMappingURL=viral-viewer.worker-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viral-viewer.worker-pool.js","sourceRoot":"","sources":["../../../src/components/worker/viral-viewer.worker-pool.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,IAAI;AACJ,4BAA4B;AAC5B,QAAQ;AACR,2EAA2E;AAC3E,2CAA2C;AAC3C,2BAA2B;AAC3B,4BAA4B;AAC5B,QAAQ;AAER,mBAAmB;AACnB,QAAQ;AACR,uCAAuC;AACvC,QAAQ;AAER,iBAAiB;AACjB,QAAQ;AACR,+EAA+E;AAC/E,QAAQ;AACR,kCAAkC;AAClC,gDAAgD;AAChD,6BAA6B;AAC7B,QAAQ;AACR,mBAAmB;AACnB,QAAQ;AACR,gEAAgE;AAChE,YAAY;AACZ,0CAA0C;AAC1C,oCAAoC;AACpC,kEAAkE;AAClE,6CAA6C;AAC7C,2CAA2C;AAC3C,sCAAsC;AACtC,kCAAkC;AAClC,qCAAqC;AACrC,iBAAiB;AACjB,YAAY;AACZ,QAAQ;AACR,IAAI;AAEJ,sBAAsB;AACtB,qBAAqB;AACrB,QAAQ;AACR,wDAAwD;AACxD,0CAA0C;AAC1C,kCAAkC;AAClC,YAAY;AACZ,gCAAgC;AAChC,6BAA6B;AAC7B,QAAQ;AAER,qBAAqB;AACrB,yCAAyC;AACzC,gCAAgC;AAChC,2BAA2B;AAC3B,QAAQ;AAER,gBAAgB;AAChB,2BAA2B;AAC3B,QAAQ;AAER,8BAA8B;AAC9B,mCAAmC;AACnC,uCAAuC;AACvC,QAAQ;AACR,IAAI"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class WorkerThreadPool {
|
|
2
|
+
private _workers;
|
|
3
|
+
private _free;
|
|
4
|
+
private _busy;
|
|
5
|
+
private _queue;
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param size number of worker
|
|
9
|
+
* @param scriptPath javascript path for worker execute
|
|
10
|
+
*/
|
|
11
|
+
constructor(size: number, scriptPath: string);
|
|
12
|
+
get length(): number;
|
|
13
|
+
get busy(): boolean;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param inputData Input data send to worker
|
|
17
|
+
* @param resolve callback from worker
|
|
18
|
+
*/
|
|
19
|
+
Enqueue<T, M>(inputData: T, resolve: (result: M) => void): void;
|
|
20
|
+
private _PumpQueue;
|
|
21
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerThreadPool = void 0;
|
|
4
|
+
const worker_thread_1 = require("./worker-thread");
|
|
5
|
+
class WorkerThreadPool {
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param size number of worker
|
|
9
|
+
* @param scriptPath javascript path for worker execute
|
|
10
|
+
*/
|
|
11
|
+
constructor(size, scriptPath) {
|
|
12
|
+
this._workers = [...Array(size)].map(() => new worker_thread_1.WorkerThread(scriptPath));
|
|
13
|
+
this._free = [...this._workers];
|
|
14
|
+
this._busy = {};
|
|
15
|
+
this._queue = [];
|
|
16
|
+
}
|
|
17
|
+
get length() {
|
|
18
|
+
return this._workers.length;
|
|
19
|
+
}
|
|
20
|
+
get busy() {
|
|
21
|
+
return this._queue.length > 0 || Object.keys(this._busy).length > 0;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param inputData Input data send to worker
|
|
26
|
+
* @param resolve callback from worker
|
|
27
|
+
*/
|
|
28
|
+
Enqueue(inputData, resolve) {
|
|
29
|
+
this._queue.push([inputData, resolve]);
|
|
30
|
+
this._PumpQueue();
|
|
31
|
+
}
|
|
32
|
+
_PumpQueue() {
|
|
33
|
+
while (this._free.length > 0 && this._queue.length > 0) {
|
|
34
|
+
const w = this._free.pop();
|
|
35
|
+
console.log(`using worker ${w.id}`);
|
|
36
|
+
this._busy[w.id] = w;
|
|
37
|
+
const [inputData, workResolve] = this._queue.shift();
|
|
38
|
+
w.postMessage(inputData, (v) => {
|
|
39
|
+
delete this._busy[w.id];
|
|
40
|
+
this._free.push(w);
|
|
41
|
+
workResolve(v);
|
|
42
|
+
this._PumpQueue();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.WorkerThreadPool = WorkerThreadPool;
|
|
48
|
+
//# sourceMappingURL=worker-pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-pool.js","sourceRoot":"","sources":["../../../src/components/worker/worker-pool.ts"],"names":[],"mappings":";;;AAAA,mDAA+C;AAE/C,MAAa,gBAAgB;IAMzB;;;;OAIG;IACH,YAAY,IAAY,EAAE,UAAkB;QACxC,IAAI,CAAC,QAAQ,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,4BAAY,CAAC,UAAU,CAAC,CAAC,CAAC;QACzE,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAED,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|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WorkerThread = void 0;
|
|
4
|
+
let _IDs = 1;
|
|
5
|
+
class WorkerThread {
|
|
6
|
+
constructor(s) {
|
|
7
|
+
this._worker = new Worker(s);
|
|
8
|
+
this._worker.onmessage = (e) => {
|
|
9
|
+
this._OnMessage(e);
|
|
10
|
+
};
|
|
11
|
+
this._resolve = null;
|
|
12
|
+
this._id = _IDs++;
|
|
13
|
+
}
|
|
14
|
+
_OnMessage(e) {
|
|
15
|
+
const resolve = this._resolve;
|
|
16
|
+
this._resolve = null;
|
|
17
|
+
if (resolve) {
|
|
18
|
+
resolve(e.data);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
get id() {
|
|
22
|
+
return this._id;
|
|
23
|
+
}
|
|
24
|
+
postMessage(data, resolve) {
|
|
25
|
+
this._resolve = resolve;
|
|
26
|
+
this._worker.postMessage(data);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.WorkerThread = WorkerThread;
|
|
30
|
+
//# sourceMappingURL=worker-thread.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-thread.js","sourceRoot":"","sources":["../../../src/components/worker/worker-thread.ts"],"names":[],"mappings":";;;AAAA,IAAI,IAAI,GAAG,CAAC,CAAC;AAEb,MAAa,YAAY;IAKrB,YAAY,CAAS;QACjB,IAAI,CAAC,OAAO,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,CAAC,EAAE,EAAE;YAC3B,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,IAAI,EAAE,CAAC;IACtB,CAAC;IAEO,UAAU,CAAC,CAAe;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,OAAO,EAAE;YACT,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SACnB;IACL,CAAC;IAED,IAAW,EAAE;QACT,OAAO,IAAI,CAAC,GAAG,CAAC;IACpB,CAAC;IAEM,WAAW,CAAC,IAAS,EAAE,OAA4B;QACtD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;CACJ;AA9BD,oCA8BC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const workerCode: any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.workerCode = void 0;
|
|
4
|
+
function workerFunction() {
|
|
5
|
+
self.addEventListener("message", (event) => {
|
|
6
|
+
setTimeout(() => {
|
|
7
|
+
self.postMessage(2);
|
|
8
|
+
}, Math.random() * 2000);
|
|
9
|
+
}, false);
|
|
10
|
+
}
|
|
11
|
+
exports.workerCode = workerFunction;
|
|
12
|
+
//# sourceMappingURL=test-worker-pool.script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-worker-pool.script.js","sourceRoot":"","sources":["../../../src/components/worker-script/test-worker-pool.script.ts"],"names":[],"mappings":";;;AAAA,SAAS,cAAc;IAEnB,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,CAAC,KAA2B,EAAE,EAAE;QAC7D,UAAU,CAAC,GAAG,EAAE;YACZ,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;IAE7B,CAAC,EACG,KAAK,CACR,CAAC;AAIN,CAAC;AAEY,QAAA,UAAU,GAAQ,cAAc,CAAC"}
|
package/dist/viral-viewer-api.js
CHANGED
|
@@ -21,6 +21,7 @@ class ViralViewerApi {
|
|
|
21
21
|
this.compressProcessor = new compress_processor_1.CompressProcessor();
|
|
22
22
|
this.worker = null;
|
|
23
23
|
this.worker2 = null;
|
|
24
|
+
// worker3: TestWorkerPool | null = null;
|
|
24
25
|
this.localStorageService = new local_storage_service_1.LocalStorageService();
|
|
25
26
|
this.options = options;
|
|
26
27
|
this.targetElement = options.container;
|
|
@@ -37,6 +38,7 @@ class ViralViewerApi {
|
|
|
37
38
|
this.pointCloudLoader = new viral_viewer_point_cloud_loader_1.ViralViewerPointCloudLoader(this);
|
|
38
39
|
this.worker = new viral_viewer_worker_1.ViralViewerWorker(this);
|
|
39
40
|
this.worker2 = new viral_viewer_2_worker_1.ViralViewerWorker2(this);
|
|
41
|
+
// this.worker3 = new TestWorkerPool();
|
|
40
42
|
this.viralAnimation.animation();
|
|
41
43
|
}
|
|
42
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viral-viewer-api.js","sourceRoot":"","sources":["../src/viral-viewer-api.ts"],"names":[],"mappings":";;;AACA,6FAAuF;AACvF,iFAA6E;AAC7E,iFAA4E;AAC5E,yGAAkG;AAClG,mEAA+D;AAC/D,gEAA4D;AAC5D,gEAA4D;AAC5D,yEAAqE;AACrE,8FAAyF;AACzF,4EAAwE;AACxE,gEAA4D;AAC5D,sEAAkE;AAClE,4EAAuE;AACvE,yEAAqE;AACrE,qFAA+E;
|
|
1
|
+
{"version":3,"file":"viral-viewer-api.js","sourceRoot":"","sources":["../src/viral-viewer-api.ts"],"names":[],"mappings":";;;AACA,6FAAuF;AACvF,iFAA6E;AAC7E,iFAA4E;AAC5E,yGAAkG;AAClG,mEAA+D;AAC/D,gEAA4D;AAC5D,gEAA4D;AAC5D,yEAAqE;AACrE,8FAAyF;AACzF,4EAAwE;AACxE,gEAA4D;AAC5D,sEAAkE;AAClE,4EAAuE;AACvE,yEAAqE;AACrE,qFAA+E;AAK/E,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