Skip to content

Class ModelLibrary

Namespace: Apogee.Rendering
Assembly: Apogee.Rendering.dll

The models that entities draw ( is an id from here; scripts see this as models). A model is loaded once per path whatever the number of entities that show it, and reloaded in place when its file changes, so entities keep their id. Ids are never reused.

public sealed class ModelLibrary : EngineObject, IDisposable

Inheritance

object ← EngineObject ← ModelLibrary

Implements

IDisposable

Inherited Members

EngineObject.IsAdopted, EngineObject.Handle, EngineObject.IsDestroyed, EngineObject.Class, EngineObject.Adopt(), EngineObject.TryGet(SlotHandle, out EngineObject), EngineObject.Destroy(), object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks

Ids are handed out as soon as a path names a readable file, even before there is a GPU: a game's scripts run first and the renderer comes later (or never, in a headless run). The model is read and put on the GPU the first time something asks for it after ; a file that does not load is logged once and draws nothing until it is reloaded. Everything runs on the thread that renders.

Constructors

ModelLibrary(VirtualFileSystem, ContentLoader)

public ModelLibrary(VirtualFileSystem files, ContentLoader content)

Parameters

files VirtualFileSystem

Where models are read from.

content ContentLoader

Reads them (imported ones when there is an artifact).

Properties

Class

What the registry knows about this object's class.

public override ClassInfo Class { get; }

Property Value

ClassInfo

Count

How many models have an id.

public int Count { get; }

Property Value

int

IsAttached

True once models can be put on the GPU.

public bool IsAttached { get; }

Property Value

bool

Paths

The virtual paths of the models loaded by path.

public IReadOnlyCollection<string> Paths { get; }

Property Value

IReadOnlyCollection<string>

Methods

Add(ModelData)

Puts a model made in code on the GPU and returns its id. There has to be a renderer ().

public uint Add(ModelData model)

Parameters

model ModelData

Returns

uint

Attach(SceneRenderer, TextureCaps)

Lets models go on the GPU of renderer; caps are the compressed texture formats it samples.

public void Attach(SceneRenderer renderer, TextureCaps caps)

Parameters

renderer SceneRenderer

caps TextureCaps

BoundsOf(uint)

The box of the model in its own space, for picking and framing: from the model on the GPU when it is there, otherwise measured from the file once (the file is read, but nothing is put on the GPU). Null for an id the library does not know or a file that does not load.

public (Vector3 Min, Vector3 Max)? BoundsOf(uint id)

Parameters

id uint

Returns

(Vector3 Min, Vector3 Max)?

Detach()

Frees the GPU side (before the device goes away). The ids stay, and the models come back on the next .

public void Detach()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Find(uint)

The model with that id on the GPU, or null: there is none (0, or one that was removed), there is no renderer, or its file does not load.

public GpuModel? Find(uint id)

Parameters

id uint

Returns

GpuModel?

IdOf(string)

The id of the model loaded from path, or 0.

public uint IdOf(string path)

Parameters

path string

Returns

uint

Load(string)

The id of the model at path, which is the same for every call with that path. path may also be the uid://… of a model, which is the file that has it. The file has to exist (or, in a game that shipped only its imported artifacts, be an imported one); whether it is a model shows when it is first drawn.

public uint Load(string path)

Parameters

path string

Returns

uint

OnDestroyed()

protected override void OnDestroyed()

PathOf(uint)

The path the model id was loaded from, or null for an id the library does not know: what a scene saves instead of the number.

public string? PathOf(uint id)

Parameters

id uint

Returns

string?

Reload(string)

Reads the model at path again, if it has an id, and swaps it in under the same id. The old one is freed once the new one is ready; when the file no longer loads the exception propagates and the old model stays. Returns false when the path has no id.

public bool Reload(string path)

Parameters

path string

Returns

bool

Remove(uint)

Frees a model; entities that still name its id draw nothing. Returns false when there was none.

public bool Remove(uint id)

Parameters

id uint

Returns

bool