LineSegmentsGeometry constructor
LineSegmentsGeometry(
- LineSegmentData segments, {
- double width = 0.01,
- double normalOffset = 0.0,
Creates a segment batch from segments.
width is the ribbon's world-space width. normalOffset displaces
endpoints along the source normals (ignored when the segment data
carries none).
Implementation
LineSegmentsGeometry(
LineSegmentData segments, {
double width = 0.01,
double normalOffset = 0.0,
}) : _width = width {
setVertexShader(baseShaderLibrary['LineSegmentsVertex']!);
final quad = _sharedQuad();
setVertices(quad.vertices, _kQuadVertexCount);
setIndices(quad.indices, gpu.IndexType.int16);
final positions = segments.positions;
final normals = segments.normals;
_segmentCount = segments.segmentCount;
final endpoints = Float32List(positions.length);
for (var i = 0; i < positions.length; i++) {
endpoints[i] = normalOffset != 0.0 && normals != null
? positions[i] + normals[i] * normalOffset
: positions[i];
}
_endpoints = endpoints;
if (_segmentCount > 0) {
final bytes = ByteData.sublistView(endpoints);
final buffer = gpu.gpuContext.createDeviceBuffer(
gpu.StorageMode.hostVisible,
bytes.lengthInBytes,
);
buffer.overwrite(bytes);
_instances = gpu.BufferView(
buffer,
offsetInBytes: 0,
lengthInBytes: bytes.lengthInBytes,
);
}
_recomputeBounds();
}