viral-viewer-2 2.7.9 → 2.8.1
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 +9 -13
- 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 +155 -5
- 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,8 +3,7 @@ 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");
|
|
10
9
|
const simplify_modifier_1 = require("../../threejs-addon/simplify-modifier");
|
|
@@ -16,9 +15,8 @@ class ViralViewerWorker2 {
|
|
|
16
15
|
this.threejsMaterials = new dictionary_model_1.Dictionary();
|
|
17
16
|
this.maxPolygonPerObject = 1000;
|
|
18
17
|
this.maxPolygonForEdge = 1000;
|
|
19
|
-
this.threejsLoader = new three_1.BufferGeometryLoader();
|
|
20
18
|
// Create a new Blob containing the worker code
|
|
21
|
-
const blob = new Blob([`(${
|
|
19
|
+
const blob = new Blob([`(${load_model_worker_2_script_1.workerCode})()`]);
|
|
22
20
|
const workerPath = URL.createObjectURL(blob);
|
|
23
21
|
// Create a new Worker from the Blob
|
|
24
22
|
this.workerPool = new worker_pool_1.WorkerThreadPool(4, workerPath);
|
|
@@ -46,11 +44,10 @@ class ViralViewerWorker2 {
|
|
|
46
44
|
inputData.Indices = model.Indices;
|
|
47
45
|
inputData.Vertices = model.Vertices;
|
|
48
46
|
this.workerPool.Enqueue(inputData, (data) => {
|
|
49
|
-
let
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// geometry.computeVertexNormals();
|
|
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();
|
|
54
51
|
const edges = new three_1.EdgesGeometry(geometry, 90);
|
|
55
52
|
const line = new three_1.LineSegments(edges, new three_1.LineBasicMaterial({ color: "#202020", linewidth: 0.5 }));
|
|
56
53
|
const childMesh = new three_1.Mesh(geometry, this.threejsMaterials.get(model.MaterialIndex));
|
|
@@ -68,11 +65,10 @@ class ViralViewerWorker2 {
|
|
|
68
65
|
inputData.Indices = model.Indices;
|
|
69
66
|
inputData.Vertices = model.Vertices;
|
|
70
67
|
this.workerPool.Enqueue(inputData, (data) => {
|
|
71
|
-
let
|
|
72
|
-
// let buffer = data.buffer;
|
|
68
|
+
let buffer = data.buffer;
|
|
73
69
|
let geometry = new three_1.BufferGeometry();
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
const dummyGeometry = new three_1.BufferGeometry();
|
|
71
|
+
dummyGeometry.setAttribute("position", new three_1.BufferAttribute(buffer, 3));
|
|
76
72
|
// In case number of polygon larger than expect, merge them to reduce polygon first, for optimize purpose
|
|
77
73
|
if (dummyGeometry.attributes.position.count > this.maxPolygonPerObject) {
|
|
78
74
|
const modifier = new simplify_modifier_1.SimplifyModifier();
|
|
@@ -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,sBAAiB,GAAG,IAAI,CAAC;QAGtC,+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,CAAC,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1D,CAAC;IACM,OAA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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-vi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I,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,102 @@ function workerFunction() {
|
|
|
75475
75475
|
}
|
|
75476
75476
|
return new BufferAttribute(array, itemSize, normalized);
|
|
75477
75477
|
}
|
|
75478
|
+
class EdgesGeometry extends BufferGeometry {
|
|
75479
|
+
constructor(geometry = null, thresholdAngle = 1) {
|
|
75480
|
+
super();
|
|
75481
|
+
this.type = 'EdgesGeometry';
|
|
75482
|
+
this.parameters = {
|
|
75483
|
+
geometry: geometry,
|
|
75484
|
+
thresholdAngle: thresholdAngle
|
|
75485
|
+
};
|
|
75486
|
+
if (geometry !== null) {
|
|
75487
|
+
const precisionPoints = 4;
|
|
75488
|
+
const precision = Math.pow(10, precisionPoints);
|
|
75489
|
+
const thresholdDot = Math.cos(MathUtils.DEG2RAD * thresholdAngle);
|
|
75490
|
+
const indexAttr = geometry.getIndex();
|
|
75491
|
+
const positionAttr = geometry.getAttribute('position');
|
|
75492
|
+
const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
|
|
75493
|
+
const indexArr = [0, 0, 0];
|
|
75494
|
+
const vertKeys = ['a', 'b', 'c'];
|
|
75495
|
+
const hashes = new Array(3);
|
|
75496
|
+
const edgeData = {};
|
|
75497
|
+
const vertices = [];
|
|
75498
|
+
for (let i = 0; i < indexCount; i += 3) {
|
|
75499
|
+
if (indexAttr) {
|
|
75500
|
+
indexArr[0] = indexAttr.getX(i);
|
|
75501
|
+
indexArr[1] = indexAttr.getX(i + 1);
|
|
75502
|
+
indexArr[2] = indexAttr.getX(i + 2);
|
|
75503
|
+
}
|
|
75504
|
+
else {
|
|
75505
|
+
indexArr[0] = i;
|
|
75506
|
+
indexArr[1] = i + 1;
|
|
75507
|
+
indexArr[2] = i + 2;
|
|
75508
|
+
}
|
|
75509
|
+
const { a, b, c } = _triangle;
|
|
75510
|
+
a.fromBufferAttribute(positionAttr, indexArr[0]);
|
|
75511
|
+
b.fromBufferAttribute(positionAttr, indexArr[1]);
|
|
75512
|
+
c.fromBufferAttribute(positionAttr, indexArr[2]);
|
|
75513
|
+
_triangle.getNormal(_normal);
|
|
75514
|
+
// create hashes for the edge from the vertices
|
|
75515
|
+
hashes[0] = `${Math.round(a.x * precision)},${Math.round(a.y * precision)},${Math.round(a.z * precision)}`;
|
|
75516
|
+
hashes[1] = `${Math.round(b.x * precision)},${Math.round(b.y * precision)},${Math.round(b.z * precision)}`;
|
|
75517
|
+
hashes[2] = `${Math.round(c.x * precision)},${Math.round(c.y * precision)},${Math.round(c.z * precision)}`;
|
|
75518
|
+
// skip degenerate triangles
|
|
75519
|
+
if (hashes[0] === hashes[1] || hashes[1] === hashes[2] || hashes[2] === hashes[0]) {
|
|
75520
|
+
continue;
|
|
75521
|
+
}
|
|
75522
|
+
// iterate over every edge
|
|
75523
|
+
for (let j = 0; j < 3; j++) {
|
|
75524
|
+
// get the first and next vertex making up the edge
|
|
75525
|
+
const jNext = (j + 1) % 3;
|
|
75526
|
+
const vecHash0 = hashes[j];
|
|
75527
|
+
const vecHash1 = hashes[jNext];
|
|
75528
|
+
const v0 = _triangle[vertKeys[j]];
|
|
75529
|
+
const v1 = _triangle[vertKeys[jNext]];
|
|
75530
|
+
const hash = `${vecHash0}_${vecHash1}`;
|
|
75531
|
+
const reverseHash = `${vecHash1}_${vecHash0}`;
|
|
75532
|
+
if (reverseHash in edgeData && edgeData[reverseHash]) {
|
|
75533
|
+
// if we found a sibling edge add it into the vertex array if
|
|
75534
|
+
// it meets the angle threshold and delete the edge from the map.
|
|
75535
|
+
if (_normal.dot(edgeData[reverseHash].normal) <= thresholdDot) {
|
|
75536
|
+
vertices.push(v0.x, v0.y, v0.z);
|
|
75537
|
+
vertices.push(v1.x, v1.y, v1.z);
|
|
75538
|
+
}
|
|
75539
|
+
edgeData[reverseHash] = null;
|
|
75540
|
+
}
|
|
75541
|
+
else if (!(hash in edgeData)) {
|
|
75542
|
+
// if we've already got an edge here then skip adding a new one
|
|
75543
|
+
edgeData[hash] = {
|
|
75544
|
+
index0: indexArr[j],
|
|
75545
|
+
index1: indexArr[jNext],
|
|
75546
|
+
normal: _normal.clone(),
|
|
75547
|
+
};
|
|
75548
|
+
}
|
|
75549
|
+
}
|
|
75550
|
+
}
|
|
75551
|
+
// iterate over all remaining, unmatched edges and add them to the vertex array
|
|
75552
|
+
for (const key in edgeData) {
|
|
75553
|
+
if (edgeData[key]) {
|
|
75554
|
+
const { index0, index1 } = edgeData[key];
|
|
75555
|
+
_v0.fromBufferAttribute(positionAttr, index0);
|
|
75556
|
+
_v1.fromBufferAttribute(positionAttr, index1);
|
|
75557
|
+
vertices.push(_v0.x, _v0.y, _v0.z);
|
|
75558
|
+
vertices.push(_v1.x, _v1.y, _v1.z);
|
|
75559
|
+
}
|
|
75560
|
+
}
|
|
75561
|
+
this.setAttribute('position', new Float32BufferAttribute(vertices, 3));
|
|
75562
|
+
}
|
|
75563
|
+
}
|
|
75564
|
+
copy(source) {
|
|
75565
|
+
super.copy(source);
|
|
75566
|
+
this.parameters = Object.assign({}, source.parameters);
|
|
75567
|
+
return this;
|
|
75568
|
+
}
|
|
75569
|
+
}
|
|
75570
|
+
//My code
|
|
75571
|
+
//////////////////
|
|
75572
|
+
const maxPolygonPerObject = 1000;
|
|
75573
|
+
const maxPolygonForEdge = 1000;
|
|
75478
75574
|
function addMesh(indices, vertices, transform = null, callback = (buffer) => { }) {
|
|
75479
75575
|
let verticePoints = [];
|
|
75480
75576
|
if (transform == null) {
|
|
@@ -75533,17 +75629,71 @@ function workerFunction() {
|
|
|
75533
75629
|
});
|
|
75534
75630
|
}
|
|
75535
75631
|
self.addEventListener("message", (event) => {
|
|
75632
|
+
let data = event.data;
|
|
75536
75633
|
progressGeometries(event.data, (buffer) => {
|
|
75537
75634
|
const dummyGeometry = new BufferGeometry();
|
|
75538
75635
|
dummyGeometry.setAttribute("position", new BufferAttribute(buffer, 3));
|
|
75539
75636
|
dummyGeometry.computeVertexNormals();
|
|
75540
|
-
|
|
75541
|
-
|
|
75542
|
-
|
|
75543
|
-
|
|
75544
|
-
|
|
75637
|
+
if (data.Instances > 0) {
|
|
75638
|
+
const childMesh = new InstancedMesh(dummyGeometry, null, data.Instances.length);
|
|
75639
|
+
childMesh.castShadow = true;
|
|
75640
|
+
childMesh.receiveShadow = true;
|
|
75641
|
+
for (let index = 0; index < data.Instances.length; index++) {
|
|
75642
|
+
const transform = data.Instances[index];
|
|
75643
|
+
let numbers = [
|
|
75644
|
+
transform.BasisX.X,
|
|
75645
|
+
-transform.BasisX.Z,
|
|
75646
|
+
-transform.BasisX.Y,
|
|
75647
|
+
0,
|
|
75648
|
+
-transform.BasisZ.X,
|
|
75649
|
+
transform.BasisZ.Z,
|
|
75650
|
+
transform.BasisZ.Y,
|
|
75651
|
+
0,
|
|
75652
|
+
-transform.BasisY.X,
|
|
75653
|
+
transform.BasisY.Z,
|
|
75654
|
+
transform.BasisY.Y,
|
|
75655
|
+
0,
|
|
75656
|
+
-transform.Offset.X,
|
|
75657
|
+
transform.Offset.Z,
|
|
75658
|
+
transform.Offset.Y,
|
|
75659
|
+
1,
|
|
75660
|
+
];
|
|
75661
|
+
//transform first
|
|
75662
|
+
let matrix4 = new Matrix4();
|
|
75663
|
+
matrix4.fromArray(numbers);
|
|
75664
|
+
childMesh.setMatrixAt(index, matrix4);
|
|
75665
|
+
//if number of polygon smaller than expect, generate edges
|
|
75666
|
+
if (dummyGeometry.attributes.position.count < maxPolygonForEdge) {
|
|
75667
|
+
const edges = new EdgesGeometry(dummyGeometry, 90);
|
|
75668
|
+
const line = new LineSegments(edges, new LineBasicMaterial({ color: "#666", linewidth: 0.5 }));
|
|
75669
|
+
line.applyMatrix4(matrix4);
|
|
75670
|
+
childMesh.add(line);
|
|
75671
|
+
}
|
|
75672
|
+
}
|
|
75673
|
+
let jsonData = childMesh.toJSON();
|
|
75674
|
+
self.postMessage(jsonData);
|
|
75675
|
+
}
|
|
75676
|
+
else {
|
|
75677
|
+
const edges = new EdgesGeometry(dummyGeometry, 90);
|
|
75678
|
+
const line = new LineSegments(edges, new LineBasicMaterial({ color: "#202020", linewidth: 0.5 }));
|
|
75679
|
+
const childMesh = new Mesh(dummyGeometry);
|
|
75680
|
+
childMesh.add(line);
|
|
75681
|
+
childMesh.castShadow = true;
|
|
75682
|
+
childMesh.receiveShadow = true;
|
|
75683
|
+
let jsonData = childMesh.toJSON();
|
|
75684
|
+
self.postMessage(jsonData);
|
|
75685
|
+
}
|
|
75545
75686
|
});
|
|
75546
75687
|
}, false);
|
|
75688
|
+
class ViralViewerRevitNoneStructuralGeometry {
|
|
75689
|
+
constructor() {
|
|
75690
|
+
this.MaterialIndex = 0;
|
|
75691
|
+
this.Vertices = [];
|
|
75692
|
+
this.Indices = [];
|
|
75693
|
+
this.Name = "";
|
|
75694
|
+
this.Instances = [];
|
|
75695
|
+
}
|
|
75696
|
+
}
|
|
75547
75697
|
}
|
|
75548
75698
|
exports.workerCode = workerFunction;
|
|
75549
75699
|
//# sourceMappingURL=threejs.types.js.map
|