ModelBatch¶
Namespace Nfty.Model in assembly Nfty.Model.
Rises many pictures at once and delivers the files to a folder or a zip.
Methods¶
Build(IEnumerable<ModelInput>, RiseOptions)¶
Rises every input that can rise.
Parameters
inputs(IEnumerable<ModelInput>) - The pictures. Enumerated once, each finished before the next is asked for — a lazy sequence may free an input when the next is requested.options(RiseOptions) - How to rise and write.
Returns. The files, and a line for each picture skipped.
Export(IReadOnlyList<string>, Func<int, ModelInput>, Action<ModelInput>?, RiseOptions, ModelDestination, IProgress<int>?, CancellationToken, Action<string>?)¶
public static ModelExportResult Export(IReadOnlyList<string> baseNames, Func<int, ModelInput> open, Action<ModelInput>? release, RiseOptions options, ModelDestination destination, IProgress<int>? progress = null, CancellationToken cancellation = default, Action<string>? onWritten = null);
Rises a batch and writes it as it goes: each model is built, written and let go before the next picture is asked for, so a batch of ten thousand holds one model, never ten thousand.
Parameters
baseNames(IReadOnlyList<string>) - One wanted name per picture; made safe and distinct exactly asModelBatch.Build()does, in this order.open(Func<int, ModelInput>) - Hands over picturei. Called once per index, on the calling thread, never before the previous picture has been released. ItsModelInput.BaseNameis ignored: the name isbaseNames's.release(Action<ModelInput>?) - Called once for every opened picture as soon as its files are written (or its build failed); null when the caller keeps ownership.options(RiseOptions) - How to rise and write.destination(ModelDestination) - A folder or a zip.progress(IProgress<int>?) - Told how many pictures are done (written or skipped) after each one.cancellation(CancellationToken) - Checked before each picture. A canceled zip is never left behind (it is written beside its destination and moved over it only when complete); a canceled folder keeps the models finished before the stop, each whole, since a file is written only once its model is.onWritten(Action<string>?) - Told each file's name once it is in the destination, on the thread doing the export; how a caller knows whether a stopped batch wrote anything.
Returns. The file names written, the pictures skipped, and the files that already existed.
Remarks
Models are written in ordinal order of their first file name, each model's files in the writer's order: for a one-file format that is exactly ordinal order of every entry, so a zip has the bytes ModelBatch.WriteZip() would give the built files. Identical input gives identical bytes either way.
Export(IReadOnlyList<string>, Func<int, ModelInput>, Action<ModelInput>?, RiseOptions, ModelDestination, Parallelism, IProgress<int>?, CancellationToken, Action<string>?)¶
public static ModelExportResult Export(IReadOnlyList<string> baseNames, Func<int, ModelInput> open, Action<ModelInput>? release, RiseOptions options, ModelDestination destination, Parallelism parallelism, IProgress<int>? progress = null, CancellationToken cancellation = default, Action<string>? onWritten = null);
Rises a batch like ModelBatch.Export(), but builds meshes in a bounded window of pictures at once and writes them strictly in ordinal order, so the destination holds exactly the bytes the sequential overload gives.
Parameters
baseNames(IReadOnlyList<string>) - One wanted name per picture; made safe and distinct exactly asModelBatch.Build()does, in this order.open(Func<int, ModelInput>) - Hands over picturei. Called from worker threads, possibly several at once and for several different pictures: it must be safe to call concurrently. Each picture is released before the batch asks for one beyond the window. ItsModelInput.BaseNameis ignored: the name isbaseNames's.release(Action<ModelInput>?) - Called once for every opened picture as soon as its model is built (or its build failed), on the thread that built it; null when the caller keeps ownership.options(RiseOptions) - How to rise and write.destination(ModelDestination) - A folder or a zip.parallelism(Parallelism) - How many pictures build at once. A sequential degree gives exactly the sequential overload's behavior, on the calling thread.progress(IProgress<int>?) - Told how many pictures are done (written or skipped), in order, one call at a time.cancellation(CancellationToken) - Checked before each window and each picture. A canceled zip is never left behind; a canceled folder keeps every model written before the stop, each one whole.onWritten(Action<string>?) - Told each file's name once it is in the destination, in write order, on the calling thread.
Returns. The file names written, the pictures skipped, and the files that already existed.
Remarks
Build wide, write narrow. The mesh build and the file encode are pure functions of one picture and fan out into slots; the sink (a zip's entries share one stream) is only ever touched by the calling thread, in the ordinal order the sequential overload uses. Memory is bounded by the window — at most twice the degree of finished models wait to be written.
When several pictures in one window fail, the lowest-ordinal one is rethrown, so the message never depends on the thread count. A window that fails writes nothing of itself.
FileNamesFor(string, ModelFormat)¶
The file names ModelWriter.Write() writes for a base name.
Parameters
baseName(string) - The base name.format(ModelFormat) - The format.
Returns. The names, in the writer's order.
Exceptions
ArgumentOutOfRangeException-formatis not a defined model format.
SafeBaseName(string)¶
Makes a name safe as a file name on every platform.
Parameters
name(string) - What the caller wants to call it.
Returns. The name with reserved and control characters replaced by -, outer spaces and dots trimmed; model when nothing is left.
Remarks
An explicit set, not GetInvalidFileNameChars(), which differs by OS.
UniqueBaseNames(IReadOnlyList<string>)¶
Makes a list of names safe and distinct, ignoring case.
Parameters
names(IReadOnlyList<string>) - The wanted names.
Returns. Each name made safe; a collision gets -2, -3, … skipping any suffix already taken.
WriteFolder(string, IReadOnlyList<ModelFile>)¶
Writes the files into a folder, creating it.
Parameters
directory(string) - The folder.files(IReadOnlyList<ModelFile>) - The files.
Exceptions
ArgumentException-directoryis null or whitespace.
WriteZip(string, IReadOnlyList<ModelFile>)¶
Writes the files into a zip: ordinal-sorted entries, fixed timestamp, so identical input gives identical bytes.
Parameters
zipPath(string) - The zip to create or replace.files(IReadOnlyList<ModelFile>) - The files.
Exceptions
ArgumentException-zipPathis null or whitespace.