InstancedMesh

csharp
public sealed class InstancedMesh : Object

Namespace NodeWorld.Flux.

Copies of a mesh drawn by the client every frame, without GameObjects (grass, crowds, debris): a matrix per copy in the memory of the world, and optional per-copy material properties (the material's shader must read them as instanced properties, and the material must have GPU instancing on). Drawn in packets, read straight from the memory of the world. The copies have no collision: to touch something, use ordinary objects. The script changes the arrays from any thread. Client only. Dispose (or Object.Destroy) stops it; it stops with its world.

Properties

matrices

csharp
public Matrix4x4[] matrices { get; }

Where each copy is drawn (localToWorld of each copy: Matrix4x4.TRS(position, rotation, scale)).

count

csharp
public int count { get; set; }

How many copies are drawn: the first count of matrices (at most their length).

visible

csharp
public bool visible { get; set; }

The copies are drawn (true) or not.

shadowCastingMode

csharp
public ShadowCastingMode shadowCastingMode { get; set; }

How the copies cast shadows.

receiveShadows

csharp
public bool receiveShadows { get; set; }

The copies receive shadows.

layer

csharp
public int layer { get; set; }

The layer the copies are drawn in (cameras see the layers of their culling mask).

mesh

csharp
public Mesh mesh { get; set; }

The mesh drawn (its first submesh; SetMesh for another).

material

csharp
public Material material { get; set; }

The material of the copies (GPU instancing on).

Methods

Create

csharp
public static InstancedMesh Create(Mesh mesh, Material material, int capacity, int submesh = 0)

capacity copies of the submesh of mesh drawn with material, all at the origin until the script places them.

SetMesh

csharp
public void SetMesh(Mesh mesh, int submesh)

The mesh drawn and its submesh.

AddColorProperty

csharp
public Color[] AddColorProperty(string property)

A color per copy for this property of the material's shader (an instanced property).

AddFloatProperty

csharp
public float[] AddFloatProperty(string property)

A float per copy for this property of the material's shader.

AddVectorProperty

csharp
public Vector4[] AddVectorProperty(string property)

A vector per copy for this property of the material's shader.

Dispose

csharp
public void Dispose()

The copies are no longer drawn.