UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

58 lines (57 loc) 2.06 kB
"use strict"; import { sortedNumber3 } from "./sortedIndices"; import { TET_FACE_POINT_INDICES } from "../TetCommon"; const _sortedIndices = [0, 0, 0]; const _sortedIndicesNeighbour = [0, 0, 0]; export function updateTetNeighboursFromNewTet(tetGeometry, tet) { for (let id0 = 0; id0 < 4; id0++) { const sharedPoint = tet.pointIds[id0]; const tetsSharingPoint = tetGeometry.tetrahedronsByPointId.get(sharedPoint); let faceIndex = 0; for (const facePointIndices of TET_FACE_POINT_INDICES) { if (!tetsSharingPoint) { continue; } sortedNumber3( tet.pointIds[facePointIndices[0]], tet.pointIds[facePointIndices[1]], tet.pointIds[facePointIndices[2]], _sortedIndices ); const [pt0, pt1, pt2] = _sortedIndices; tetsSharingPoint.forEach((tetId) => { if (tetId == tet.id) { return; } const tetSharingPoint = tetGeometry.tetrahedrons.get(tetId); if (!tetSharingPoint) { return; } let faceIndexNeighbour = 0; for (const facePointIndicesNeighbour of TET_FACE_POINT_INDICES) { sortedNumber3( tetSharingPoint.pointIds[facePointIndicesNeighbour[0]], tetSharingPoint.pointIds[facePointIndicesNeighbour[1]], tetSharingPoint.pointIds[facePointIndicesNeighbour[2]], _sortedIndicesNeighbour ); const [ptN0, ptN1, ptN2] = _sortedIndicesNeighbour; if (pt0 == ptN0 && pt1 == ptN1 && pt2 == ptN2) { tet.neighbours[faceIndex] = { id: tetSharingPoint.id, faceIndex: faceIndexNeighbour }; tetSharingPoint.neighbours[faceIndexNeighbour] = { id: tet.id, faceIndex }; } faceIndexNeighbour++; } }); faceIndex++; } } } export function tetNeighbour(tetGeometry, tetId, faceIndex) { var _a; const tetrahedron = tetGeometry.tetrahedrons.get(tetId); if (!tetrahedron) { return; } return (_a = tetrahedron.neighbours[faceIndex]) == null ? void 0 : _a.id; }