Class ModelLibrary¶
Namespace: Apogee.Rendering
Assembly: Apogee.Rendering.dll
The models that entities draw (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¶
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
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¶
Count¶
How many models have an id.
public int Count { get; }
Property Value¶
IsAttached¶
True once models can be put on the GPU.
public bool IsAttached { get; }
Property Value¶
Paths¶
The virtual paths of the models loaded by path.
public IReadOnlyCollection<string> Paths { get; }
Property Value¶
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¶
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¶
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¶
IdOf(string)¶
The id of the model loaded from path, or 0.
public uint IdOf(string path)
Parameters¶
path string
Returns¶
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¶
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¶
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¶
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