viral-viewer-2 2.8.0 → 2.8.2

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.
@@ -75475,6 +75475,100 @@ 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(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
+ //////////////////
75478
75572
  const maxPolygonPerObject = 1000;
75479
75573
  const maxPolygonForEdge = 1000;
75480
75574
  function addMesh(indices, vertices, transform = null, callback = (buffer) => { }) {