viral-viewer-2 3.0.4 → 3.0.5

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.
@@ -34041,7 +34041,7 @@ function workerFunction() {
34041
34041
  //////////////////
34042
34042
  const maxPolygonPerObject = 1000;
34043
34043
  const maxPolygonForEdge = 1000;
34044
- function addMesh(indices, vertices, transform = null, callback = (buffer) => { }) {
34044
+ function addMesh(indices, vertices, transform = null) {
34045
34045
  let verticePoints = [];
34046
34046
  if (transform == null) {
34047
34047
  for (let i = 0; i < indices.length; i++) {
@@ -34052,8 +34052,7 @@ function workerFunction() {
34052
34052
  verticePoints.push(point.Y);
34053
34053
  }
34054
34054
  const buffer = new Float32Array(verticePoints);
34055
- callback(buffer);
34056
- return;
34055
+ return buffer;
34057
34056
  }
34058
34057
  let numbers = [
34059
34058
  transform.BasisX.X,
@@ -34091,109 +34090,107 @@ function workerFunction() {
34091
34090
  verticePoints.push(point.z);
34092
34091
  }
34093
34092
  const buffer = new Float32Array(verticePoints);
34094
- callback(buffer);
34093
+ return buffer;
34095
34094
  }
34096
- function progressGeometries(json, callback = (buffer) => { }) {
34097
- addMesh(json.Indices, json.Vertices, json.Transform, (buffer) => {
34098
- callback(buffer);
34099
- });
34095
+ function progressGeometries(json) {
34096
+ let buffer = addMesh(json.Indices, json.Vertices, json.Transform);
34097
+ return buffer;
34100
34098
  }
34101
34099
  self.addEventListener("message", (event) => {
34102
- progressGeometries(event.data, (buffer) => {
34103
- const dummyGeometry = new BufferGeometry();
34104
- dummyGeometry.setAttribute("position", new BufferAttribute(buffer, 3));
34105
- dummyGeometry.computeVertexNormals();
34106
- if (event.data.Instances > 0) {
34107
- let geometry = new BufferGeometry();
34108
- // In case number of polygon larger than expect, merge them to reduce polygon first, for optimize purpose
34109
- if (dummyGeometry.attributes.position.count > maxPolygonPerObject) {
34110
- const modifier = new SimplifyModifier();
34111
- const ratio = maxPolygonPerObject / dummyGeometry.attributes.position.count;
34112
- const count = Math.floor(dummyGeometry.attributes.position.count * ratio); // number of polygon to remove
34113
- geometry = modifier.modify(dummyGeometry, count);
34114
- console.log(dummyGeometry.attributes.position.count, geometry.attributes.position.count);
34115
- }
34116
- else {
34117
- geometry = dummyGeometry;
34118
- }
34119
- const childMesh = new InstancedMesh(geometry, null, event.data.Instances.length);
34120
- childMesh.castShadow = true;
34121
- childMesh.receiveShadow = true;
34122
- for (let index = 0; index < event.data.Instances.length; index++) {
34123
- const transform = event.data.Instances[index];
34124
- let numbers = [
34125
- transform.BasisX.X,
34126
- -transform.BasisX.Z,
34127
- -transform.BasisX.Y,
34128
- 0,
34129
- -transform.BasisZ.X,
34130
- transform.BasisZ.Z,
34131
- transform.BasisZ.Y,
34132
- 0,
34133
- -transform.BasisY.X,
34134
- transform.BasisY.Z,
34135
- transform.BasisY.Y,
34136
- 0,
34137
- -transform.Offset.X,
34138
- transform.Offset.Z,
34139
- transform.Offset.Y,
34140
- 1,
34141
- ];
34142
- //transform first
34143
- let matrix4 = new Matrix4();
34144
- matrix4.fromArray(numbers);
34145
- childMesh.setMatrixAt(index, matrix4);
34146
- //if number of polygon smaller than expect, generate edges
34147
- if (geometry.attributes.position.count < maxPolygonForEdge) {
34148
- const edges = new EdgesGeometry(geometry, 90);
34149
- const positions = edges.attributes.position.array;
34150
- const indices = [];
34151
- for (let i = 0; i < positions.length / 3; i += 2) {
34152
- indices.push(i, i + 1);
34153
- }
34154
- const bufferGeometry = new BufferGeometry();
34155
- // Set the position attribute
34156
- bufferGeometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
34157
- // Set the index attribute
34158
- bufferGeometry.setIndex(indices);
34159
- const line = new LineSegments(bufferGeometry, new LineBasicMaterial({ color: "#666", linewidth: 0.5 }));
34160
- line.applyMatrix4(matrix4);
34161
- line.updateMatrix();
34162
- childMesh.add(line);
34163
- }
34164
- }
34165
- // childMesh.instanceMatrix.needsUpdate = true;
34166
- childMesh.updateMatrix();
34167
- let jsonData = childMesh.toJSON();
34168
- // jsonData.object.type = "InstancedMesh";
34169
- // jsonData.object.count = childMesh.count;
34170
- // jsonData.object.instanceMatrix = childMesh.instanceMatrix.toJSON();
34171
- // if (this.instanceColor !== null)
34172
- // jsonData.object.instanceColor = childMesh.instanceColor.toJSON();
34173
- console.log(jsonData);
34174
- self.postMessage(jsonData);
34100
+ let buffer = progressGeometries(event.data);
34101
+ const dummyGeometry = new BufferGeometry();
34102
+ dummyGeometry.setAttribute("position", new BufferAttribute(buffer, 3));
34103
+ dummyGeometry.computeVertexNormals();
34104
+ if (event.data.Instances > 0) {
34105
+ let geometry = new BufferGeometry();
34106
+ // In case number of polygon larger than expect, merge them to reduce polygon first, for optimize purpose
34107
+ if (dummyGeometry.attributes.position.count > maxPolygonPerObject) {
34108
+ const modifier = new SimplifyModifier();
34109
+ const ratio = maxPolygonPerObject / dummyGeometry.attributes.position.count;
34110
+ const count = Math.floor(dummyGeometry.attributes.position.count * ratio); // number of polygon to remove
34111
+ geometry = modifier.modify(dummyGeometry, count);
34112
+ console.log(dummyGeometry.attributes.position.count, geometry.attributes.position.count);
34175
34113
  }
34176
34114
  else {
34177
- const edges = new EdgesGeometry(dummyGeometry, 90);
34178
- const positions = edges.attributes.position.array;
34179
- const indices = [];
34180
- for (let i = 0; i < positions.length / 3; i += 2) {
34181
- indices.push(i, i + 1);
34182
- }
34183
- const bufferGeometry = new BufferGeometry();
34184
- // Set the position attribute
34185
- bufferGeometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
34186
- // Set the index attribute
34187
- bufferGeometry.setIndex(indices);
34188
- const line = new LineSegments(bufferGeometry, new LineBasicMaterial({ color: "#202020", linewidth: 0.5 }));
34189
- const childMesh = new Mesh(dummyGeometry);
34190
- childMesh.add(line);
34191
- childMesh.castShadow = true;
34192
- childMesh.receiveShadow = true;
34193
- let jsonData = childMesh.toJSON();
34194
- self.postMessage(jsonData);
34195
- }
34196
- });
34115
+ geometry = dummyGeometry;
34116
+ }
34117
+ const childMesh = new InstancedMesh(geometry, null, event.data.Instances.length);
34118
+ childMesh.castShadow = true;
34119
+ childMesh.receiveShadow = true;
34120
+ for (let index = 0; index < event.data.Instances.length; index++) {
34121
+ const transform = event.data.Instances[index];
34122
+ let numbers = [
34123
+ transform.BasisX.X,
34124
+ -transform.BasisX.Z,
34125
+ -transform.BasisX.Y,
34126
+ 0,
34127
+ -transform.BasisZ.X,
34128
+ transform.BasisZ.Z,
34129
+ transform.BasisZ.Y,
34130
+ 0,
34131
+ -transform.BasisY.X,
34132
+ transform.BasisY.Z,
34133
+ transform.BasisY.Y,
34134
+ 0,
34135
+ -transform.Offset.X,
34136
+ transform.Offset.Z,
34137
+ transform.Offset.Y,
34138
+ 1,
34139
+ ];
34140
+ //transform first
34141
+ let matrix4 = new Matrix4();
34142
+ matrix4.fromArray(numbers);
34143
+ childMesh.setMatrixAt(index, matrix4);
34144
+ //if number of polygon smaller than expect, generate edges
34145
+ if (geometry.attributes.position.count < maxPolygonForEdge) {
34146
+ const edges = new EdgesGeometry(geometry, 90);
34147
+ const positions = edges.attributes.position.array;
34148
+ const indices = [];
34149
+ for (let i = 0; i < positions.length / 3; i += 2) {
34150
+ indices.push(i, i + 1);
34151
+ }
34152
+ const bufferGeometry = new BufferGeometry();
34153
+ // Set the position attribute
34154
+ bufferGeometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
34155
+ // Set the index attribute
34156
+ bufferGeometry.setIndex(indices);
34157
+ const line = new LineSegments(bufferGeometry, new LineBasicMaterial({ color: "#666", linewidth: 0.5 }));
34158
+ line.applyMatrix4(matrix4);
34159
+ line.updateMatrix();
34160
+ childMesh.add(line);
34161
+ }
34162
+ }
34163
+ // childMesh.instanceMatrix.needsUpdate = true;
34164
+ childMesh.updateMatrix();
34165
+ let jsonData = childMesh.toJSON();
34166
+ // jsonData.object.type = "InstancedMesh";
34167
+ // jsonData.object.count = childMesh.count;
34168
+ // jsonData.object.instanceMatrix = childMesh.instanceMatrix.toJSON();
34169
+ // if (this.instanceColor !== null)
34170
+ // jsonData.object.instanceColor = childMesh.instanceColor.toJSON();
34171
+ console.log(jsonData);
34172
+ self.postMessage(jsonData);
34173
+ }
34174
+ else {
34175
+ const edges = new EdgesGeometry(dummyGeometry, 90);
34176
+ const positions = edges.attributes.position.array;
34177
+ const indices = [];
34178
+ for (let i = 0; i < positions.length / 3; i += 2) {
34179
+ indices.push(i, i + 1);
34180
+ }
34181
+ const bufferGeometry = new BufferGeometry();
34182
+ // Set the position attribute
34183
+ bufferGeometry.setAttribute("position", new BufferAttribute(new Float32Array(positions), 3));
34184
+ // Set the index attribute
34185
+ bufferGeometry.setIndex(indices);
34186
+ const line = new LineSegments(bufferGeometry, new LineBasicMaterial({ color: "#202020", linewidth: 0.5 }));
34187
+ const childMesh = new Mesh(dummyGeometry);
34188
+ childMesh.add(line);
34189
+ childMesh.castShadow = true;
34190
+ childMesh.receiveShadow = true;
34191
+ let jsonData = childMesh.toJSON();
34192
+ self.postMessage(jsonData);
34193
+ }
34197
34194
  }, false);
34198
34195
  class ViralViewerRevitNoneStructuralGeometry {
34199
34196
  constructor() {