Stream Linkage

Stream Linkages are used to tie multiple Streams together so that operations that affect the size of one stream affect them all together. This is useful to keep secondary vertex data streams the same size, and allow you to set data only as desired.


Creating a Stream Linkage
// Create our position stream
auto PositionStream = FRealtimeMeshStream::Create<FVector3f>(FRealtimeMeshStreams::Position);

// Create our tangents stream
auto TangentsStream = FRealtimeMeshStream::Create<FRealtimeMeshTangentsNormalPrecision>(FRealtimeMeshStreams::Tangents);

// Create our linkage that we'll use to bind the vertex streams together
FRealtimeMeshStreamLinkage VerticesLinkage;

// Bind the position stream, with a deafult value of zero vector.
// We can do this simply because we know the type
VerticesLinkage.BindStream(PositionStream, FRealtimeMeshStreamDefaultRowValue::Create(FVector3f::ZeroVector));

// Bind the tangents stream, we create the default value by passing it our wanted value, and getting the final layout from the stream.
// This lets it do the conversion once and then just blit this value into the stream.
VerticesLinkage.BindStream(TangentsStream, FRealtimeMeshStreamDefaultRowValue::Create(
    FRealtimeMeshTangentsNormalPrecision(FVector3f::ZAxisVector, FVector3f::XAxisVector),
    TangentsStream.GetLayout()));

// We can setup the two builders to make working with the streams easier    
TRealtimeMeshStreamBuilder<FVector3f> PositionStreamBuilder(PositionStream);
TRealtimeMeshStreamBuilder<FRealtimeMeshTangentsHighPrecision, FRealtimeMeshTangentsNormalPrecision> TangentsStreamBuilder(TangentsStream);

// This will add the position to the position stream. It will also set the tangents stream size to the same size and default the value
// You should *NOT* use .Add on the secondary streams when setting the value, you can just used the indexed set. 
// It doesn't matter which stream you call .Add() on, it will resize them all.
int32 Index = PositionStreamBuilder.Add(FVector3f(1, 0, 0));

// Here we just set the tangent entry for this index
// If you call .Add() again then you'll end up with 2 vertices in both streams, instead of 1 vertex with the tangent set for the existing vertex
TangentsStreamBuilder[Index] = FRealtimeMeshTangentsHighPrecision(FVector3f(0, 1, 0), FVector3f(0, 0, 1));