Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.map((line) => {
// Make sure all points are in vec3 format and unique.
const points = uniqBy(
line.points.map((point) => (shouldConvert(point) ? pointToVec3(point) : point)),
([x, y, z]) => `${x}:${y}:${z}`
);
// We need a minimum of 4 points to do the convex hull algorithm.
if (points.length < 4) {
return null;
}
// Try to run hulling on the face indices. If there is an error, discard the result.
let faceIndices;
try {
faceIndices = qh(points);
} catch (error) {
console.error(error);
return null;
}
// From the point indices of each face, find the points and flatmap to get the points of the triangles.
const trianglePoints = flatMap(faceIndices, ([index1, index2, index3]) => {
return [points[index1], points[index2], points[index3]];
});
const convertedColor = typeof line.color.r === "number" ? line.color : vec4ToRGBA(line.color);
return {
pose: line.pose,
scale: line.scale,
color: convertedColor,
points: trianglePoints,
originalMarker: line.originalMarker,