batchedText

@three-blocks/coreWebGPU
batchedText(batchedText : BatchedText, uBillboard : UniformNode) : Fn<vec3>

Creates a TSL Fn that computes BatchedText vertex transforms.

This function:

  1. Reads per-member parameters from storage buffers
  2. Uses shared textGlyphTransform for glyph geometry (code reuse with TextNode)
  3. Applies per-member matrix transformation
  4. Handles billboarding and curvature

This node should be used in material.setupVertex to handle batched text geometry transformation.

Parameters
The BatchedText instance
uBillboardUniformNode
Billboard uniform node
Returns
Fn<vec3> — A callable TSL function that returns the transformed position
Example
import { BatchedText, Text, batchedText } from '@three-blocks/core';
import {
  subBuild,
  positionLocal,
  cameraProjectionMatrix,
  modelViewMatrix,
  vec4,
  uniform
} from 'three/tsl';

const batched = new BatchedText(2, 2 * 10);

const text1 = new Text();
text1.text = 'First';
text1.position.set(0, 1, 0);
text1.updateMatrixWorld();

const text2 = new Text();
text2.text = 'Second';
text2.position.set(0, -1, 0);
text2.updateMatrixWorld();

const id1 = batched.addText(text1);
const id2 = batched.addText(text2);

const material = batched.material;
const uBillboard = uniform(0);

material.setupVertex = () => {
  // Build text geometry transformation first (sets up varyings and modifies positionLocal)
  const textPosition = subBuild(batchedText(batched, uBillboard)(), 'POSITION', 'vec3');

  // Start with text position
  let finalPosition = textPosition;

  // If user has positionNode, assign textPosition to positionLocal first
  // so their positionNode can read it, then apply their transformation
  if (material.positionNode !== null) {
    positionLocal.assign(textPosition);
    finalPosition = subBuild(material.positionNode, 'POSITION', 'vec3');
  }

  // Assign final position to positionLocal for any other code that might need it
  positionLocal.assign(finalPosition);

  // Build custom MVP using our computed position
  const mvp = cameraProjectionMatrix
    .mul(modelViewMatrix)
    .mul(vec4(finalPosition, 1.0));

  return mvp;
};