diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b10e890..b9d1f76 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,6 +30,8 @@ The frozen convenience methods on `NwcDocument` and `NwcAssembly` are in `src/NwcIO/Compatibility`. They keep their existing signatures and assembly so applications can continue using them while replacements are developed. Keep new native-format operations with the reader or writer. +The CLI uses the public APIs of NwcIO and NwcIO.Scene. Command-specific +presentation, such as model labels in raycast output, belongs to the CLI. ## Test Fixtures diff --git a/src/NwcIO.Cli/Program.cs b/src/NwcIO.Cli/Program.cs index 1e7ec4d..83813d0 100644 --- a/src/NwcIO.Cli/Program.cs +++ b/src/NwcIO.Cli/Program.cs @@ -2,7 +2,6 @@ using System.Globalization; using System.Reflection; using NwcIO; -using NwcIO.Internal.Json; using NwcIO.Model; using NwcIO.Model.Spatial; using NwcIO.Model.Viewer; @@ -901,20 +900,20 @@ int ProcessLoadedAssembly(NwcAssembly preloaded, string displayPath, string? out { if (stdoutStream != null) { - JsonExporter.Write(doc, stdoutStream, exportOptions); + doc.SaveJson(stdoutStream, exportOptions); stdoutStream.Flush(); } else { using var stdout = Console.OpenStandardOutput(); - JsonExporter.Write(doc, stdout, exportOptions); + doc.SaveJson(stdout, exportOptions); stdout.Flush(); } } else { EnsureParentDirectory(outputPath); - JsonExporter.WriteFile(doc, outputPath, exportOptions); + doc.SaveJson(outputPath, exportOptions); } } @@ -1701,7 +1700,7 @@ private static void ExecuteRaycastTest( if (index.Raycast(origin, dir, out var hit)) { - string? modelLabel = assembly?.GetModelLabel(hit.Mesh); + string? modelLabel = assembly is null ? null : GetModelLabel(assembly, hit.Mesh); string modelSuffix = modelLabel is null ? string.Empty : FormattableString.Invariant($", Model={modelLabel}"); @out.WriteLine(FormattableString.Invariant( $"Raycast HIT at distance {hit.Distance:F3}: Point={hit.Point}, Normal={hit.Normal}, MeshId={hit.Mesh.Id}, Triangle={hit.TriangleIndex}{modelSuffix}")); @@ -1712,6 +1711,23 @@ private static void ExecuteRaycastTest( } } + private static string? GetModelLabel(NwcAssembly assembly, NwcMesh mesh) + { + int modelIndex = assembly.GetModelIndex(mesh); + if (modelIndex < 0) + { + return null; + } + + var model = assembly.Models[modelIndex]; + string modelName = Path.GetFileNameWithoutExtension(model.FileInfo.SourcePath ?? string.Empty); + if (string.IsNullOrEmpty(modelName)) + { + modelName = $"Model_{modelIndex + 1}"; + } + return $"M{modelIndex + 1}_{modelName}"; + } + private static void ApplyClashGrouping(Model.Clash.NwcClashTest test, string? mode, double radius, bool printReport, TextWriter? errWriter = null) { var @err = errWriter ?? Console.Error; diff --git a/src/NwcIO/Compatibility/NwcAssembly.Compatibility.cs b/src/NwcIO/Compatibility/NwcAssembly.Compatibility.cs index b32d3c5..ecd3b19 100644 --- a/src/NwcIO/Compatibility/NwcAssembly.Compatibility.cs +++ b/src/NwcIO/Compatibility/NwcAssembly.Compatibility.cs @@ -202,7 +202,24 @@ public void SaveGlb(string path, bool worldCoordinates = true) /// Exports the entire federated assembly to a Wavefront OBJ file. public void SaveObj(string path, bool worldCoordinates = true) { - ObjExporter.WriteFile(AllMeshes, path, worldCoordinates, Name, GetModelLabel); + ObjExporter.WriteFile(AllMeshes, path, worldCoordinates, Name, GetObjModelLabel); + } + + private string? GetObjModelLabel(NwcMesh mesh) + { + int modelIndex = GetModelIndex(mesh); + if (modelIndex < 0) + { + return null; + } + + var model = Models[modelIndex]; + string modelName = Path.GetFileNameWithoutExtension(model.FileInfo.SourcePath ?? string.Empty); + if (string.IsNullOrEmpty(modelName)) + { + modelName = $"Model_{modelIndex + 1}"; + } + return $"M{modelIndex + 1}_{modelName}"; } /// Exports the entire federated assembly with geometry, materials, and spatial hierarchy to an IFC2x3 STEP file (.ifc). diff --git a/src/NwcIO/Model/NwcAssembly.cs b/src/NwcIO/Model/NwcAssembly.cs index 888397d..13c334b 100644 --- a/src/NwcIO/Model/NwcAssembly.cs +++ b/src/NwcIO/Model/NwcAssembly.cs @@ -503,23 +503,6 @@ public void SaveNwf(string path) manifest.Save(path); } - internal string? GetModelLabel(NwcMesh mesh) - { - int modelIndex = GetModelIndex(mesh); - if (modelIndex < 0) - { - return null; - } - - var model = Models[modelIndex]; - string modelName = Path.GetFileNameWithoutExtension(model.FileInfo.SourcePath ?? string.Empty); - if (string.IsNullOrEmpty(modelName)) - { - modelName = $"Model_{modelIndex + 1}"; - } - return $"M{modelIndex + 1}_{modelName}"; - } - /// /// Builds a single document that carries the assembly scene tree, meshes with their transforms, /// viewpoints, GUIDs, the assembly selection sets and the assembly TimeLiner schedule. diff --git a/src/NwcIO/NwcIO.csproj b/src/NwcIO/NwcIO.csproj index 705cbfa..75f126f 100644 --- a/src/NwcIO/NwcIO.csproj +++ b/src/NwcIO/NwcIO.csproj @@ -12,7 +12,6 @@ -