Compare commits

...

2 Commits

Author SHA1 Message Date
ema
f39b53a5c6 Support Point Cloud Data (.pcd) for 3D spatial
Some checks failed
MSBuild / build (push) Has been cancelled
MSBuild / publish (push) Has been cancelled
1. Only support PCD files with PointXYZ format.
2. Not supported for Color or Intensity formats.
2025-07-28 16:48:13 +08:00
ema
68cb555bad Unsupported .pmx incorrectly handled in advance 2025-07-28 16:19:30 +08:00
3 changed files with 111 additions and 4 deletions

View File

@@ -17,6 +17,8 @@
using Assimp;
using HelixToolkit.Wpf;
using PcdSharp.IO;
using PcdSharp.Struct;
using System;
using System.IO;
using System.Linq;
@@ -54,6 +56,86 @@ public partial class HelixPanel
modelVisual.Content = model;
}
}
if (importerType == ImporterType.Extended_PCD)
{
// Only support PCD files with PointXYZ format
// Not supported for Color or Intensity formats
var xyzCloud = PCDReader.Read<PointXYZ>(_path);
// Create a single geometry for all points to improve performance
var pointCloudGeometry = new MeshGeometry3D();
var positions = new Point3DCollection();
var triangleIndices = new Int32Collection();
// Create material for points
var pointMaterial = new DiffuseMaterial(new SolidColorBrush(Color.FromRgb(0x60, 0x80, 0xFF)));
// Adaptive point size based on total number of points
var totalPoints = xyzCloud.Points.Count;
var pointSize = totalPoints > 10000 ? 0.05d : totalPoints > 1000 ? 0.1d : 0.2d;
// Limit points for performance (show every Nth point if too many)
var step = Math.Max(1, totalPoints / 50000); // Limit to ~50k points max
var vertexIndex = 0;
for (int i = 0; i < xyzCloud.Points.Count; i += step)
{
var point = xyzCloud.Points[i];
// Create a small cube for each point
var halfSize = pointSize / 2;
// Add 8 vertices for the cube
var baseIndex = vertexIndex;
// Front face vertices
positions.Add(new Point3D(point.X - halfSize, point.Y - halfSize, point.Z + halfSize));
positions.Add(new Point3D(point.X + halfSize, point.Y - halfSize, point.Z + halfSize));
positions.Add(new Point3D(point.X + halfSize, point.Y + halfSize, point.Z + halfSize));
positions.Add(new Point3D(point.X - halfSize, point.Y + halfSize, point.Z + halfSize));
// Back face vertices
positions.Add(new Point3D(point.X - halfSize, point.Y - halfSize, point.Z - halfSize));
positions.Add(new Point3D(point.X + halfSize, point.Y - halfSize, point.Z - halfSize));
positions.Add(new Point3D(point.X + halfSize, point.Y + halfSize, point.Z - halfSize));
positions.Add(new Point3D(point.X - halfSize, point.Y + halfSize, point.Z - halfSize));
// Add triangle indices for the cube (12 triangles, 36 indices)
// Front face
triangleIndices.Add(baseIndex + 0); triangleIndices.Add(baseIndex + 1); triangleIndices.Add(baseIndex + 2);
triangleIndices.Add(baseIndex + 0); triangleIndices.Add(baseIndex + 2); triangleIndices.Add(baseIndex + 3);
// Back face
triangleIndices.Add(baseIndex + 4); triangleIndices.Add(baseIndex + 6); triangleIndices.Add(baseIndex + 5);
triangleIndices.Add(baseIndex + 4); triangleIndices.Add(baseIndex + 7); triangleIndices.Add(baseIndex + 6);
// Left face
triangleIndices.Add(baseIndex + 4); triangleIndices.Add(baseIndex + 0); triangleIndices.Add(baseIndex + 3);
triangleIndices.Add(baseIndex + 4); triangleIndices.Add(baseIndex + 3); triangleIndices.Add(baseIndex + 7);
// Right face
triangleIndices.Add(baseIndex + 1); triangleIndices.Add(baseIndex + 5); triangleIndices.Add(baseIndex + 6);
triangleIndices.Add(baseIndex + 1); triangleIndices.Add(baseIndex + 6); triangleIndices.Add(baseIndex + 2);
// Top face
triangleIndices.Add(baseIndex + 3); triangleIndices.Add(baseIndex + 2); triangleIndices.Add(baseIndex + 6);
triangleIndices.Add(baseIndex + 3); triangleIndices.Add(baseIndex + 6); triangleIndices.Add(baseIndex + 7);
// Bottom face
triangleIndices.Add(baseIndex + 4); triangleIndices.Add(baseIndex + 5); triangleIndices.Add(baseIndex + 1);
triangleIndices.Add(baseIndex + 4); triangleIndices.Add(baseIndex + 1); triangleIndices.Add(baseIndex + 0);
vertexIndex += 8;
}
pointCloudGeometry.Positions = positions;
pointCloudGeometry.TriangleIndices = triangleIndices;
// Create the model
var pointCloudModel = new GeometryModel3D
{
Geometry = pointCloudGeometry,
Material = pointMaterial,
BackMaterial = pointMaterial
};
modelVisual.Content = pointCloudModel;
}
else
{
var modelImporter = new ModelImporter();
@@ -90,6 +172,7 @@ file static class Importer
".stl" or ".obj" or ".3ds" or ".lwo" or ".ply" => ImporterType.Default,
".fbx" or ".3mf" or ".glb" or ".gltf" or ".dae" or ".dxf" => ImporterType.Extended,
".pmx" => ImporterType.Extended_MMD,
".pcd" => ImporterType.Extended_PCD,
_ => ImporterType.Unknown,
};
}
@@ -97,8 +180,28 @@ file static class Importer
file enum ImporterType
{
/// <summary>
/// Reserved or unspecified import type
/// </summary>
Unknown,
/// <summary>
/// Default importer supported by HelixToolkit
/// </summary>
Default,
/// <summary>
/// Extended importer supported by Assimp
/// </summary>
Extended,
/// <summary>
/// Extended MMD (MikuMikuDance) importer
/// </summary>
Extended_MMD,
/// <summary>
/// Extended PCD (Point Cloud Data) importer for 3D spatial data
/// </summary>
Extended_PCD,
}

View File

@@ -31,17 +31,20 @@ public class Plugin : IViewer
/// </summary>
private static readonly HashSet<string> WellKnownExtensions = new(
[
// Default
// Default supported by HelixToolkit
".stl", ".obj", ".3ds", ".lwo", ".ply",
// Extended
// Extended supported by Assimp
".fbx", ".3mf", ".blend", ".glb", ".gltf", ".dae",
#if S_DXF
".dxf",
#endif
// Extended_MMD
".pmx",
// TBD: MMD (MikuMikuDance)
//".pmx",
// PCD (Point Cloud Data)
".pcd",
]);
private HelixPanel _hp;

View File

@@ -55,6 +55,7 @@
<PackageReference Include="HelixToolkit" Version="2.27.0" />
<PackageReference Include="HelixToolkit.Wpf" Version="2.27.0" />
<PackageReference Include="AssimpNet" Version="5.0.0-beta1" />
<PackageReference Include="PcdSharp" Version="1.0.1" />
</ItemGroup>
<ItemGroup>