Game.Prefabs.MeshNode
Assembly: Game (assembly containing the game's prefab code, e.g., Assembly-CSharp)
Namespace: Game.Prefabs
Type: struct
Base: Unity.Entities.IBufferElementData
Summary:
MeshNode is a buffer element used by the game's prefab system to represent a spatial node for mesh data (for example in a spatial partition like a quadtree/octree used by prefab meshes). It stores a bounding volume, an index range into mesh/index data, and references to child subnodes. The struct is marked with InternalBufferCapacity(0), meaning no inline elements are reserved on the entity; buffers of this element type are always stored out-of-line.
Fields
-
public Bounds3 m_Bounds
Represents the axis-aligned bounding volume of this mesh node. Bounds3 comes from Colossal.Mathematics and is used for spatial tests (frustum culling, overlap checks, etc.). -
public int2 m_IndexRange
A 2-component integer vector (from Unity.Mathematics) that encodes an index range. Typically this holds (startIndex, count) or (start, end) into a shared index/mesh array for the geometry associated with this node. Exact semantics depend on the surrounding system but expect start + length or start/end style usage. -
public int4 m_SubNodes1
public int4 m_SubNodes2
Two int4 fields used to reference child subnodes. Together they allow up to 8 child indices (int4 + int4), which fits octree-style subdivision; for quadtree usage only some components may be used. Child indices are usually indices into a contiguous array of MeshNode entries (or -1/null sentinel when a child is absent). The ordering and meaning of each component (x/y/z/w) follows the consumer code in the prefab system.
Properties
- None declared on this struct. It is a plain data-only buffer element.
Constructors
- No explicit constructors are declared. As a value type (struct), MeshNode can be default-initialized; all fields will be zeroed unless set explicitly.
Methods
- None declared on this struct. It only contains raw data fields used by systems operating on buffers of MeshNode.
Usage Example
using Unity.Entities;
using Unity.Mathematics;
using Colossal.Mathematics;
using Game.Prefabs;
// Example: create an entity and add a MeshNode buffer with a single root node.
public void CreateMeshNodeBuffer(EntityManager em)
{
var archetype = em.CreateArchetype(typeof(MeshNode)); // or other components as needed
var entity = em.CreateEntity(archetype);
// Add a dynamic buffer for MeshNode
var buffer = em.AddBuffer<MeshNode>(entity);
// Prepare a root node
MeshNode root = new MeshNode();
root.m_Bounds = new Bounds3(new float3(-10f, -10f, -10f), new float3(10f, 10f, 10f));
root.m_IndexRange = new int2(0, 36); // example: start 0, count 36
// No children -> use -1 as sentinel for absent children
root.m_SubNodes1 = new int4(-1, -1, -1, -1);
root.m_SubNodes2 = new int4(-1, -1, -1, -1);
buffer.Add(root);
}
Notes / Tips: - Inspect consuming systems to confirm whether m_IndexRange uses (start,count) or (start,end) semantics. - Child index sentinel values (e.g., -1) and the target array that child indices reference are implementation details of the prefab/mesh container code. - Because InternalBufferCapacity is 0, the runtime will allocate a separate buffer storage for MeshNode elements on the entity; expect a small allocation on first use.