luv

Workshop wiki

mesh-variation.lisp

luft/mesh-variation.lisp

system luft · 8 definitions · on GitHub

in-package#:luft
defun%vary-surface-mesh-bevel-widths
owner-witnessesoutput-ownersrealize-context-ownerswidth-functionstock-maskssite-widthscontract-t-junctions-p

Compile one site policy and realize an owner-preserving mesh cohort.

check-typeowner-witnesseslist
check-typeoutput-ownerslist
check-typerealize-context-ownerslist
unlessowner-witnesses
error"A site-local bevel cohort must contain at least one witness."
unlessoutput-owners
error"A site-local bevel cohort must select at least one output owner."
whenwidth-function
check-typewidth-functionfunction
whenstock-masks
check-typestock-masksvector
check-typesite-widthsvector
unless
ifwidth-function
and
nullstock-masks
nullsite-widths
andstock-maskssite-widths
error"Specify exactly one site-local bevel policy representation."

Site policy remains semantic. The renderer's positive byte-mask lane folds through bounded sparse pages; arbitrary masks and the generic callback retain the EQL table oracle. Triangle realization stays in the witness's packed scalar language, and both compilers produce the same tight dense-or-sparse width field below.

let*
domain
surface-mesh-domain
cdarowner-witnesses
owner-set
make-hash-table:test#'equal
output-set
make-hash-table:test#'equal
realize-set
make-hash-table:test#'equal
output-witnessesnil
realized-witnessesnil
total-triangle-count0
width-by-sitenil
dense-widthsnil
site-count0
width-census
make-array5:element-type'
unsigned-byte32
:initial-element0
maximum-width1
minimum-site-xmost-positive-fixnum
maximum-site-xmost-negative-fixnum
minimum-site-ymost-positive-fixnum
maximum-site-ymost-negative-fixnum
minimum-site-zmost-positive-fixnum
maximum-site-zmost-negative-fixnum
dolist
owner-witnessowner-witnesses
unless
conspowner-witness
error"A bevel cohort entry must be (OWNER . SURFACE-MESH), not ~S."owner-witness
let
owner
carowner-witness
witness
cdrowner-witness
check-typewitnesssurface-mesh
when
nth-value1
gethashownerowner-set
error"Duplicate bevel cohort owner ~S."owner
setf
gethashownerowner-set
t
unless
world-domain=domain
surface-mesh-domainwitness
error"Bevel cohort owner ~S has a different world domain."owner
unless
=1
surface-mesh-bevel-widthwitness
error"A site-local bevel witness must have width one, not ~D."
surface-mesh-bevel-widthwitness
incftotal-triangle-count
dolist
owneroutput-owners
when
nth-value1
gethashowneroutput-set
error"Duplicate bevel cohort output owner ~S."owner
unless
nth-value1
gethashownerowner-set
error"Bevel cohort output owner ~S has no witness."owner
setf
gethashowneroutput-set
t
dolist
owner
appendoutput-ownersrealize-context-owners
unless
nth-value1
gethashownerowner-set
error"Bevel cohort realization owner ~S has no witness."owner
setf
gethashownerrealize-set
t
setfoutput-witnesses
remove-if-not
lambda
owner-witness
nth-value1
gethash
carowner-witness
output-set
owner-witnesses
realized-witnesses
remove-if-not
lambda
owner-witness
nth-value1
gethash
carowner-witness
realize-set
owner-witnesses
if
andstock-masks
%paged-byte-stock-mask-policy-pdomainstock-maskssite-widths
multiple-value-setq
width-by-sitedense-widthssite-countmaximum-widthminimum-site-xmaximum-site-xminimum-site-ymaximum-site-yminimum-site-zmaximum-site-z
%compile-paged-byte-stock-mask-bevel-sitesowner-witnessesstock-maskssite-widthswidth-census
progn
setfwidth-by-site
make-hash-table:test#'eql:size
max16
truncatetotal-triangle-count8
labels
owner-key
xyz
multiple-value-bind
site-xsite-ysite-zdirection-xdirection-ydirection-z
declare
ignoredirection-xdirection-ydirection-z
setfminimum-site-x
minminimum-site-xsite-x
maximum-site-x
maxmaximum-site-xsite-x
minimum-site-y
minminimum-site-ysite-y
maximum-site-y
maxmaximum-site-ysite-y
minimum-site-z
minminimum-site-zsite-z
maximum-site-z
maxmaximum-site-zsite-z
observe-stock
keystock
pushnewstock
gethashkeywidth-by-site
:test#'=
observe-stock-mask
keystock-mask
setf
gethashkeywidth-by-site
thefixnum
logiorstock-mask
thefixnum
gethashkeywidth-by-site0
declare
inlineowner-keyobserve-stockobserve-stock-mask
ftype
function
fixnumfixnum
*
observe-stockobserve-stock-mask
ifstock-masks
dolist
owner-witnessowner-witnesses
let
witness
cdrowner-witness
%do-surface-mesh-triangle-scalars
witnesskindstockambientmaskaxayazbxbybzcxcycz
declare
ignorekindambientmask
unless
<stock
lengthstock-masks
error"Mesh stock ~D is outside the compiled bevel policy of ~D entries."stock
lengthstock-masks
let
stock-mask
arefstock-masksstock
unless
typepstock-mask'
unsigned-byte61
error"Mesh stock ~D has invalid compiled bevel mask ~S."stockstock-mask
let*
stock-mask
thefixnumstock-mask
a
owner-keyaxayaz
b
owner-keybxbybz
c
owner-keycxcycz
observe-stock-maskastock-mask
unless
=ba
observe-stock-maskbstock-mask
unless
or
=ca
=cb
observe-stock-maskcstock-mask
dolist
owner-witnessowner-witnesses
let
witness
cdrowner-witness
%do-surface-mesh-triangle-scalars
witnesskindstockambientmaskaxayazbxbybzcxcycz
declare
ignorekindambientmask
let
a
owner-keyaxayaz
b
owner-keybxbybz
c
owner-keycxcycz
observe-stockastock
unless
=ba
observe-stockbstock
unless
or
=ca
=cb
observe-stockcstock
labels
record-width
unless
error"Site-local bevel policy assigned invalid width ~S at ~S."width
setf
gethashkeywidth-by-site
width
maximum-width
maxmaximum-widthwidth
incf
arefwidth-censuswidth
ifstock-masks
maphash
lambda
keysite-mask
unless
and
pluspsite-mask
<site-mask
lengthsite-widths
error"Incident mesh stocks compiled to invalid bevel mask ~D at ~S."site-mask
record-widthkey
arefsite-widthssite-mask
width-by-site
maphash
lambda
keystocks
record-widthkey
funcallwidth-function
sortstocks#'<
width-by-site
setfsite-count
hash-table-countwidth-by-site
when
zeropsite-count
setfminimum-site-x0maximum-site-x0minimum-site-y0maximum-site-y0minimum-site-z0maximum-site-z0
let*
site-x-span
1+
-maximum-site-xminimum-site-x
site-y-span
1+
-maximum-site-yminimum-site-y
site-z-span
1+
-maximum-site-zminimum-site-z
site-volume
*site-x-spansite-y-spansite-z-span
dense-widths
ordense-widths
when
make-arraysite-volume:element-type'
unsigned-byte8
:initial-element0
packing
%make-spatial-edge-packing-for-boxminimum-site-x
1+maximum-site-x
minimum-site-y
1+maximum-site-y
builder-by-owner
make-hash-table:test#'equal
live-triangle-counts-by-owner
make-hash-table:test#'equal
declare
typefixnumsite-x-spansite-y-spansite-z-spansite-volumesite-count
when
anddense-widthswidth-by-site
plusp
hash-table-countwidth-by-site
maphash
lambda
setf
arefdense-widths
%dense-bevel-site-indexminimum-site-xminimum-site-yminimum-site-zsite-y-spansite-z-span
width
width-by-site
clrhashwidth-by-site
dolist
owner-witnessrealized-witnesses
let*
owner
carowner-witness
witness
cdrowner-witness
builder
%make-surface-mesh-builderdomainmaximum-width
setf
surface-mesh-builder-singular-star-countbuilder
surface-mesh-singular-star-countwitness
gethashownerbuilder-by-owner
builder
gethashownerlive-triangle-counts-by-owner
make-array3:element-type'
unsigned-byte32
:initial-element0
let*
field
%make-bevel-site-width-fieldwidth-by-sitedense-widthsminimum-site-xminimum-site-yminimum-site-zsite-y-spansite-z-span
plan
%plan-variable-bevel-transitionsfieldowner-witnessesoutput-witnessesoutput-setrealize-setlive-triangle-counts-by-ownerpackingcontract-t-junctions-p
multiple-value-bind
owner-meshescontext-owner-meshes
%emit-variable-bevel-transition-ownersfieldrealized-witnessesoutput-setbuilder-by-ownerlive-triangle-counts-by-ownerpackingplan
let
candidate-splits
%bevel-transition-plan-candidate-splitsplan
valuesowner-mesheswidth-census
list:collapsed-triangle-count
%bevel-transition-plan-collapsed-triangle-countplan
:context-collapsed-triangle-count
%bevel-transition-plan-context-collapsed-triangle-countplan
:unmatched-edge-count
%bevel-transition-plan-unmatched-edge-countplan
:repaired-edge-count
hash-table-count
%bevel-transition-plan-repair-splitsplan
:residual-edge-count
%bevel-transition-plan-residual-edge-countplan
:candidate-splits
loopforedgebeingthehash-keysofcandidate-splitsusing
hash-valuepoints
append
multiple-value-bind
leftright
loopforpointinpointscollect
listleftright
context-owner-meshes
defun%vary-one-surface-mesh-bevel-widths
witnesswidth-functioncontract-t-junctions-p
check-typewidth-functionfunction
multiple-value-bind
owner-mesheswidth-censusdiagnostics
%vary-surface-mesh-bevel-widths
list
consnilwitness
listnil
nilwidth-functionnilnilcontract-t-junctions-p
values
cdarowner-meshes
width-censusdiagnostics
defunvary-surface-mesh-bevel-widths
witnesswidth-function

Evaluate one closed width-one witness at a local width per vertex site.

width-function is called once for each canonical lattice vertex as (width-function X Y Z INCIDENT-STOCKS) where INCIDENT-STOCKS is a sorted, duplicate-free list of the packed stocks on witness triangles using that site. It must return an integer width from one through four.

Every witness vertex has the exact affine form 8*S + Q with Q in {-1,0,1}^3. The result replaces it by 8*S + width(S)*Q. Since every incident primitive uses the same canonical S, shared vertices remain equal without stitching. At the medial limit a witness triangle can collapse to three collinear points. The result contracts that triangle by splitting its surviving neighbour's long edge at the middle point, eliminating the otherwise visible T-junction without inventing a surface. witness remains the rebuild oracle for topology and uniform-width geometry. Transition triangles may leave the uniform mesher's 26 exact normal directions. The packed trit normal remains an orientation witness; fragment shading derives the actual primitive normal from world-space position derivatives, so the new directions are not lighting-quantized.

The second value is a five-entry site census indexed by width. The third is a diagnostic plist containing the collapsed-triangle, locally unmatched-edge, repaired-edge, and residual-edge counts. For the required closed width-one witness, only a collapse can change edge parity, so the queried local counts are the complete transition defect. This production entry point always contracts medial T-junctions; the deliberately open study surface has a separate diagnostic name.

defunvary-uncontracted-surface-mesh-bevel-widths-diagnostic
witnesswidth-function

Return the deliberately open pre-repair variable-width study surface.

%vary-one-surface-mesh-bevel-widthswitnesswidth-functionnil
defun%vary-one-surface-mesh-bevel-widths-from-stock-masks
witnessstock-maskssite-widthscontract-t-junctions-p
check-typestock-masksvector
check-typesite-widthsvector
multiple-value-bind
owner-mesheswidth-censusdiagnostics
%vary-surface-mesh-bevel-widths
list
consnilwitness
listnil
nilnilstock-maskssite-widthscontract-t-junctions-p
values
cdarowner-meshes
width-censusdiagnostics
defunvary-surface-mesh-bevel-widths-from-stock-masks
witnessstock-maskssite-widths

Evaluate a closed width-one witness from an incident-stock mask policy.

stock-masks is indexed by packed triangle stock. The masks of every stock incident on a canonical vertex site are combined with LOGIOR, then that mask indexes site-widths. This is the dense production form of the generic callback contract: it preserves the same shared site field and the same realization and repair algorithm without constructing stock lists in the triangle loop.

Every referenced stock mask must be a positive fixnum bit mask, and each combined mask must be a valid site-widths index. Index zero is unused; every selected entry must be an integer width from one through four. This canonical entry point always repairs medial T-junctions.

defunvary-uncontracted-surface-mesh-bevel-widths-from-stock-masks-diagnostic
witnessstock-maskssite-widths

Return the dense-policy variable-width study surface before repair.

defunvary-surface-mesh-cohort-bevel-widths-from-stock-masks
owner-witnessesstock-maskssite-widths&key
output-ownersniloutput-owners-p
realize-context-owners

Evaluate an owner-keyed width-one cohort from one shared stock-mask policy.

owner-witnesses is a nonempty alist of stable owner keys to width-one surface meshes in one world domain. The incident stock masks of every witness are compiled into one canonical site field; collapse discovery and T-junction repair likewise see the entire cohort. Each surviving source triangle and every repair child is emitted to the source triangle's original owner.

When output-owners is omitted, every witness owner is returned. When supplied, it is a nonempty subset of the witness keys. Every witness contributes to the shared site policy and repair plan. realize-context-owners may additionally select nonpublished owners whose transformed surface is needed by a cold query, such as an attachment frame whose canonical primitive belongs to a neighboring chunk. Context realization never expands the output publication set.

The first value is a fresh alist, in owner-witnesses order, containing only the selected owners. The second value is the shared five-entry site-width census. The third is the transition diagnostic plist; its residual count covers only collapse/repair neighborhoods relevant to the selected output interior. The fourth value is a fresh alist of realized context owners, also in witness order and excluding every selected output owner.

check-typeowner-witnesseslist
check-typestock-masksvector
check-typesite-widthsvector
%vary-surface-mesh-bevel-widthsowner-witnesses
ifoutput-owners-poutput-owners
mapcar#'carowner-witnesses
realize-context-ownersnilstock-maskssite-widthst