Game.Rendering.BatchDataHelpers
Assembly:
Game
Namespace:
Game.Rendering
Type:
public static class BatchDataHelpers
Base:
System.Object (static helper class)
Summary:
BatchDataHelpers is a collection of static utility functions used by the renderer to compute per-instance parameters, transform/curve matrices and sub-mesh flags for a variety of in-game objects (buildings, trees, nets/roads, stacks, decals, curves, etc.). It provides helpers to build composition and transform matrices, compute tile counts and tiling parameters, extract animation/bone/light buffers indices and produce compact float/float4 parameter values that shaders or GPU batching code consume. These utilities are heavily used when composing batched meshes for edges, nodes, curves and other scene elements.
Fields
-
public struct CompositionParameters
CompositionParameters is a value-type container used to pass precomputed transform and mapping info to the renderer. Its fields: -
public float3x4 m_TransformMatrix
World-space transform/translation used to position a composed object (stored compactly as a 3x4). -
public float4x4 m_CompositionMatrix0
...m_CompositionMatrix7
Up to eight float4x4 matrices containing curve/control point positions and per-vertex mapping offsets for different composition regions (edge sides, middle, curves). These are used to map prefab geometry onto curves/edges/nodes. -
public float4 m_CompositionSync0
...m_CompositionSync3
Sync/mapping offset vectors (packed floats) used to coordinate UV or vertex mapping across composition matrices.
Properties
- (none)
This static helper class exposes only methods and the nested CompositionParameters struct; it has no properties.
Constructors
- (none)
BatchDataHelpers is a static class and has no instance constructors.
Methods
-
public static float4 GetBuildingState(PseudoRandomSeed pseudoRandomSeed, CitizenPresence citizenPresence, float lightFactor, bool abandoned, bool electricity)
Returns a packed float4 representing randomized building visual state: random seed, light intensity (affected by citizen presence and electricity), a damage/decay factor when abandoned or without electricity, and a spare component. Used to vary building instance visuals. -
public static float4 GetBuildingState(PseudoRandomSeed pseudoRandomSeed, int passengersCount, int passengerCapacity, float lightFactor, bool destroyed)
Overload that computes a building state based on vehicle passenger fullness instead of citizenPresence. -
public static float3 GetAnimationCoordinate(Game.Prefabs.AnimationClip clip, float time, float previousTime)
Converts animation times into texture coordinate parameters for sampling animation atlases (handles once vs looping playback, texture offsets, ranges and width). -
public static float2 GetBoneParameters(Skeleton skeleton)
Returns packed float2 with bone buffer begin/end indices (as floats) for the supplied skeleton. -
public static float2 GetBoneParameters(Animated animated)
Same as above but for an Animated instance (reads m_BoneAllocation). -
public static float2 GetLightParameters(Emissive emissive)
Returns packed float2 with emissive/light buffer begin/end indices (as floats) for the given Emissive. -
public static float4 GetWetness(Surface surface)
Packs surface wetness/snow/accumulated wetness/snow into a normalized float4 (multiplied by 1/255). -
public static float4 GetDamage(Surface surface, Damaged damaged, OnFire onFire)
Produces a float4 containing a combined dirty/damage factor, the two damage channels and normalized fire intensity used by shaders to drive damage visuals. -
public static SubMeshFlags CalculateTreeSubMeshData(Tree tree, GrowthScaleData growthScaleData, out float3 scale)
Determines which tree sub-mesh (child/teen/adult/elderly/dead/stump) to use and computes per-instance scale based on the tree's growth and growthScaleData. Returns SubMeshFlags indicating the required sub-mesh and outputs a scale vector. -
public static SubMeshFlags CalculateNetObjectSubMeshData(Game.Objects.NetObject netObject)
Calculates sub-mesh flags for a NetObject based on its flags (e.g. track pass-through, backward) and returns a SubMeshFlags bitmask used during composition. -
public static SubMeshFlags CalculateQuantitySubMeshData(Quantity quantity, QuantityObjectData quantityObjectData, bool editorMode)
Chooses the correct quantity sub-mesh (empty / partial / full variants) based on fullness, step mask and whether the editor mode is active. -
public static SubMeshFlags CalculateStackSubMeshData(Stack stack, StackData stackData, out int3 tileCounts, out float3 offsets, out float3 scale)
Calculates how a stacked object (like pallets/tiles) should be split into start/middle/end tiles, tile counts, offsets and scales. Returns sub-mesh flags marking start/middle/end presence and outputs tileCounts, offsets, and scale. -
public static void AlignStack(ref Stack stack, StackData stackData, bool start, bool end)
Adjusts a Stack's range so it aligns within space constraints, optionally centering or anchoring at start/end depending on provided flags. -
public static void CalculateStackSubMeshData(StackData stackData, float3 offsets, float3 scales, int tileIndex, SubMeshFlags subMeshFlags, ref float3 subMeshPosition, ref float3 subMeshScale)
Given precomputed offsets & scales, computes and applies the translation and scale for a particular sub-mesh tile index of a stack (affects x/y/z depending on stack direction). -
public static void CalculateEdgeParameters(EdgeGeometry edgeGeometry, bool isRotated, out CompositionParameters compositionParameters)
Computes CompositionParameters for an edge (road/track) using edgeGeometry bounds, start/end segments and mapping offsets. Handles rotated mapping variants and populates composition matrices and sync offsets used to map prefab geometry onto the edge. -
public static void CalculateNodeParameters(EdgeNodeGeometry nodeGeometry, NetCompositionData prefabCompositionData, out CompositionParameters compositionParameters)
Computes composition matrices for a node (intersection or connection) including optional middle radius handling. Uses prefab composition data for width/sync offsets and constructs matrices for left/right/middle areas and curve mapping. -
public static void CalculateOrphanParameters(Node node, NodeGeometry nodeGeometry, NetCompositionData prefabCompositionData, bool isPrimary, out CompositionParameters compositionParameters)
Builds parameters for orphaned node geometries (nodes without a matched segment) by synthesizing a segment/curve for left/right and preparing composition matrices and mapping offsets. 'isPrimary' selects orientation for the constructed segment. -
private static void CalculateMappingOffsets(Segment segment, out float4 leftOffsets, out float4 rightOffsets, float2 leftMappingOffset, float2 rightMappingOffset)
Internal helper to compute four mapping offsets for left and right spline parts of a segment based on segment lengths and provided mapping offset ranges. -
private static float4x4 BuildEdgeMatrix(Bezier4x3 curve, float3 offset, float4 mappingOffsets)
Packs a Bezier curve's four control points (a,b,c,d) offset by a reference point plus mapping offsets into a float4x4 where each column is a control point + mapping offset in the w channel. Used to quickly pass curve geometry to GPU. -
private static Bezier4x3 BuildCurve(float3 startPos, float3 direction, float length)
Constructs a cubic Bezier (4 control points) from a start position, directional vector (normalized) and length by stepping the direction at 1/3 and 2/3 intervals. -
public static float4x4 BuildTransformMatrix(Curve curve, float4 size, float4 curveScale, float smoothingDistance, bool isDecal, bool isLoaded)
Builds a transform matrix used to place/scale decal-like or curve-wrapped geometry. For decals it computes an oriented TRS that tightly bounds the curve span considering smoothing; for loaded/placeholder or non-decal cases it produces simpler translations/scales. This method handles edge cases where the curve is nearly degenerate. -
public static float4x4 BuildCurveMatrix(Curve curve, float3x4 transformMatrix, float4 size, int tilingCount)
Produces a float4x4 that encodes the curve's control points relative to a transform translation (transformMatrix.c3) and computes UV mapping offsets to support tiling. Used when composing curve geometry into GPU instances. -
public static float4 BuildCurveParams(float4 size, NodeLane nodeLane)
Encodes per-lane curve parameters (length, sharing start/end info) into a float4 used by shaders or composition. -
public static float4 BuildCurveParams(float4 size, EdgeLane edgeLane)
Encodes per-edge-lane curve parameters (length, connectivity flags) into a float4. -
public static float4 BuildCurveParams(float4 size, Game.Net.Elevation elevation)
Encodes curve parameters that include elevation information and a flag if elevation is invalid. -
public static float4 BuildCurveParams(float4 size)
Simple curve params that include the curve length (size.z) and default flags. -
public static float4 BuildCurveScale(NodeLane nodeLane, NetLaneData netLaneData)
Computes scale factors for a lane on a node based on width offsets and net lane base width; returns a float4 with replicated components for convenience. -
public static float4 BuildCurveScale()
Returns uniform scale (1f) as a float4 (used as a default). -
public static int GetTileCount(Curve curve, float length, int tilingCount, bool geometryTiling, out int clipCount)
Computes how many tiles/clips are required to cover a curve. If tilingCount != 0 it calculates clipCount and uses tilingCount to determine rows; otherwise geometryTiling controls whether to use curve length / length to decide tile count. Outputs clipCount (0 when not using per-clip tiling). Clamps result to [1,256] and handles rounding per tiling mode.
Usage Example
// Example: compute composition parameters for an edge and use them to create instance data
EdgeGeometry edgeGeom = /* obtained from net geometry builder */;
bool isRotated = false;
BatchDataHelpers.CompositionParameters compParams;
BatchDataHelpers.CalculateEdgeParameters(edgeGeom, isRotated, out compParams);
// compParams now contains m_TransformMatrix, composition matrices (m_CompositionMatrix0..7)
// and sync vectors (m_CompositionSync0..3) which can be uploaded to GPU instance buffers
// or used to feed a MaterialPropertyBlock for rendering.