Your comments

Got the measurement working also. Here my (dirty) code, but should give others some idea how to add the measurement line and label with distance:


private void viewPort3d_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

{
// Remove previour measurement line
if (viewPort3d.Children.Contains(mMeasurementline)) viewPort3d.Children.Remove(mMeasurementline);
if (viewPort3d.Children.Contains(mMeasurementText)) viewPort3d.Children.Remove(mMeasurementText);

// Define first point
System.Windows.Point p = e.GetPosition(viewPort3d);
var hits = Viewport3DHelper.FindHits(viewPort3d.Viewport, p);
if (hits.Any()) mPoint1 = hits[0].Position;
}

private void viewPort3d_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
System.Windows.Point p = e.GetPosition(viewPort3d);
var hits = Viewport3DHelper.FindHits(viewPort3d.Viewport, p);

if (hits.Any())
{
// Define second point
mPoint2 = hits[0].Position;
if (mPoint1 != null && mPoint2 != null)
{
double distance = Math.Sqrt(Math.Pow(mPoint1.X - mPoint2.X, 2) + Math.Pow(mPoint1.Y - mPoint2.Y, 2) + Math.Pow(mPoint1.Z - mPoint2.Z, 2));
mMeasurementText = new TextVisual3D();
mMeasurementText.Text = Math.Round(distance, 3).ToString() + " mm";
mMeasurementText.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
mMeasurementText.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
mMeasurementText.Height = distance / 10;
mMeasurementText.Position = new Point3D((mPoint1.X + mPoint2.X) / 2, (mPoint1.Y + mPoint2.Y) / 2, (mPoint1.Z + mPoint2.Z) / 2);
mMeasurementText.TextDirection = new Vector3D((mPoint1.X - mPoint2.X) / distance, (mPoint1.Y - mPoint2.Y) / distance, (mPoint1.Z - mPoint2.Z) / distance);
mMeasurementText.UpDirection = viewPort3d.Camera.UpDirection;
mMeasurementText.UpDirection.Normalize();
mMeasurementText.Foreground = new SolidColorBrush(Colors.Black);
viewPort3d.Children.Add(mMeasurementText);

mMeasurementline = new LinesVisual3D();
mMeasurementline.Points.Add(mPoint1);
mMeasurementline.Points.Add(mPoint2);
viewPort3d.Children.Add(mMeasurementline);
}
}

}

Hi, many thanks for the tips, these allowed to already find a solution for the "mesh on top". The trick was NOT to use the modelimporter class, but to use the STLReader class directly, as this exposes the read-in meshes. The modelimporter only gives a Model3DGroup back, and from this you cannot recreate the points collection (or at least I did not find out how...)


My code now looks like this:


StLReader reader = new StLReader();

reader.Read(fileName);
LinesVisual3D lines = new LinesVisual3D();
lines.Thickness = 1;
lines.Points = reader.Meshes[0].Positions;

viewPort3d.Children.Add(lines);


Now to solve the measurement function...

Hi,


Many thanx for the quick reply. There are actually 2 features I would like some hints on:

- how to make distance measurements between two points in a model

- showing the wire mesh on top of the coloured surfaces


For this last one I read I should use the LinesVisual3D and populate that using the Tesselate function, but this function seems not available on my imported STL-file (a ModelVisual3D object).

Very nice, really impressed. Any change parts of this will ever be released open source? I just started playing around with the Helix toolkit, and your library would be wonderfull to improve the looks and features...