Skip to content

Game.Rendering.AreaTriangleData

Assembly:
Assembly-CSharp.dll (typical for Cities: Skylines 2 mods; the source file does not declare an assembly explicitly)
Namespace:
Game.Rendering

Type:
public struct AreaTriangleData

Base:
System.ValueType

Summary:
Represents a single triangle used by the game's rendering systems for area/mesh rendering. Contains world-space vertex positions, adjacency information in XZ (previous/next) for each vertex, a Y min/max range for the triangle, an offset direction (packed into a float4), and a level-of-detail distance factor. This struct is well suited for packing into GPU buffers or NativeArrays for high-performance rendering/compute work.


Fields

  • public float3 m_APos
    World-space position of vertex A. Use Unity.Mathematics.float3 (x, y, z).

  • public float3 m_BPos
    World-space position of vertex B.

  • public float3 m_CPos
    World-space position of vertex C.

  • public float2 m_APrevXZ
    XZ coordinates of the previous vertex adjacent to A (used for adjacency/smoothing, silhouette, or tangent direction calculations). Stored in a float2: (x, z).

  • public float2 m_BPrevXZ
    XZ coordinates of the previous vertex adjacent to B.

  • public float2 m_CPrevXZ
    XZ coordinates of the previous vertex adjacent to C.

  • public float2 m_ANextXZ
    XZ coordinates of the next vertex adjacent to A.

  • public float2 m_BNextXZ
    XZ coordinates of the next vertex adjacent to B.

  • public float2 m_CNextXZ
    XZ coordinates of the next vertex adjacent to C.

  • public float2 m_YMinMax
    Minimum and maximum Y values across the triangle (yMin, yMax). Useful for coarse culling, z-bias, or elevation-related calculations.

  • public float4 m_OffsetDir
    Packed offset direction and/or additional per-triangle parameters. Commonly used to store a 3D offset vector in xyz and a scalar in w (for example, offset magnitude or a sign flag). Exact usage may vary by renderer/shader.

  • public float m_LodDistanceFactor
    A scalar used to modulate level-of-detail behavior for this triangle (e.g., biasing LOD selection based on triangle importance or distance).

Properties

  • None (this is a plain data struct with public fields only).

Constructors

  • public AreaTriangleData()
    Implicit parameterless constructor provided by C#. Fields will be initialized to their default values (zeros). For predictable values, explicitly assign fields after construction.

Methods

  • None (no instance methods defined in the source). This is a POD (plain-old-data) struct intended for packing and passing to GPU/compute.

Notes for Modders and Usage Tips

  • Layout & interop:
  • The struct uses Unity.Mathematics types (float2/float3/float4), which are blittable and suitable for NativeArray, ComputeBuffer/GraphicsBuffer, and direct GPU interop when LayoutKind.Sequential is used.
  • When sending instances to GPU shaders, ensure the shader-side structure matches the field order and packing (HLSL float2/float3/float4) to avoid misalignment.
  • float3 is 12 bytes; depending on target and marshalling, padding might be inserted to align subsequent fields. Confirm size with System.Runtime.InteropServices.Marshal.SizeOf() if necessary.

  • Typical uses:

  • Building area-mesh geometry for procedural rendering (roads, parks, decals).
  • Providing adjacency (prev/next XZ) for correct smoothing, bevels, or mesh expansion in the shader.
  • culling/heurstics using m_YMinMax and m_LodDistanceFactor.
  • Packing offset directions and extra flags in m_OffsetDir.w to reduce number of GPU attributes.

  • Performance:

  • Prefer NativeArray or GraphicsBuffer/ComputeBuffer for large batches.
  • Fill data on worker threads where possible, then upload in bulk to avoid per-triangle GC allocations or driver overhead.

  • Interpreting adjacency fields:

  • m_PrevXZ and m_NextXZ contain only XZ; Y is omitted because adjacency generally matters in plan view (XZ) for smooth edges and thickness expansion# Game.Rendering.AreaTriangleData

Assembly:
Assembly-CSharp.dll (typical for Cities: Skylines 2 mods; the source file does not declare an assembly explicitly)
Namespace:
Game.Rendering

Type:
public struct AreaTriangleData

Base:
System.ValueType

Summary:
Represents a single triangle used by the game's rendering systems for area/mesh rendering. Contains world-space vertex positions, adjacency information in XZ (previous/next) for each vertex, a Y min/max range for the triangle, an offset direction (packed into a float4), and a level-of-detail distance factor. This struct is intended for high-performance use (NativeArray/GraphicsBuffer/ComputeBuffer) and shader interop.


Fields

  • public float3 m_APos
    World-space position of vertex A. Use Unity.Mathematics.float3 (x, y, z).

  • public float3 m_BPos
    World-space position of vertex B.

  • public float3 m_CPos
    World-space position of vertex C.

  • public float2 m_APrevXZ
    XZ coordinates of the previous vertex adjacent to A (used for adjacency/smoothing, silhouette, or tangent direction calculations). Stored as (x, z).

  • public float2 m_BPrevXZ
    XZ coordinates of the previous vertex adjacent to B.

  • public float2 m_CPrevXZ
    XZ coordinates of the previous vertex adjacent to C.

  • public float2 m_ANextXZ
    XZ coordinates of the next vertex adjacent to A.

  • public float2 m_BNextXZ
    XZ coordinates of the next vertex adjacent to B.

  • public float2 m_CNextXZ
    XZ coordinates of the next vertex adjacent to C.

  • public float2 m_YMinMax
    Minimum and maximum Y values across the triangle (yMin, yMax). Useful for coarse culling, depth bounds, or height-based calculations.

  • public float4 m_OffsetDir
    Packed offset direction and/or additional per-triangle parameters. Typically the xyz components store an offset direction vector and the w component holds a scalar (for example an offset magnitude or a flag). The exact packing is renderer-specific.

  • public float m_LodDistanceFactor
    A scalar used to modulate level-of-detail behavior for this triangle (e.g., biasing LOD selection based on triangle importance or distance).

Properties

  • None (this is a plain data struct with public fields only).

Constructors

  • public AreaTriangleData()
    Implicit parameterless constructor provided by C#. All fields default to zero. For predictable values, explicitly assign fields after construction.

Methods

  • None (no instance methods defined in the source). This is a POD (plain-old-data) struct intended for packing and passing to GPU/compute.

Usage Example

using Unity.Mathematics;
using System.Runtime.InteropServices;

// Create and populate one triangle
AreaTriangleData tri = new AreaTriangleData();
tri.m_APos = new float3(0f, 0f, 0f);
tri.m_BPos = new float3(1f, 0f, 0f);
tri.m_CPos = new float3(0f, 0f, 1f);

// adjacency in XZ (previous/next points for each vertex)
tri.m_APrevXZ = new float2(-1f, 0f);
tri.m_ANextXZ = new float2(0.5f, 1f);
// ... set other prev/next fields ...

// compute min/max Y for the triangle
float yMin = math.min(tri.m_APos.y, math.min(tri.m_BPos.y, tri.m_CPos.y));
float yMax = math.max(tri.m_APos.y, math.max(tri.m_BPos.y, tri.m_CPos.y));
tri.m_YMinMax = new float2(yMin, yMax);

// compute a face-normal-based offset direction (example)
float3 normal = math.normalize(math.cross(tri.m_BPos - tri.m_APos, tri.m_CPos - tri.m_APos));
tri.m_OffsetDir = new float4(normal, 1.0f); // store normal.xyz and a scalar in w

tri.m_LodDistanceFactor = 1.0f;

// Example: place many AreaTriangleData into a NativeArray or GraphicsBuffer for GPU use.
// Note: ensure shader-side struct matches this exact field order and packing.

{{ Additional notes }} - When sending this struct to the GPU, verify HLSL struct layout matches the managed layout (float3 vs float4 packing). Adding explicit StructLayout(LayoutKind.Sequential) can help ensure predictable layout. - Use NativeArray or GraphicsBuffer for large batches to avoid per-object overhead. - Many of the adjacency and offset fields are renderer-specific; inspect related shaders or rendering code in the game to understand exact semantics (e.g., what is expected in m_OffsetDir.w).