dymokomi/luce-3d
Source of release 0.9.5
0.9.5 / src / renderers / subdivision_draw.lucb
## Drawing a subdivided cage (geocore subdivision): the surface pass draws
## its limit-surface display mesh (made by the compute worker, a cache hit
## here), wires stay on the cage, and a face selection of the cage tints the
## display faces that came from the selected cage faces.
from luce_geocore import geocore
from luce_geocore.geocore import Matrix4
from luce_geocore.kernel import Domain
from renderers.mesh_batch import FaceHighlight
## `cage`'s face highlight for `display`'s faces (by `.cage_face`), into
## `out`; cheap when neither changed.
pub func display_highlight(cage: const FaceHighlight*, display: const geocore.Mesh*, out: FaceHighlight*) -> !:
out.color = cage.color
out.weight = cage.weight
let topology = display.corners_id()
let key = (cage.key *% 0x9E3779B97F4A7C15) ^ topology
if key == out.key and topology == out.topology: return
out.topology = topology
out.key = key
if cage.words.count == 0:
out.words.clear()
return
let index = display.find_attribute(".cage_face", (i64)(u8)Domain.face)
let faces = (usize)display.face_count()
try out.words.fill((faces + 31) // 32, 0)
if index < 0: return
let entry = try display.attribute_entry(index)
let owners = u32[]((u32*)entry.data.view().data, faces)
let words = cage.words.view()
for face in 0..<faces:
let owner = (usize)owners[face]
if owner // 32 < words.length and (words[owner // 32] >> (u32)(owner % 32)) & 1 != 0:
out.words.items[face // 32] |= (u32)1 << (u32)(face % 32)
## The cage face display face `face` came from (a pick's -1 stays).
pub func cage_face_of(display: const geocore.Mesh*, face: i64) -> i64!:
if face < 0: return face
let owners = try cage_faces(display)
if owners.length == 0: return face
return (i64)owners[(usize)face] if (usize)face < owners.length else -1
## The cage face of each of `display`'s faces (empty: it has no
## `.cage_face`, its faces are their own).
pub func cage_faces(display: const geocore.Mesh*) -> const u32[]!:
let index = display.find_attribute(".cage_face", (i64)(u8)Domain.face)
if index < 0:
var empty: u32[]
return empty
let entry = try display.attribute_entry(index)
return u32[]((u32*)entry.data.view().data, (usize)display.face_count())