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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ API between minor releases.

### Added

- Point clouds render as point sprites: export format 4 carries `points` instances and `kind: "points"` geometries
(with optional per-vertex colours); the viewer draws them beside the triangle chunks with shared element visibility,
section clipping and bounds. `ioviewer` reads point clouds (E57, LAS/LAZ, PTG, ReCap, PLY, PCD, PTS, PTX, XYZ and more)
through `PclIO.Scene` 0.1.1. Points are not picked, measured or detail-cut in this version.
- Direct `.rvt` imports include building storeys and straight, circular and multi-segment grid axes through `RvtIO.Scene` 0.5.1.
- `ioviewer` reads Navisworks `.nwc` caches through `NwcIO.Scene` 0.13.0.
- Standalone HTML opens with the section box or cutting planes saved in `ViewerDocument`.
Expand Down
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
<!-- Patch = adds or fixes, minor = breaking while IOScene is 0.x; the -0.0 keeps out previews of the next breaking line
(nuget.org refuses the shorter bound -0 in a dependency). -->
<PackageVersion Include="IOScene" Version="[0.1.2, 0.2.0-0.0)" />
<PackageVersion Include="IOCoord" Version="0.1.0-preview.1" />
<PackageVersion Include="IOCoord" Version="0.1.0-preview.2" />
<PackageVersion Include="IfcIO.Scene" Version="0.11.1" />
<PackageVersion Include="NwcIO.Scene" Version="0.13.0" />
<PackageVersion Include="PclIO.Scene" Version="0.1.1" />
<PackageVersion Include="RvtIO.Scene" Version="0.5.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageVersion Include="xunit" Version="2.9.3" />
Expand Down
1 change: 1 addition & 0 deletions src/IOViewer.Cli/IOViewer.Cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PackageReference Include="IOCoord" />
<PackageReference Include="IfcIO.Scene" />
<PackageReference Include="NwcIO.Scene" />
<PackageReference Include="PclIO.Scene" />
<PackageReference Include="RvtIO.Scene" />
</ItemGroup>

Expand Down
24 changes: 19 additions & 5 deletions src/IOViewer.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@
using IOViewer.Importers;
using IOViewer.Model;
using NwcIO.Scene;
using PclIO.Scene;
using RvtIO.Scene;

namespace IOViewer.Cli;

internal static class Program
{
private const string UsageText = """
Usage: ioviewer <input.glb|input.obj|input.json|input.ifc|input.ifczip|input.rvt|input.nwc> [output.html] [options]
Usage: ioviewer <input.glb|input.obj|input.json|input.ifc|input.ifczip|input.rvt|input.nwc|point-cloud> [output.html] [options]
ioviewer --help | --version

Generates standalone interactive 3D WebGL / HTML BIM & CAD model viewers
from 3D models (glTF/GLB, Wavefront OBJ, JSON, IFC, Revit, Navisworks). The HTML file
from 3D models (glTF/GLB, Wavefront OBJ, JSON, IFC, Revit, Navisworks) and point clouds
(E57, LAS/LAZ, PTG, ReCap, PLY, PCD, PTS, PTX, XYZ and more, read with PclIO). The HTML file
has no external dependencies and works offline. JSON input is viewer JSON,
an IOScene scene file or an IOViewer 0.1/0.2 snapshot. IFC (.ifc, .ifczip)
is read with IfcIO, Revit (.rvt) with RvtIO and Navisworks caches (.nwc)
with NwcIO. Conversion diagnostics are reported as warnings or errors.

Arguments:
<input> Path to input 3D model (.glb, .obj, .json, .ifc, .ifczip, .rvt or .nwc).
<input> Path to input 3D model (.glb, .obj, .json, .ifc, .ifczip, .rvt, .nwc) or point cloud
(.e57, .las, .laz, .ptg, .rcs, .rcp, .ply, .pcd, .pts, .ptx, .xyz, .csv, .sbf, .fls,
.lgsx, .lgs, .srf, .smf, .c3db, .bin, .pnts).
[output] Destination path for exported file (.html, .json or .ivmesh for clustered LOD).
Default: <input-without-ext>.html.

Expand Down Expand Up @@ -328,7 +332,7 @@ public static int Main(string[] args)
int undrawn = ViewerPayloadWriter.UndrawnInstances(doc.Scene);
if (undrawn > 0)
{
Console.Error.WriteLine($"Warning: {undrawn} meshes of lines, points or an unknown kind are not shown; the viewer draws triangles only.");
Console.Error.WriteLine($"Warning: {undrawn} meshes of lines or an unknown kind are not shown; the viewer draws triangles and point clouds.");
}
}

Expand Down Expand Up @@ -366,10 +370,20 @@ private static ViewerDocument Load(string path, out IReadOnlyList<SceneDiagnosti
".ifc" or ".ifczip" => FromIfc(path, out diagnostics),
".rvt" => FromRvt(path, out diagnostics),
".nwc" => FromNwc(path, out diagnostics),
_ => throw new NotSupportedException($"Unsupported input file extension: '{ext}'. Supported: .glb, .obj, .json, .ifc, .ifczip, .rvt, .nwc.")
".e57" or ".las" or ".laz" or ".ptg" or ".rcs" or ".rcp" or ".ply" or ".pcd" or ".pts" or ".ptx"
or ".xyz" or ".csv" or ".sbf" or ".fls" or ".lgsx" or ".lgs" or ".srf" or ".smf" or ".c3db" or ".bin" or ".pnts"
=> FromPcl(path, out diagnostics),
_ => throw new NotSupportedException($"Unsupported input file extension: '{ext}'. Supported: .glb, .obj, .json, .ifc, .ifczip, .rvt, .nwc and point clouds (.e57, .las, .laz, .ptg, .rcs, .rcp, .ply, .pcd, .pts, .ptx, .xyz, .csv, .sbf, .fls, .lgsx, .lgs, .srf, .smf, .c3db, .bin, .pnts).")
};
}

private static ViewerDocument FromPcl(string path, out IReadOnlyList<SceneDiagnostic> diagnostics)
{
var result = PclSceneReader.Read(path);
diagnostics = result.Diagnostics;
return FromScene(path, result.Document, diagnostics);
}

private static ViewerDocument FromIfc(string path, out IReadOnlyList<SceneDiagnostic> diagnostics)
{
var result = IfcSceneReader.Read(path);
Expand Down
96 changes: 83 additions & 13 deletions src/IOViewer/Exporters/ViewerPayloadWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ internal sealed class ViewerPayloadWriter
private readonly List<uint> _instanceMaterial = [];
private readonly List<int> _instanceElement = [];
private readonly List<float> _instanceMatrix = [];
private readonly List<uint> _pointGeometry = [];
private readonly List<uint> _pointMaterial = [];
private readonly List<int> _pointElement = [];
private readonly List<float> _pointMatrix = [];
private readonly Dictionary<string, PreparedViewpoint> _viewpointStates = new(StringComparer.Ordinal);
private readonly List<ViewerBcfTopic> _bcfTopics;
private readonly Dictionary<ViewerBcfViewpoint, PreparedViewpoint> _bcfStates = [];
Expand All @@ -54,6 +58,7 @@ internal sealed class ViewerPayloadWriter
private int _skipped;
private int _writtenMeshes;
private InstanceViews _instances;
private InstanceViews _pointViews;

private ViewerPayloadWriter(ViewerDocument doc, HtmlViewerOptions options)
{
Expand Down Expand Up @@ -230,12 +235,13 @@ private void ValidateMetadata()
}
}

/// <summary>Counts the instances the viewer does not draw because their geometry is not made of triangles.</summary>
/// <summary>Counts the instances the viewer does not draw because their geometry is neither triangles nor points.</summary>
public static int UndrawnInstances(SceneDocument scene)
{
var topology = new Dictionary<int, SceneTopology>();
foreach (var geometry in scene.Geometries) topology.TryAdd(geometry.Id, geometry.Topology);
return scene.Instances.Count(i => topology.TryGetValue(i.GeometryId, out var t) && t != SceneTopology.Triangles);
return scene.Instances.Count(i => topology.TryGetValue(i.GeometryId, out var t)
&& t != SceneTopology.Triangles && t != SceneTopology.Points);
}

private Dictionary<long, int> Build()
Expand Down Expand Up @@ -302,6 +308,11 @@ private Dictionary<long, int> Build()
foreach (var instance in _scene.Instances)
{
var geometry = geometries[instance.GeometryId];
if (geometry.Topology == SceneTopology.Points)
{
AddPointInstance(geometry, instance, elementIndex);
continue;
}
if (geometry.Topology != SceneTopology.Triangles)
{
_skipped++;
Expand Down Expand Up @@ -338,7 +349,7 @@ private Dictionary<long, int> Build()
_instanceGeometry.Add((uint)geometryIndex);
_instanceMaterial.Add((uint)MaterialIndex(instance));
_instanceElement.Add(elementIndex.TryGetValue(instance.ElementId, out int index) ? index : -1);
AddMatrix(transform, translation);
AddMatrix(transform, translation, _instanceMatrix);
_writtenMeshes++;
}

Expand All @@ -347,9 +358,49 @@ private Dictionary<long, int> Build()
_blob.Add(CollectionsMarshal.AsSpan(_instanceMaterial)),
_blob.Add(CollectionsMarshal.AsSpan(_instanceElement)),
_blob.Add(CollectionsMarshal.AsSpan(_instanceMatrix)));
_pointViews = new InstanceViews(
_blob.Add(CollectionsMarshal.AsSpan(_pointGeometry)),
_blob.Add(CollectionsMarshal.AsSpan(_pointMaterial)),
_blob.Add(CollectionsMarshal.AsSpan(_pointElement)),
_blob.Add(CollectionsMarshal.AsSpan(_pointMatrix)));
return elementIndex;
}

// A point instance is baked into RTC and written as a points geometry (positions only, no indices, normals or UVs);
// the viewer draws it as a point sprite cloud, separate from the merged triangle chunks.
private void AddPointInstance(SceneGeometry geometry, SceneInstance instance, Dictionary<long, int> elementIndex)
{
var transform = instance.Transform ?? Transform3d.Identity;
var rtc = new Vector3d[geometry.Vertices.Count];
var box = BoundingBox3d.Empty;
for (int i = 0; i < rtc.Length; i++)
{
rtc[i] = transform.Apply(geometry.Vertices[i]) - _rtcOffset;
box = box.Encapsulate(rtc[i]);
}

int geometryIndex;
Vector3d translation;
if (GeometryQuantizer.TryQuantize(rtc, out var origin, out var q))
{
var local = box.IsEmpty ? box : new BoundingBox3d(box.Min - origin, box.Max - origin);
geometryIndex = AddGeometry(q, null, Vector3d.Zero, Array.Empty<int>(), null, null, local, points: true);
translation = origin;
}
else
{
var min = box.IsEmpty ? Vector3d.Zero : box.Min;
var bounds = new BoundingBox3d(Vector3d.Zero, box.Max - min);
geometryIndex = AddGeometry(null, Floats(rtc, min), null, Array.Empty<int>(), null, null, bounds, points: true);
translation = min;
}

_pointGeometry.Add((uint)geometryIndex);
_pointMaterial.Add((uint)MaterialIndex(instance));
_pointElement.Add(elementIndex.TryGetValue(instance.ElementId, out int index) ? index : -1);
AddMatrix(Transform3d.Identity, translation, _pointMatrix);
}

private static void CheckIndices(IReadOnlyList<int> indices, int vertexCount, string owner)
{
for (int i = 0; i < indices.Count; i++)
Expand Down Expand Up @@ -501,7 +552,7 @@ private static float[] Floats(Vector3d[] vertices, Vector3d offset)

// Returns the index of an identical geometry written before (same bytes and origin), or writes this one. Positions
// are either grid steps q from origin, or f32 positions (origin null).
private int AddGeometry(ushort[]? q, float[]? positions, Vector3d? origin, IReadOnlyList<int> indices, short[]? normals, float[]? uvs, BoundingBox3d bounds)
private int AddGeometry(ushort[]? q, float[]? positions, Vector3d? origin, IReadOnlyList<int> indices, short[]? normals, float[]? uvs, BoundingBox3d bounds, bool points = false)
{
int vertexCount = (q?.Length ?? positions!.Length) / 3;
ushort[]? indices16 = null;
Expand All @@ -519,6 +570,7 @@ private int AddGeometry(ushort[]? q, float[]? positions, Vector3d? origin, IRead

var hasher = new HashCode();
hasher.Add(origin);
hasher.Add(points);
hasher.AddBytes(Bytes(q));
hasher.AddBytes(Bytes(positions));
hasher.AddBytes(Bytes(indices16));
Expand All @@ -537,7 +589,8 @@ private int AddGeometry(ushort[]? q, float[]? positions, Vector3d? origin, IRead
foreach (int candidate in candidates)
{
var entry = _geometries[candidate];
if (entry.Origin == origin
if (entry.Points == points
&& entry.Origin == origin
&& (q is not null ? Same(q, entry.Positions) : Same(positions, entry.Positions))
&& (indices16 is not null ? Same(indices16, entry.Indices) : Same(indices32, entry.Indices))
&& Same(normals, entry.Normals)
Expand All @@ -553,7 +606,8 @@ private int AddGeometry(ushort[]? q, float[]? positions, Vector3d? origin, IRead
indices16 is not null ? _blob.Add(indices16) : _blob.Add(indices32),
normals is null ? null : _blob.Add(normals),
uvs is null ? null : _blob.Add(uvs),
bounds);
bounds,
points);
_geometries.Add(written);
candidates.Add(_geometries.Count - 1);
return _geometries.Count - 1;
Expand Down Expand Up @@ -593,13 +647,13 @@ private int MaterialIndex(SceneInstance instance)
}

// Matrix4.elements[0,1,2,4,5,6,8,9,10,12,13,14]: the three axes of t, then the translation, already in RTC.
private void AddMatrix(Transform3d t, Vector3d translation)
private static void AddMatrix(Transform3d t, Vector3d translation, List<float> target)
{
foreach (var axis in (ReadOnlySpan<Vector3d>)[t.XAxis, t.YAxis, t.ZAxis, translation])
{
_instanceMatrix.Add((float)axis.X);
_instanceMatrix.Add((float)axis.Y);
_instanceMatrix.Add((float)axis.Z);
target.Add((float)axis.X);
target.Add((float)axis.Y);
target.Add((float)axis.Z);
}
}

Expand Down Expand Up @@ -627,7 +681,7 @@ public void WriteMeta(Stream output)
{
using var w = new Utf8JsonWriter(output);
w.WriteStartObject();
w.WriteNumber("format", 3);
w.WriteNumber("format", _pointGeometry.Count > 0 ? 4 : 3);
w.WriteString("title", _options.Title);
var host = _scene.Models.Count > 0 ? _scene.Models[0] : null;
w.WriteString("author", host?.Author ?? "IOViewer");
Expand Down Expand Up @@ -689,6 +743,7 @@ public void WriteMeta(Stream output)
}
w.WritePropertyName("indices");
g.Indices.WriteTo(w);
if (g.Points) w.WriteString("kind", "points");
WriteView(w, "normals", g.Normals);
WriteView(w, "uvs", g.Uvs);
WriteBox(w, "bbox", g.Bounds, Vector3d.Zero);
Expand All @@ -709,6 +764,21 @@ public void WriteMeta(Stream output)
_instances.Matrix.WriteTo(w);
w.WriteEndObject();

if (_pointGeometry.Count > 0)
{
w.WriteStartObject("points");
w.WriteNumber("count", _pointGeometry.Count);
w.WritePropertyName("geometry");
_pointViews.Geometry.WriteTo(w);
w.WritePropertyName("material");
_pointViews.Material.WriteTo(w);
w.WritePropertyName("element");
_pointViews.Element.WriteTo(w);
w.WritePropertyName("matrix");
_pointViews.Matrix.WriteTo(w);
w.WriteEndObject();
}

WriteReview(w);
w.WriteEndObject();
}
Expand Down Expand Up @@ -1095,8 +1165,8 @@ private sealed record PreparedViewpoint(SectionState? Sections, int[]? HiddenEle

private readonly record struct MaterialKey(byte R, byte G, byte B, double Opacity, int? Texture);

// Origin is META q.o: set for u16 grid-step positions, null for f32.
private sealed record GeometryEntry(BlobView Positions, Vector3d? Origin, BlobView Indices, BlobView? Normals, BlobView? Uvs, BoundingBox3d Bounds);
// Origin is META q.o: set for u16 grid-step positions, null for f32. Points marks a point-sprite geometry (no indices).
private sealed record GeometryEntry(BlobView Positions, Vector3d? Origin, BlobView Indices, BlobView? Normals, BlobView? Uvs, BoundingBox3d Bounds, bool Points = false);

// An own-vertex mesh baked into RTC: Relative = float32 positions relative to Min, the exact minimum corner; Indices
// with the winding reversed under a mirroring transform.
Expand Down
364 changes: 182 additions & 182 deletions src/IOViewer/Viewer/dist/viewer.js

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion src/IOViewer/Viewer/src/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,22 @@ function validateMeta(meta) {
|| g.positions?.t !== (q ? 'u16' : 'f32')
|| (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.uvs != null && g.uvs.t !== 'f32')
|| (g.kind != null && g.kind !== 'points')
|| (g.colors != null && g.colors.t !== 'u8')) {
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.`);
}
}
validateReviewMeta(meta);
for (const material of meta.materials) {
const index = material.texture;
Expand Down
Loading