@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
83 lines (82 loc) • 2.56 kB
JavaScript
;
import { Vector4 } from "three";
import { QuadPrimitive } from "../QuadPrimitive";
import { QuadGraph } from "./QuadGraph";
import { arrayDifference } from "../../../../ArrayUtils";
const _v4 = new Vector4();
const _v40 = new Vector4();
const _v41 = new Vector4();
const _quad0IndicesSet = /* @__PURE__ */ new Set();
export function quadGraphFromQuadObject(object) {
const quadGraph = new QuadGraph();
const indices = object.geometry.index;
const primitivesCount = QuadPrimitive.entitiesCount(object);
for (let i = 0; i < primitivesCount; i++) {
_v4.fromArray(indices, i * 4);
quadGraph.addQuad(i, _v4.toArray());
}
return quadGraph;
}
const _neighbourIdsSharingEdge = [];
const _neighbourIdsSharingPoint = [];
export function quadGraphDirectDiagonalTiles(graph, quadId, target) {
graph.neighbourIdsSharingPoint(quadId, _neighbourIdsSharingPoint);
graph.neighbourIdsSharingEdge(quadId, _neighbourIdsSharingEdge);
arrayDifference(_neighbourIdsSharingPoint, _neighbourIdsSharingEdge, target);
}
export function halfEdgeIndicesInCommonBetweenQuads(options) {
const { quadObject, quadId0, quadId1, target } = options;
const srcIndices = quadObject.geometry.index;
_v40.fromArray(srcIndices, quadId0 * 4);
_v41.fromArray(srcIndices, quadId1 * 4);
_quad0IndicesSet.clear();
_quad0IndicesSet.add(_v40.x);
_quad0IndicesSet.add(_v40.y);
_quad0IndicesSet.add(_v40.z);
_quad0IndicesSet.add(_v40.w);
let firstPointAdded = false;
if (_quad0IndicesSet.has(_v41.x)) {
target.index0 = _v41.x;
firstPointAdded = true;
}
if (_quad0IndicesSet.has(_v41.y)) {
if (firstPointAdded) {
target.index1 = _v41.y;
return;
}
target.index0 = _v41.y;
firstPointAdded = true;
}
if (_quad0IndicesSet.has(_v41.z)) {
if (firstPointAdded) {
target.index1 = _v41.z;
return;
}
target.index0 = _v41.z;
firstPointAdded = true;
}
if (_quad0IndicesSet.has(_v41.w)) {
if (firstPointAdded) {
target.index1 = _v41.w;
return;
}
target.index0 = _v41.w;
firstPointAdded = true;
}
}
export function pointInCommonBetweenQuadsSharingPoint(graph, quadId0, quadId1) {
const quadNode0 = graph.quadNode(quadId0);
const quadNode1 = graph.quadNode(quadId1);
if (quadNode0 == null || quadNode1 == null) {
return;
}
const indices0 = quadNode0.indices;
const indices1 = quadNode1.indices;
for (const index0 of indices0) {
for (const index1 of indices1) {
if (index0 == index1) {
return index0;
}
}
}
}