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: 3 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ what breaks the scene contract, such as an instance that names a missing element

The model's up axis is +Z. The interface is in Russian when the browser language is Russian and in English otherwise.

Viewer JSON can store drawing labels in `Annotations` and layouts in `Sheets`. Set `InitialSheetKey` to choose the first layout shown.
A label can reference an `ElementId` so it follows that element's visibility. Its optional `Width` sets the wrap width in scene metres.

Point clouds have a collapsible minimap showing their XY footprint and the camera heading. Colored point cloud inputs keep their source RGB.
A viewer snapshot can also contain `PointColors`, a dictionary using scene geometry IDs and base64 RGB triplets in vertex order,
and `Panoramas`, a list with `ElementId`, XYZ `Position` in scene metres, and a base64 `Jpeg`. Use a 2:1 equirectangular JPEG with its
Expand Down
2 changes: 1 addition & 1 deletion src/IOViewer.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public static int Main(string[] args)
int undrawn = ViewerPayloadWriter.UndrawnInstances(doc.Scene);
if (undrawn > 0)
{
Console.Error.WriteLine($"Warning: {undrawn} meshes of lines or an unknown kind are not shown; the viewer draws triangles and point clouds.");
Console.Error.WriteLine($"Warning: {undrawn} meshes of an unknown kind are not shown; the viewer draws triangles, lines and point clouds.");
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/IOViewer/Exporters/HtmlViewerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public sealed class HtmlViewerOptions
public bool IncludeClashes { get; set; } = true;
public bool InitialWireframe { get; set; }
public bool InitialWhiteMode { get; set; }
public bool Initial2DMode { get; set; }
public string? InitialBackground { get; set; }

/// <summary>
/// Maximum total number of mesh vertices written to the viewer (each mesh counts the vertices it draws).
Expand Down
12 changes: 12 additions & 0 deletions src/IOViewer/Exporters/JsonViewerExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ internal sealed class ViewerJsonFile
public Dictionary<int, byte[]>? PointIntensities { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<ViewerPanorama>? Panoramas { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<ViewerAnnotation>? Annotations { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public List<ViewerSheet>? Sheets { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? InitialSheetKey { get; set; }

public static ViewerJsonFile From(ViewerDocument doc) => new()
{
Expand All @@ -91,6 +97,9 @@ internal sealed class ViewerJsonFile
PointColors = doc.PointColors is { Count: > 0 } ? doc.PointColors : null,
PointIntensities = doc.PointIntensities is { Count: > 0 } ? doc.PointIntensities : null,
Panoramas = doc.Panoramas is { Count: > 0 } ? doc.Panoramas : null,
Annotations = doc.Annotations is { Count: > 0 } ? doc.Annotations : null,
Sheets = doc.Sheets is { Count: > 0 } ? doc.Sheets : null,
InitialSheetKey = doc.InitialSheetKey,
};

public ViewerDocument ToDocument() => new(Scene)
Expand All @@ -104,5 +113,8 @@ internal sealed class ViewerJsonFile
PointColors = PointColors ?? [],
PointIntensities = PointIntensities ?? [],
Panoramas = Panoramas ?? [],
Annotations = Annotations ?? [],
Sheets = Sheets ?? [],
InitialSheetKey = InitialSheetKey,
};
}
192 changes: 189 additions & 3 deletions src/IOViewer/Exporters/ViewerPayloadWriter.cs

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions src/IOViewer/Model/ViewerAnnotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using IOScene;

namespace IOViewer.Model;

/// <summary>
/// A 2D/3D text label attached to the drawing (such as CAD <c>TEXT</c> or <c>MTEXT</c>) rendered in the viewer overlay.
/// </summary>
public sealed class ViewerAnnotation
{
/// <summary>Text string to display (newlines separate lines).</summary>
public string Text { get; set; } = string.Empty;

/// <summary>Anchor position in scene coordinates (metres, Z up).</summary>
public Vector3d Position { get; set; }

/// <summary>Text height in scene units (metres).</summary>
public double Height { get; set; } = 0.25;

/// <summary>Counter-clockwise rotation angle in the XY plane, in radians.</summary>
public double RotationRadians { get; set; }

/// <summary>Optional wrapping box width in scene units (0 disables wrapping).</summary>
public double Width { get; set; }

/// <summary>AutoCAD-compatible attachment point (1=TL, 2=TC, 3=TR, 4=ML, 5=MC, 6=MR, 7=BL, 8=BC, 9=BR).</summary>
public int Attachment { get; set; } = 1;

/// <summary>Optional foreground colour (sRGB); null falls back to adaptive foreground ink.</summary>
public RgbaColor? Color { get; set; }

/// <summary>Optional owning element id in <see cref="SceneDocument.Elements"/> so hiding/isolating hides the text too.</summary>
public long? ElementId { get; set; }

/// <summary>Optional sheet key in <see cref="ViewerDocument.Sheets"/> when the annotation belongs to a specific sheet/space.</summary>
public string? SheetKey { get; set; }
}
9 changes: 9 additions & 0 deletions src/IOViewer/Model/ViewerDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public ViewerDocument(SceneDocument scene)
/// <summary>Equirectangular photographs attached to scan elements.</summary>
public List<ViewerPanorama> Panoramas { get; set; } = [];

/// <summary>2D/3D text annotations overlaid on the drawing.</summary>
public List<ViewerAnnotation> Annotations { get; set; } = [];

/// <summary>Switchable spaces and paper layouts (e.g. Model Space and Paper Space sheets).</summary>
public List<ViewerSheet> Sheets { get; set; } = [];

/// <summary>Optional key of the initial sheet to show on load.</summary>
public string? InitialSheetKey { get; set; }

/// <summary>Title of the scene: reads and writes <see cref="SceneDocument.Title"/>.</summary>
[JsonIgnore]
public string Title
Expand Down
30 changes: 30 additions & 0 deletions src/IOViewer/Model/ViewerSheet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using IOScene;

namespace IOViewer.Model;

/// <summary>
/// A switchable drawing space or paper layout inside <see cref="ViewerDocument"/> (such as Model Space or Paper Space Sheet).
/// </summary>
public sealed class ViewerSheet
{
/// <summary>Unique sheet/space key (e.g. <c>model</c>, <c>Layout1</c>).</summary>
public string Key { get; set; } = string.Empty;

/// <summary>Display label shown in the viewer sheet switcher.</summary>
public string Name { get; set; } = string.Empty;

/// <summary>True when this sheet represents Model Space rather than a Paper Space layout.</summary>
public bool IsModelSpace { get; set; }

/// <summary>Preferred 2D CAD view lock when switching to this sheet.</summary>
public bool Is2D { get; set; } = true;

/// <summary>Optional preferred background hex colour (<c>#RRGGBB</c>) when activating this sheet.</summary>
public string? BackgroundColor { get; set; }

/// <summary>Optional paper extents drawn as a subtle sheet frame when active.</summary>
public BoundingBox3d? PaperBounds { get; set; }

/// <summary>Element ids belonging to this sheet (elements absent from active sheet are hidden when it is selected).</summary>
public IReadOnlyList<long> ElementIds { get; set; } = [];
}
450 changes: 253 additions & 197 deletions src/IOViewer/Viewer/dist/viewer.js

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions src/IOViewer/Viewer/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,26 @@ function validateMeta(meta) {
|| (q && (!vector(q.o) || typeof q.s !== 'number'))
|| (g.normals != null && !['f32', 'i16'].includes(g.normals.t))
|| (g.uvs != null && g.uvs.t !== 'f32')
|| (g.kind != null && g.kind !== 'points')
|| (g.kind != null && g.kind !== 'points' && g.kind !== 'lines')
|| (g.colors != null && (g.kind !== 'points' || g.colors.t !== 'u8' || g.colors.n !== g.positions.n))
|| (g.intensities != null && (g.kind !== 'points' || g.intensities.t !== 'u8' || 3 * g.intensities.n !== g.positions.n))) {
throw new ModelDataError('Invalid META geometry.');
}
}
if (meta.points != null) {
const p = meta.points;
if (!object(p) || !Number.isSafeInteger(p.count) || p.count < 0) throw new ModelDataError('Invalid META point count.');
for (const [name, type, length] of [
['geometry', 'u32', p.count], ['material', 'u32', p.count],
['element', 'i32', p.count], ['matrix', 'f32', p.count * 12],
]) {
if (p[name]?.t !== type || p[name].n !== length) throw new ModelDataError(`Invalid META point ${name} view.`);
for (const kind of ['points', 'lines']) {
if (meta[kind] != null) {
const p = meta[kind];
if (!object(p) || !Number.isSafeInteger(p.count) || p.count < 0) throw new ModelDataError(`Invalid META ${kind} count.`);
for (const [name, type, length] of [
['geometry', 'u32', p.count], ['material', 'u32', p.count],
['element', 'i32', p.count], ['matrix', 'f32', p.count * 12],
]) {
if (p[name]?.t !== type || p[name].n !== length) throw new ModelDataError(`Invalid META ${kind} ${name} view.`);
}
}
}
if (meta.annotations != null && !records(meta.annotations)) throw new ModelDataError('Invalid META annotations.');
if (meta.sheets != null && !records(meta.sheets)) throw new ModelDataError('Invalid META sheets.');
if (meta.panoramas != null && (!records(meta.panoramas) || meta.panoramas.some((p) =>
!Number.isInteger(p.element) || p.element < 0 || p.element >= meta.elements.length ||
(p.name != null && typeof p.name !== 'string') || !vector(p.position) || !p.position.every(Number.isFinite) || !Number.isFinite(p.yaw) ||
Expand Down
Loading
Loading