Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-geocore

Source of release 0.7.2

0.7.2 / src / geometries / overlays.lucb

## Bulk CPU overlay extraction for worker preparation, with no Luce value boxes.
import memory
from geometries.polygon import Mesh
from math.vector import Vector3
from math.matrix import Matrix4

## Base-only owned heap endpoints. The caller frees the result on its thread.
## Normals are per-face guides; false extracts unique polygon edges.
pub func mesh_overlay_points(mesh: Mesh*, matrix: Matrix4, normals: bool = false) -> Vector3[]!:
    let count = mesh.face_count() if normals else (try mesh.edge_count())
    let points = try new Vector3[(usize)count * 2] --- in memory.heap
    errdefer free(points) in memory.heap
    let length = mesh.bounds().maximum.subtract(mesh.bounds().minimum).length() * 0.015
    for index in 0..<count:
        if not normals:
            points[(usize)index * 2] = matrix.transform_point(try mesh.point(try mesh.edge_point(index, 0)))
            points[(usize)index * 2 + 1] = matrix.transform_point(try mesh.point(try mesh.edge_point(index, 1)))
        else:
            let p = matrix.transform_point(try mesh.face_center(index))
            var n = Vector3()
            let offset = try mesh.face_offset(index)
            for corner in 0..<(try mesh.face_size(index)):
                n = n.add(try mesh.corner_normal(offset + corner))
            n = try n.normalized() if n.length() > 0.000000001 else (try mesh.face_normal(index))
            points[(usize)index * 2] = p
            # A face without an area (its normal zero) gets a guide of no length.
            points[(usize)index * 2 + 1] = p.add((try matrix.transform_normal(n)).multiply_scalar(length)) if n.length() > 0.000000001 else p
    return points