Per-line instance table for the batched LineBatch3D renderer. More...
| Import Statement: | import Clayground.Canvas3D |
LineBatchInstancing turns a set of styled polylines into a single GPU instance table, one instance per line segment, over the unit-quad base mesh provided by LineBatchGeometry. Each 80-byte instance entry encodes an affine transform that maps the base quad's unit-x axis onto the segment (no quaternions, 12 floats per segment), plus the per-line color and a customData vector carrying width and a reserved styleId.
The vertex shader reconstructs the segment endpoints as P0 = INSTANCE_MODEL_MATRIX * vec4(0,0,0,1) and P1 = INSTANCE_MODEL_MATRIX * vec4(1,0,0,1) and expands the quad into a camera-facing ribbon.
This type is used internally by LineBatch3D.
See also LineBatch3D and LineBatchGeometry.
count : int |
The number of lines (polylines) currently in the batch.
lines : list |
Declarative list of styled polylines.
Each element is an object of the form { points: [Qt.vector3d, ...], color: <color>, width: <real>, styleId: <int> }. A polyline with N points produces N-1 line-segment instances that share the line's color, width and styleId.
real pathLength(int lineIndex) |
Returns the total length of line lineIndex in world units.
Returns 0 for an out-of-range index or a line with fewer than two points. This is the same accumulated distance the shader uses to run patterns continuously along the polyline.
vector3d positionAt(int lineIndex, real distance) |
Returns the point distance world units along line lineIndex.
The distance is clamped to the line's extent, so 0 yields the first point and any distance past the total length yields the last point. Out-of-range indices and empty lines return the zero vector.
void setBulk(ByteArray positions, ByteArray startIndices, ByteArray colors, ByteArray widths, ByteArray styleIds) |
Fast path for building the batch from packed binary buffers.
[startIndices[i], startIndices[i+1]).void updateEndpointsBulk(ByteArray positions) |
Rewrites the endpoints of every single-segment line in one pass.
positions is a packed float32 buffer with 6 floats per line (p0.xyz, p1.xyz) in line order. This is the fast per-frame path used by ConnectorLayer3D: it patches only the affected instance entries in place, recomputes the batch bounds once and triggers a single instance-table upload. Lines that do not have exactly one segment are skipped.
void updateLinePoints(int lineIndex, list points) |
Patches only the given line's instance-table region and re-uploads.
Rewrites line lineIndex from points. When the new point count keeps the same number of segments, only that line's entries are rewritten in place (no rebuild of other lines). If the segment count changes, the whole table is rebuilt.
void updatePolylinesBulk(ByteArray positions, int pointsPerLine) |
Rewrites the points of every uniform-topology line in one pass.
positions is a packed float32 buffer with pointsPerLine * 3 floats per line (p0.xyz, p1.xyz, ...) in line order. This is the fast per-frame path used by ConnectorLayer3D for curved connectors: it rewrites each matching line's points, recomputes its instance entries (including the per-segment accumulated path distance, so dot/chevron patterns run continuously along the new curve), recomputes the batch bounds once and triggers a single instance-table upload. A line is patched only when its topology matches the buffer (instanceCount == pointsPerLine - 1 and points.size() == pointsPerLine); other lines are skipped.