viral-viewer-2 2.7.8 → 2.8.0
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/viral-viewer-2.worker.d.ts +0 -1
- package/dist/components/worker/viral-viewer-2.worker.js +69 -82
- package/dist/components/worker/viral-viewer-2.worker.js.map +1 -1
- package/dist/components/worker/viral-viewer-3.worker.d.ts +21 -0
- package/dist/components/worker/viral-viewer-3.worker.js +142 -0
- package/dist/components/worker/viral-viewer-3.worker.js.map +1 -0
- package/dist/components/worker-script/threejs.types.js +62 -6
- package/dist/components/worker-script/threejs.types.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +11 -1
- package/dist/types.js.map +1 -1
- package/dist/viral-viewer-api.d.ts +2 -0
- package/dist/viral-viewer-api.js +3 -0
- package/dist/viral-viewer-api.js.map +1 -1
- package/package.json +1 -1
|
@@ -11,7 +11,6 @@ export declare class ViralViewerWorker2 {
|
|
|
11
11
|
threejsMaterials: Dictionary<number, MeshPhongMaterial>;
|
|
12
12
|
private readonly maxPolygonPerObject;
|
|
13
13
|
private readonly maxPolygonForEdge;
|
|
14
|
-
private threejsLoader;
|
|
15
14
|
constructor(viralViewerApi: ViralViewerApi, scriptUrl?: string);
|
|
16
15
|
initial(materials: RenderMaterial[]): void;
|
|
17
16
|
loadStructuralGeometry(model: ViralViewerRevitStructuralGeometry, callbackOnSuccess?: () => void): void;
|
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ViralViewerWorker2 = void 0;
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
5
|
const three_1 = require("three");
|
|
6
|
-
|
|
7
|
-
const threejs_types_1 = require("../worker-script/threejs.types");
|
|
6
|
+
const load_model_worker_2_script_1 = require("../worker-script/load-model-worker-2.script");
|
|
8
7
|
const dictionary_model_1 = require("../../models/dictionary.model");
|
|
9
8
|
const worker_pool_1 = require("./base/worker-pool");
|
|
9
|
+
const simplify_modifier_1 = require("../../threejs-addon/simplify-modifier");
|
|
10
10
|
class ViralViewerWorker2 {
|
|
11
11
|
constructor(viralViewerApi, scriptUrl = "../worker-script/load-model-worker-2.script.js") {
|
|
12
12
|
this.viralViewerApi = viralViewerApi;
|
|
@@ -15,9 +15,8 @@ class ViralViewerWorker2 {
|
|
|
15
15
|
this.threejsMaterials = new dictionary_model_1.Dictionary();
|
|
16
16
|
this.maxPolygonPerObject = 1000;
|
|
17
17
|
this.maxPolygonForEdge = 1000;
|
|
18
|
-
this.threejsLoader = new three_1.BufferGeometryLoader();
|
|
19
18
|
// Create a new Blob containing the worker code
|
|
20
|
-
const blob = new Blob([`(${
|
|
19
|
+
const blob = new Blob([`(${load_model_worker_2_script_1.workerCode})()`]);
|
|
21
20
|
const workerPath = URL.createObjectURL(blob);
|
|
22
21
|
// Create a new Worker from the Blob
|
|
23
22
|
this.workerPool = new worker_pool_1.WorkerThreadPool(4, workerPath);
|
|
@@ -45,25 +44,19 @@ class ViralViewerWorker2 {
|
|
|
45
44
|
inputData.Indices = model.Indices;
|
|
46
45
|
inputData.Vertices = model.Vertices;
|
|
47
46
|
this.workerPool.Enqueue(inputData, (data) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// childMesh.add(line);
|
|
62
|
-
// childMesh.castShadow = true;
|
|
63
|
-
// childMesh.receiveShadow = true;
|
|
64
|
-
// if (this.mainModel)
|
|
65
|
-
// this.mainModel.add(childMesh);
|
|
66
|
-
// this.viralViewerApi.viralRenderer.render();
|
|
47
|
+
let buffer = data.buffer;
|
|
48
|
+
const geometry = new three_1.BufferGeometry();
|
|
49
|
+
geometry.setAttribute("position", new three_1.BufferAttribute(buffer, 3));
|
|
50
|
+
geometry.computeVertexNormals();
|
|
51
|
+
const edges = new three_1.EdgesGeometry(geometry, 90);
|
|
52
|
+
const line = new three_1.LineSegments(edges, new three_1.LineBasicMaterial({ color: "#202020", linewidth: 0.5 }));
|
|
53
|
+
const childMesh = new three_1.Mesh(geometry, this.threejsMaterials.get(model.MaterialIndex));
|
|
54
|
+
childMesh.add(line);
|
|
55
|
+
childMesh.castShadow = true;
|
|
56
|
+
childMesh.receiveShadow = true;
|
|
57
|
+
if (this.mainModel)
|
|
58
|
+
this.mainModel.add(childMesh);
|
|
59
|
+
this.viralViewerApi.viralRenderer.render();
|
|
67
60
|
callbackOnSuccess();
|
|
68
61
|
});
|
|
69
62
|
}
|
|
@@ -72,66 +65,60 @@ class ViralViewerWorker2 {
|
|
|
72
65
|
inputData.Indices = model.Indices;
|
|
73
66
|
inputData.Vertices = model.Vertices;
|
|
74
67
|
this.workerPool.Enqueue(inputData, (data) => {
|
|
75
|
-
|
|
76
|
-
let
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// else {
|
|
91
|
-
// geometry = dummyGeometry;
|
|
92
|
-
// }
|
|
68
|
+
let buffer = data.buffer;
|
|
69
|
+
let geometry = new three_1.BufferGeometry();
|
|
70
|
+
const dummyGeometry = new three_1.BufferGeometry();
|
|
71
|
+
dummyGeometry.setAttribute("position", new three_1.BufferAttribute(buffer, 3));
|
|
72
|
+
// In case number of polygon larger than expect, merge them to reduce polygon first, for optimize purpose
|
|
73
|
+
if (dummyGeometry.attributes.position.count > this.maxPolygonPerObject) {
|
|
74
|
+
const modifier = new simplify_modifier_1.SimplifyModifier();
|
|
75
|
+
const ratio = this.maxPolygonPerObject / dummyGeometry.attributes.position.count;
|
|
76
|
+
const count = Math.floor(dummyGeometry.attributes.position.count * ratio); // number of polygon to remove
|
|
77
|
+
geometry = modifier.modify(dummyGeometry, count);
|
|
78
|
+
console.log(model.Name, dummyGeometry.attributes.position.count, geometry.attributes.position.count);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
geometry = dummyGeometry;
|
|
82
|
+
}
|
|
93
83
|
// geometry.computeVertexNormals();
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// if (this.mainModel) {
|
|
133
|
-
// this.mainModel.add(childMesh);
|
|
134
|
-
// }
|
|
84
|
+
const childMesh = new three_1.InstancedMesh(geometry, this.threejsMaterials.get(model.MaterialIndex), model.Instances.length);
|
|
85
|
+
childMesh.castShadow = true;
|
|
86
|
+
childMesh.receiveShadow = true;
|
|
87
|
+
for (let index = 0; index < model.Instances.length; index++) {
|
|
88
|
+
const transform = model.Instances[index];
|
|
89
|
+
let numbers = [
|
|
90
|
+
transform.BasisX.X,
|
|
91
|
+
-transform.BasisX.Z,
|
|
92
|
+
-transform.BasisX.Y,
|
|
93
|
+
0,
|
|
94
|
+
-transform.BasisZ.X,
|
|
95
|
+
transform.BasisZ.Z,
|
|
96
|
+
transform.BasisZ.Y,
|
|
97
|
+
0,
|
|
98
|
+
-transform.BasisY.X,
|
|
99
|
+
transform.BasisY.Z,
|
|
100
|
+
transform.BasisY.Y,
|
|
101
|
+
0,
|
|
102
|
+
-transform.Offset.X,
|
|
103
|
+
transform.Offset.Z,
|
|
104
|
+
transform.Offset.Y,
|
|
105
|
+
1,
|
|
106
|
+
];
|
|
107
|
+
//transform first
|
|
108
|
+
let matrix4 = new three_1.Matrix4();
|
|
109
|
+
matrix4.fromArray(numbers);
|
|
110
|
+
childMesh.setMatrixAt(index, matrix4);
|
|
111
|
+
//if number of polygon smaller than expect, generate edges
|
|
112
|
+
if (geometry.attributes.position.count < this.maxPolygonForEdge) {
|
|
113
|
+
const edges = new three_1.EdgesGeometry(geometry, 90);
|
|
114
|
+
const line = new three_1.LineSegments(edges, new three_1.LineBasicMaterial({ color: "#666", linewidth: 0.5 }));
|
|
115
|
+
line.applyMatrix4(matrix4);
|
|
116
|
+
childMesh.add(line);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (this.mainModel) {
|
|
120
|
+
this.mainModel.add(childMesh);
|
|
121
|
+
}
|
|
135
122
|
callbackOnSuccess();
|
|
136
123
|
});
|
|
137
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"viral-viewer-2.worker.js","sourceRoot":"","sources":["../../../src/components/worker/viral-viewer-2.worker.ts"],"names":[],"mappings":";;;AACA,uCAA4K;AAC5K,iCAAsN;AACtN,
|
|
1
|
+
{"version":3,"file":"viral-viewer-2.worker.js","sourceRoot":"","sources":["../../../src/components/worker/viral-viewer-2.worker.ts"],"names":[],"mappings":";;;AACA,uCAA4K;AAC5K,iCAAsN;AACtN,4FAAyE;AACzE,oEAA2D;AAC3D,oDAAsD;AACtD,6EAAyE;AAEzE,MAAa,kBAAkB;IAO3B,YAAmB,cAA8B,EAAE,YAAoB,gDAAgD;QAApG,mBAAc,GAAd,cAAc,CAAgB;QAL1C,cAAS,GAAqB,EAAE,CAAC;QACjC,cAAS,GAAgB,IAAI,CAAC;QAC9B,qBAAgB,GAA0C,IAAI,6BAAU,EAA6B,CAAC;QAC5F,wBAAmB,GAAG,IAAI,CAAC;QAC3B,sB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,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC,iBAAiB,EAAE;oBAC7D,MAAM,KAAK,GAAG,IAAI,qBAAa,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;oBAC9C,MAAM,IAAI,GAAG,IAAI,oBAAY,CACzB,KAAK,EACL,IAAI,yBAAiB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAC3D,CAAC;oBACF,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;oBAC3B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;iBACvB;aAGJ;YACD,IAAI,IAAI,CAAC,SAAS,EAAE;gBAChB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;aACjC;YACD,iBAAiB,EAAE,CAAC;QACxB,CAAC,CAAC,CAAA;IACN,CAAC;IACM,QAAQ,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;QAC3C,OAAO,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC;IACM,cAAc,CAAC,CAAS;QAC3B,IAAI,GAAG,GAAG,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;AAzID,gDAyIC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ViralViewerApi } from "../../viral-viewer-api";
|
|
2
|
+
import { RenderMaterial, ViralViewerRevitNoneStructuralGeometry, ViralViewerRevitStructuralGeometry } from "../../types";
|
|
3
|
+
import { Mesh, MeshPhongMaterial } from "three";
|
|
4
|
+
import { Dictionary } from "../../models/dictionary.model";
|
|
5
|
+
import { WorkerThreadPool } from "./base/worker-pool";
|
|
6
|
+
export declare class ViralViewerWorker3 {
|
|
7
|
+
viralViewerApi: ViralViewerApi;
|
|
8
|
+
workerPool: WorkerThreadPool;
|
|
9
|
+
materials: RenderMaterial[];
|
|
10
|
+
mainModel: Mesh | null;
|
|
11
|
+
threejsMaterials: Dictionary<number, MeshPhongMaterial>;
|
|
12
|
+
private readonly maxPolygonPerObject;
|
|
13
|
+
private readonly maxPolygonForEdge;
|
|
14
|
+
private threejsLoader;
|
|
15
|
+
constructor(viralViewerApi: ViralViewerApi, scriptUrl?: string);
|
|
16
|
+
initial(materials: RenderMaterial[]): void;
|
|
17
|
+
loadStructuralGeometry(model: ViralViewerRevitStructuralGeometry, callbackOnSuccess?: () => void): void;
|
|
18
|
+
loadNoneStructuralGeometry(model: ViralViewerRevitNoneStructuralGeometry, callbackOnSuccess?: () => void): void;
|
|
19
|
+
rgbToHex(r: number, g: number, b: number): string;
|
|
20
|
+
componentToHex(c: number): string;
|
|
21
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ViralViewerWorker3 = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const three_1 = require("three");
|
|
6
|
+
// import { workerCode } from "../worker-script/load-model-worker-2.script";
|
|
7
|
+
const threejs_types_1 = require("../worker-script/threejs.types");
|
|
8
|
+
const dictionary_model_1 = require("../../models/dictionary.model");
|
|
9
|
+
const worker_pool_1 = require("./base/worker-pool");
|
|
10
|
+
class ViralViewerWorker3 {
|
|
11
|
+
constructor(viralViewerApi, scriptUrl = "../worker-script/load-model-worker-2.script.js") {
|
|
12
|
+
this.viralViewerApi = viralViewerApi;
|
|
13
|
+
this.materials = [];
|
|
14
|
+
this.mainModel = null;
|
|
15
|
+
this.threejsMaterials = new dictionary_model_1.Dictionary();
|
|
16
|
+
this.maxPolygonPerObject = 1000;
|
|
17
|
+
this.maxPolygonForEdge = 1000;
|
|
18
|
+
this.threejsLoader = new three_1.BufferGeometryLoader();
|
|
19
|
+
// Create a new Blob containing the worker code
|
|
20
|
+
const blob = new Blob([`(${threejs_types_1.workerCode})()`]);
|
|
21
|
+
const workerPath = URL.createObjectURL(blob);
|
|
22
|
+
// Create a new Worker from the Blob
|
|
23
|
+
this.workerPool = new worker_pool_1.WorkerThreadPool(4, workerPath);
|
|
24
|
+
}
|
|
25
|
+
initial(materials) {
|
|
26
|
+
this.materials = materials;
|
|
27
|
+
this.mainModel = new three_1.Mesh();
|
|
28
|
+
this.mainModel.name = "Viral Model";
|
|
29
|
+
this.viralViewerApi.viralScene.addObject(this.mainModel);
|
|
30
|
+
for (let index = 0; index < materials.length; index++) {
|
|
31
|
+
const material = materials[index];
|
|
32
|
+
let colorString = this.rgbToHex(material.Red, material.Green, material.Blue);
|
|
33
|
+
let renderMaterial = new three_1.MeshPhongMaterial({
|
|
34
|
+
color: colorString,
|
|
35
|
+
opacity: material.Opacity,
|
|
36
|
+
transparent: material.Opacity != 1 ? true : false,
|
|
37
|
+
// flatShading: true,
|
|
38
|
+
name: material.Name
|
|
39
|
+
});
|
|
40
|
+
this.threejsMaterials.add(index, renderMaterial);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
loadStructuralGeometry(model, callbackOnSuccess = () => { }) {
|
|
44
|
+
let inputData = new types_1.ViralViewerRevitNoneStructuralGeometry();
|
|
45
|
+
inputData.Indices = model.Indices;
|
|
46
|
+
inputData.Vertices = model.Vertices;
|
|
47
|
+
this.workerPool.Enqueue(inputData, (data) => {
|
|
48
|
+
let mesh = this.threejsLoader.parse(data);
|
|
49
|
+
console.log(mesh);
|
|
50
|
+
// let buffer = data.buffer;
|
|
51
|
+
// const geometry = new BufferGeometry();
|
|
52
|
+
// geometry.setAttribute("position", new BufferAttribute(buffer, 3));
|
|
53
|
+
// geometry.computeVertexNormals();
|
|
54
|
+
// const edges = new EdgesGeometry(geometry, 90);
|
|
55
|
+
// const line = new LineSegments(
|
|
56
|
+
// edges,
|
|
57
|
+
// new LineBasicMaterial({ color: "#202020", linewidth: 0.5 })
|
|
58
|
+
// );
|
|
59
|
+
// const childMesh = new Mesh(geometry, this.threejsMaterials.get(model.MaterialIndex));
|
|
60
|
+
// childMesh.add(line);
|
|
61
|
+
// childMesh.castShadow = true;
|
|
62
|
+
// childMesh.receiveShadow = true;
|
|
63
|
+
// if (this.mainModel)
|
|
64
|
+
// this.mainModel.add(childMesh);
|
|
65
|
+
// this.viralViewerApi.viralRenderer.render();
|
|
66
|
+
callbackOnSuccess();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
loadNoneStructuralGeometry(model, callbackOnSuccess = () => { }) {
|
|
70
|
+
this.workerPool.Enqueue(model, (data) => {
|
|
71
|
+
let mesh = this.threejsLoader.parse(data.data);
|
|
72
|
+
console.log(mesh);
|
|
73
|
+
// // let buffer = data.buffer;
|
|
74
|
+
// let geometry = new BufferGeometry();
|
|
75
|
+
// // const dummyGeometry = new BufferGeometry();
|
|
76
|
+
// // dummyGeometry.setAttribute("position", new BufferAttribute(buffer, 3));
|
|
77
|
+
// // In case number of polygon larger than expect, merge them to reduce polygon first, for optimize purpose
|
|
78
|
+
// if (dummyGeometry.attributes.position.count > this.maxPolygonPerObject) {
|
|
79
|
+
// const modifier = new SimplifyModifier();
|
|
80
|
+
// const ratio = this.maxPolygonPerObject / dummyGeometry.attributes.position.count;
|
|
81
|
+
// const count = Math.floor(dummyGeometry.attributes.position.count * ratio); // number of polygon to remove
|
|
82
|
+
// geometry = modifier.modify(dummyGeometry, count);
|
|
83
|
+
// console.log(model.Name, dummyGeometry.attributes.position.count, geometry.attributes.position.count)
|
|
84
|
+
// }
|
|
85
|
+
// else {
|
|
86
|
+
// geometry = dummyGeometry;
|
|
87
|
+
// }
|
|
88
|
+
// // geometry.computeVertexNormals();
|
|
89
|
+
// const childMesh = new InstancedMesh(geometry, this.threejsMaterials.get(model.MaterialIndex), model.Instances.length);
|
|
90
|
+
// childMesh.castShadow = true;
|
|
91
|
+
// childMesh.receiveShadow = true;
|
|
92
|
+
// for (let index = 0; index < model.Instances.length; index++) {
|
|
93
|
+
// const transform = model.Instances[index];
|
|
94
|
+
// let numbers = [
|
|
95
|
+
// transform.BasisX.X,
|
|
96
|
+
// -transform.BasisX.Z,
|
|
97
|
+
// -transform.BasisX.Y,
|
|
98
|
+
// 0,
|
|
99
|
+
// -transform.BasisZ.X,
|
|
100
|
+
// transform.BasisZ.Z,
|
|
101
|
+
// transform.BasisZ.Y,
|
|
102
|
+
// 0,
|
|
103
|
+
// -transform.BasisY.X,
|
|
104
|
+
// transform.BasisY.Z,
|
|
105
|
+
// transform.BasisY.Y,
|
|
106
|
+
// 0,
|
|
107
|
+
// -transform.Offset.X,
|
|
108
|
+
// transform.Offset.Z,
|
|
109
|
+
// transform.Offset.Y,
|
|
110
|
+
// 1,
|
|
111
|
+
// ];
|
|
112
|
+
// //transform first
|
|
113
|
+
// let matrix4 = new Matrix4();
|
|
114
|
+
// matrix4.fromArray(numbers);
|
|
115
|
+
// childMesh.setMatrixAt(index, matrix4);
|
|
116
|
+
// //if number of polygon smaller than expect, generate edges
|
|
117
|
+
// if (geometry.attributes.position.count < this.maxPolygonForEdge) {
|
|
118
|
+
// const edges = new EdgesGeometry(geometry, 90);
|
|
119
|
+
// const line = new LineSegments(
|
|
120
|
+
// edges,
|
|
121
|
+
// new LineBasicMaterial({ color: "#666", linewidth: 0.5 })
|
|
122
|
+
// );
|
|
123
|
+
// line.applyMatrix4(matrix4);
|
|
124
|
+
// childMesh.add(line);
|
|
125
|
+
// }
|
|
126
|
+
// }
|
|
127
|
+
// if (this.mainModel) {
|
|
128
|
+
// this.mainModel.add(childMesh);
|
|
129
|
+
// }
|
|
130
|
+
callbackOnSuccess();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
rgbToHex(r, g, b) {
|
|
134
|
+
return "#" + this.componentToHex(r) + this.componentToHex(g) + this.componentToHex(b);
|
|
135
|
+
}
|
|
136
|
+
componentToHex(c) {
|
|
137
|
+
var hex = c.toString(16);
|
|
138
|
+
return hex.length == 1 ? "0" + hex : hex;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.ViralViewerWorker3 = ViralViewerWorker3;
|
|
142
|
+
//# sourceMappingURL=viral-viewer-3.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viral-viewer-3.worker.js","sourceRoot":"","sources":["../../../src/components/worker/viral-viewer-3.worker.ts"],"names":[],"mappings":";;;AACA,uCAA4K;AAC5K,iCAAsN;AACtN,4EAA4E;AAC5E,kEAA4D;AAC5D,oEAA2D;AAC3D,oDAAsD;AAGtD,MAAa,kBAAkB;IAQ3B,YAAmB,cAA8B,EAAE,YAAoB,gDAAgD;QAApG,mBAAc,GAAd,cAAc,CAAgB;QAN1C,cAAS,GAAqB,EAAE,CAAC;QACjC,cAAS,GAAgB,IAAI,CAAC;QAC9B,qBAAgB,GAA0C,IAAI,6BAAU,EAA6B,CAAC;QAC5F,wBAAmB,GAAG,IAAI,CAAC;QAC3B,sBAAiB,GAAG,IAAI,CAAC;QAClC,kBAAa,GAAG,IAAI,4BAAoB,EAAE,CAAC;QAG/C,+CAA+C;QAC/C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,0BAAU,KAAK,CAAC,CAAC,CAAC;QAC7C,MAAM,UAAU,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC7C,oCAAoC;QACpC,IAAI,CAAC,UAAU,GAAG,IAAI,8BAAgB,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;IACM,OAAO,CAAC,SAA2B;QACtC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,IAAI,CAAC,SAAS,GAAG,IAAI,YAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,SAAS,CAAC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,qBAAqB;YACrB,uEAAuE;YACvE,aAAa;YACb,sCAAsC;YACtC,+BAA+B;YAC/B,QAAQ;YAGR,IAAI;YACJ,wBAAwB;YACxB,qCAAqC;YACrC,IAAI;YACJ,iBAAiB,EAAE,CAAC;QACxB,CAAC,CAAC,CAAA;IACN,CAAC;IACM,QAAQ,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS;QAC3C,OAAO,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1F,CAAC;IACM,cAAc,CAAC,CAAS;QAC3B,IAAI,GAAG,GAAG,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;AA1ID,gDA0IC"}
|
|
@@ -75475,6 +75475,8 @@ function workerFunction() {
|
|
|
75475
75475
|
}
|
|
75476
75476
|
return new BufferAttribute(array, itemSize, normalized);
|
|
75477
75477
|
}
|
|
75478
|
+
const maxPolygonPerObject = 1000;
|
|
75479
|
+
const maxPolygonForEdge = 1000;
|
|
75478
75480
|
function addMesh(indices, vertices, transform = null, callback = (buffer) => { }) {
|
|
75479
75481
|
let verticePoints = [];
|
|
75480
75482
|
if (transform == null) {
|
|
@@ -75533,17 +75535,71 @@ function workerFunction() {
|
|
|
75533
75535
|
});
|
|
75534
75536
|
}
|
|
75535
75537
|
self.addEventListener("message", (event) => {
|
|
75538
|
+
let data = event.data;
|
|
75536
75539
|
progressGeometries(event.data, (buffer) => {
|
|
75537
75540
|
const dummyGeometry = new BufferGeometry();
|
|
75538
75541
|
dummyGeometry.setAttribute("position", new BufferAttribute(buffer, 3));
|
|
75539
|
-
|
|
75540
|
-
|
|
75541
|
-
|
|
75542
|
-
|
|
75543
|
-
|
|
75544
|
-
|
|
75542
|
+
dummyGeometry.computeVertexNormals();
|
|
75543
|
+
if (data.Instances > 0) {
|
|
75544
|
+
const childMesh = new InstancedMesh(dummyGeometry, null, data.Instances.length);
|
|
75545
|
+
childMesh.castShadow = true;
|
|
75546
|
+
childMesh.receiveShadow = true;
|
|
75547
|
+
for (let index = 0; index < data.Instances.length; index++) {
|
|
75548
|
+
const transform = data.Instances[index];
|
|
75549
|
+
let numbers = [
|
|
75550
|
+
transform.BasisX.X,
|
|
75551
|
+
-transform.BasisX.Z,
|
|
75552
|
+
-transform.BasisX.Y,
|
|
75553
|
+
0,
|
|
75554
|
+
-transform.BasisZ.X,
|
|
75555
|
+
transform.BasisZ.Z,
|
|
75556
|
+
transform.BasisZ.Y,
|
|
75557
|
+
0,
|
|
75558
|
+
-transform.BasisY.X,
|
|
75559
|
+
transform.BasisY.Z,
|
|
75560
|
+
transform.BasisY.Y,
|
|
75561
|
+
0,
|
|
75562
|
+
-transform.Offset.X,
|
|
75563
|
+
transform.Offset.Z,
|
|
75564
|
+
transform.Offset.Y,
|
|
75565
|
+
1,
|
|
75566
|
+
];
|
|
75567
|
+
//transform first
|
|
75568
|
+
let matrix4 = new Matrix4();
|
|
75569
|
+
matrix4.fromArray(numbers);
|
|
75570
|
+
childMesh.setMatrixAt(index, matrix4);
|
|
75571
|
+
//if number of polygon smaller than expect, generate edges
|
|
75572
|
+
if (dummyGeometry.attributes.position.count < maxPolygonForEdge) {
|
|
75573
|
+
const edges = new EdgesGeometry(dummyGeometry, 90);
|
|
75574
|
+
const line = new LineSegments(edges, new LineBasicMaterial({ color: "#666", linewidth: 0.5 }));
|
|
75575
|
+
line.applyMatrix4(matrix4);
|
|
75576
|
+
childMesh.add(line);
|
|
75577
|
+
}
|
|
75578
|
+
}
|
|
75579
|
+
let jsonData = childMesh.toJSON();
|
|
75580
|
+
self.postMessage(jsonData);
|
|
75581
|
+
}
|
|
75582
|
+
else {
|
|
75583
|
+
const edges = new EdgesGeometry(dummyGeometry, 90);
|
|
75584
|
+
const line = new LineSegments(edges, new LineBasicMaterial({ color: "#202020", linewidth: 0.5 }));
|
|
75585
|
+
const childMesh = new Mesh(dummyGeometry);
|
|
75586
|
+
childMesh.add(line);
|
|
75587
|
+
childMesh.castShadow = true;
|
|
75588
|
+
childMesh.receiveShadow = true;
|
|
75589
|
+
let jsonData = childMesh.toJSON();
|
|
75590
|
+
self.postMessage(jsonData);
|
|
75591
|
+
}
|
|
75545
75592
|
});
|
|
75546
75593
|
}, false);
|
|
75594
|
+
class ViralViewerRevitNoneStructuralGeometry {
|
|
75595
|
+
constructor() {
|
|
75596
|
+
this.MaterialIndex = 0;
|
|
75597
|
+
this.Vertices = [];
|
|
75598
|
+
this.Indices = [];
|
|
75599
|
+
this.Name = "";
|
|
75600
|
+
this.Instances = [];
|
|
75601
|
+
}
|
|
75602
|
+
}
|
|
75547
75603
|
}
|
|
75548
75604
|
exports.workerCode = workerFunction;
|
|
75549
75605
|
//# sourceMappingURL=threejs.types.js.map
|