Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 21 additions & 5 deletions src/NwcIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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}"));
Expand All @@ -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;
Expand Down
19 changes: 18 additions & 1 deletion src/NwcIO/Compatibility/NwcAssembly.Compatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,24 @@ public void SaveGlb(string path, bool worldCoordinates = true)
/// <summary>Exports the entire federated assembly to a Wavefront OBJ file.</summary>
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}";
}

/// <summary>Exports the entire federated assembly with geometry, materials, and spatial hierarchy to an IFC2x3 STEP file (.ifc).</summary>
Expand Down
17 changes: 0 additions & 17 deletions src/NwcIO/Model/NwcAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}

/// <summary>
/// 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.
Expand Down
1 change: 0 additions & 1 deletion src/NwcIO/NwcIO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
<ItemGroup>
<InternalsVisibleTo Include="NwcIO.Tests" />
<InternalsVisibleTo Include="NwcIO.Scene.Tests" />
<InternalsVisibleTo Include="NwcIO.Cli" />
</ItemGroup>

</Project>
Loading