Class TriangleMeshBlock
Vertex/Point3D
soup, which is what made the transform phase memory-latency-bound.
Interaction with the rest of the pipeline is unchanged: each visible
triangle is queued as a thin preallocated MeshTriangle handle
into the same RenderAggregator, sorted by the same comparator,
binned into the same tile grid, and painted by the same
TexturedTriangle.paintFlat(RenderingContext, Texture, boolean, Point2D, Point2D, Point2D, Point2D, Point2D, Point2D, double, double, double, double, double) core — bit-exact with the
object-backed path.
Subpixel-cull verdicts are cached per triangle (cullEpoch):
while the verdict epoch holds, a culled triangle costs one integer
compare per frame — no vertex math at all.
Global illumination: the GI system traces block triangles like any
other scene triangle and writes per-triangle light totals (ambient +
direct with shadows + indirect bounce) into giLight. The
paint path multiplies texture texels by that per-triangle light; while
no GI system has stamped the block the array is null and painting is
bit-identical to the unlit path. Render-side cost: one array read and
three multiplies per triangle — ray casting happens only on the
dedicated GI threads.
Limitations vs object-backed triangles: no mouse picking, no SDF
textures (rejected at build). Per-texel lightmaps exist only inside
the GI stage-3 radius bubble (see lightmapAt(int)); outside it GI
lands per triangle — the right granularity for far game meshes.
-
Field Summary
Fields inherited from class AbstractShape
cachedBoundingBox, mouseInteractionController -
Constructor Summary
ConstructorsConstructorDescriptionTriangleMeshBlock(double[] world, double[] uv, Texture[] textures, boolean backfaceCull) Builds a block from baked world-space triangle soup. -
Method Summary
Modifier and TypeMethodDescriptionalbedo(int tri) Average color of the triangle's texture (albedo for GI bounce rays), sampled from the primary bitmap on a coarse stride and cached per texture.attachLightmapIfAbsent(int tri, Lightmap lightmap) Attaches a lightmap to a triangle unless one is already attached.voidAllocates and publishes the per-triangle GI light array if absent (called by the GI system when this block enters a scene snapshot).Returns the axis-aligned bounding box for this shape in local coordinates.intgetTransformWeight(RenderingContext renderingContext) Estimated cost of transforming this shape, in arbitrary units where a leaf primitive counts 1.float[]giLight()The per-triangle GI light array (3 floats per triangle), or null when no GI system has stamped this block — the paint path then renders the plain texture.lightmapAt(int tri) The lightmap attached to a triangle, or null when the triangle is outside the stage-3 bubble (or GI has not reached it yet).voidsetGiLight(int tri, float r, float g, float b) Writes one triangle's GI light total (light units, may exceed 255 — the paint path clamps).texture(int tri) The triangle's base texture (also read by the GI system when it attaches a lightmap: the composite resamples this texture into lightmap space).voidtransform(TransformStack transforms, RenderAggregator aggregator, RenderingContext renderingContext) Transforms every triangle of the block with the composed top transform of the stack (hoisted out of the loop), culls (near plane, subpixel with verdict cache, viewport) and queues a thin handle per surviving triangle.voidtriangleUv(int tri, double[] out) Copies the triangle's 6 UV coordinates (primary-texture pixels).voidtriangleVertices(int tri, float[] out) Copies the triangle's 9 world-space vertex coordinates intoout(x0,y0,z0, x1,y1,z1, x2,y2,z2).voidtriangleWorld(int tri, double[] out) Copies the triangle's 9 world-space vertex coordinates at full double precision (GI lightmap construction and cache keys).inttriCount()Methods inherited from class AbstractShape
invalidateBounds, setMouseInteractionController
-
Constructor Details
-
TriangleMeshBlock
Builds a block from baked world-space triangle soup.- Parameters:
world- 9 doubles per triangle (x0,y0,z0,x1,...), world space; the array is adopted, not copieduv- 6 doubles per triangle (u0,v0,...) in primary texture pixels; adoptedtextures- one texture per trianglebackfaceCull- cull clockwise triangles on screen
-
-
Method Details
-
triCount
public int triCount() -
ensureGiLight
public void ensureGiLight()Allocates and publishes the per-triangle GI light array if absent (called by the GI system when this block enters a scene snapshot). Fresh arrays start at 255 per channel — the historical full-texture look — so enabling GI shows no dark age before the first estimates land. Idempotent and thread-safe. -
setGiLight
public void setGiLight(int tri, float r, float g, float b) Writes one triangle's GI light total (light units, may exceed 255 — the paint path clamps). Called from GI worker threads only, and only afterensureGiLight(). -
giLight
public float[] giLight()The per-triangle GI light array (3 floats per triangle), or null when no GI system has stamped this block — the paint path then renders the plain texture.- Returns:
- the light array or null
-
albedo
Average color of the triangle's texture (albedo for GI bounce rays), sampled from the primary bitmap on a coarse stride and cached per texture. Cost is paid once per distinct texture, not per triangle.- Parameters:
tri- triangle index- Returns:
- the average texture color
-
triangleVertices
public void triangleVertices(int tri, float[] out) Copies the triangle's 9 world-space vertex coordinates intoout(x0,y0,z0, x1,y1,z1, x2,y2,z2). Used by the GI system at snapshot build.- Parameters:
tri- triangle indexout- destination array of at least 9 floats
-
triangleWorld
public void triangleWorld(int tri, double[] out) Copies the triangle's 9 world-space vertex coordinates at full double precision (GI lightmap construction and cache keys).- Parameters:
tri- triangle indexout- destination array of at least 9 doubles
-
triangleUv
public void triangleUv(int tri, double[] out) Copies the triangle's 6 UV coordinates (primary-texture pixels). Used by the GI system when attaching a lightmap.- Parameters:
tri- triangle indexout- destination array of at least 6 doubles
-
lightmapAt
The lightmap attached to a triangle, or null when the triangle is outside the stage-3 bubble (or GI has not reached it yet).- Parameters:
tri- triangle index- Returns:
- the lightmap or null
-
attachLightmapIfAbsent
Attaches a lightmap to a triangle unless one is already attached. Called from GI threads; idempotent and thread-safe.- Parameters:
tri- triangle indexlightmap- the candidate lightmap- Returns:
- the lightmap actually attached to the slot (the argument, or the pre-existing one on a lost race)
-
getBoundingBox
Description copied from class:AbstractShapeReturns the axis-aligned bounding box for this shape in local coordinates.The bounding box is used for frustum culling to determine if the shape is potentially visible before expensive vertex transformations.
Conservative default: Returns a very large box that ensures the shape is always considered visible. Subclasses should override to provide tight bounds computed from their geometry.
Caching: The bounding box is cached after first computation. If geometry changes, call
AbstractShape.invalidateBounds()to trigger recomputation on next call.- Overrides:
getBoundingBoxin classAbstractShape- Returns:
- the axis-aligned bounding box in local coordinates
-
getTransformWeight
Description copied from class:AbstractShapeEstimated cost of transforming this shape, in arbitrary units where a leaf primitive counts 1. Composites override this with their total subtree weight. Used by the parallel transform fork to decide where splitting pays off.- Overrides:
getTransformWeightin classAbstractShape- Parameters:
renderingContext- the rendering context (frame identity for caching)- Returns:
- transform weight, always at least 1
-
transform
public void transform(TransformStack transforms, RenderAggregator aggregator, RenderingContext renderingContext) Transforms every triangle of the block with the composed top transform of the stack (hoisted out of the loop), culls (near plane, subpixel with verdict cache, viewport) and queues a thin handle per surviving triangle. All expressions replicateTransformStack.transform/Vertex.calculateLocationRelativeToViewerexactly, so output is bit-identical with the object-backed path.- Specified by:
transformin classAbstractShape- Parameters:
transforms- the current stack of transforms (world-to-camera transformations)aggregator- collects transformed shapes for depth-sorted renderingrenderingContext- provides frame dimensions, graphics context, and frame metadata
-
texture
The triangle's base texture (also read by the GI system when it attaches a lightmap: the composite resamples this texture into lightmap space).
-