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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ The default and the fallback for missing or unsupported drawing units are both m
dwgio scene drawing.dwg drawing.scene.json --unit mm
```

The plain export command writes OBJ, GLB and HTML by output extension and accepts the same `--unit` values:
The plain export command writes OBJ, GLB and HTML by output extension and accepts the same `--unit` values.
OBJ and GLB contain model space only; use HTML to view paper-space sheets and their viewports:

```sh
dwgio drawing.dwg drawing.obj --unit mm # Wavefront OBJ + drawing.mtl with the ACI colours
Expand Down
2 changes: 2 additions & 0 deletions src/DwgIO.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,13 @@ internal static int ExportDocument(
return DwgExitCodes.Usage;
}

sceneOptions.IncludePaperSpace = false;
var objResult = DwgSceneExport.SaveObj(doc, target, sceneOptions);
output.WriteLine($"{doc.Version} elements={objResult.ElementCount} ({objResult.ElementsWithGeometry} with geometry) -> {target}");
}
else if (Path.GetExtension(target).Equals(".glb", StringComparison.OrdinalIgnoreCase))
{
sceneOptions.IncludePaperSpace = false;
var glbResult = DwgSceneExport.SaveGlb(doc, target, sceneOptions);
output.WriteLine($"{doc.Version} elements={glbResult.ElementCount} ({glbResult.ElementsWithGeometry} with geometry) -> {target}");
}
Expand Down
49 changes: 46 additions & 3 deletions tests/DwgIO.Tests/BlocksAndSheetsTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Text;
using DwgIO.Cli;
using DwgIO.Export;
using DwgIO.Model;
using DwgIO.Scene;
using IOScene;
using IOScene.Formats;
using Xunit;

namespace DwgIO.Tests;
Expand Down Expand Up @@ -87,8 +89,7 @@ public void Insert_ExpandsBlockGeometry_WithTransformBasePointAndByBlockColor()
Assert.Equal(new RgbaColor(255, 0, 0), inst.Color);
}

[Fact]
public void PaperSpaceLayoutAndViewport_ProjectAndClipModelSpaceGeometryIntoSheet()
private static DwgDocument DrawingWithViewport()
{
const ulong modelHandle = 0x1F;
const ulong paperHandle = 0x20;
Expand Down Expand Up @@ -186,7 +187,13 @@ public void PaperSpaceLayoutAndViewport_ProjectAndClipModelSpaceGeometryIntoShee
},
};

var doc = new DwgDocument("sheets.dwg", TestHeader, entities, blocks: blocks, layouts: layouts);
return new DwgDocument("sheets.dwg", TestHeader, entities, blocks: blocks, layouts: layouts);
}

[Fact]
public void PaperSpaceLayoutAndViewport_ProjectAndClipModelSpaceGeometryIntoSheet()
{
var doc = DrawingWithViewport();
var result = DwgSceneReader.Read(doc, new DwgSceneOptions
{
LengthUnit = "m",
Expand Down Expand Up @@ -230,6 +237,42 @@ public void PaperSpaceLayoutAndViewport_ProjectAndClipModelSpaceGeometryIntoShee
Assert.Contains("\"initial2DMode\":true", autoHtml, StringComparison.Ordinal);
}

[Theory]
[InlineData(".obj")]
[InlineData(".glb")]
public void DirectExchangeExport_WritesModelLineWithoutProjectedViewportCopy(string extension)
{
using var directory = new TemporaryDirectory();
string path = Path.Combine(directory.Path, "model" + extension);

Assert.Equal(DwgExitCodes.Ok, Program.ExportDocument(DrawingWithViewport(), path, TextWriter.Null, TextWriter.Null));

if (extension == ".obj")
{
string[] lines = File.ReadAllLines(path);
Assert.Single(lines, line => line.StartsWith("l ", StringComparison.Ordinal));
Assert.Collection(lines.Where(line => line.StartsWith("v ", StringComparison.Ordinal)).Order(StringComparer.Ordinal),
vertex => Assert.Equal("v -20 0 0", vertex),
vertex => Assert.Equal("v 20 0 0", vertex));
}
else
{
var scene = GlbSceneReader.Load(path);
var instance = Assert.Single(scene.Instances);
var geometry = Assert.Single(scene.Geometries, g => g.Id == instance.GeometryId);
Assert.Equal(SceneTopology.Lines, geometry.Topology);
var vertices = geometry.Vertices.Select((instance.Transform ?? Transform3d.Identity).Apply).OrderBy(v => v.X).ToArray();
Assert.Equal(new[] { new Vector3d(-20, 0, 0), new Vector3d(20, 0, 0) }, vertices);
}
}

private sealed class TemporaryDirectory : IDisposable
{
public string Path { get; } = Directory.CreateTempSubdirectory("dwgio-sheet-").FullName;

public void Dispose() => Directory.Delete(Path, recursive: true);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
Expand Down
Loading