In this code it happens that :- total object is 90mm, now if i enter 50 in textbox and object from 1mm to 50mm appears and object from 51mm to 90mm is removed. Now if I enter 60 in the textbox then the object from 1mm to 60mm should appear and the object from 61mm to 90mm should be removed but only the object from 1mm to 50mm is shown which should appear from 1mm to 60mm. Now I want to show as many objects as I enter in the textbox
private void viewPort3d_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ClickCount == 2 && e.ChangedButton == MouseButton.Left) { isLeftButtonDoubleClicked = true; var hitResult = VisualTreeHelper.HitTest(viewPort3d, e.GetPosition(viewPort3d)); if (hitResult != null && hitResult.VisualHit is ModelVisual3D visual3D) { // Store the original material of the newly selected object var group2 = selectedModel.Content as Model3DGroup; if (group2 != null && group2.Children.Count > 0) { var model = group2.Children[0] as GeometryModel3D; { STL.UpdateMaterial = model.Material; var bounds = model.Bounds; double width = bounds.SizeX * 1000;// convert to millimeters double height = bounds.SizeY * 1000;// convert to millimeters double depth = bounds.SizeZ * 1000; // convert to millimeters var z = depth/1000.0; // Get the value entered in the depthTextBox double hideDepth = 0.0; double.TryParse(depthTextBox.Text, out hideDepth); // Calculate the percentage of the object that should be hidden double hidePercent = Math.Min(hideDepth, z) / z; // Update the mesh geometry to hide the appropriate part of the object var meshGeometry = model.Geometry as MeshGeometry3D; if (meshGeometry != null) { var newMeshGeometry = new MeshGeometry3D(); for (int i = 0; i < meshGeometry.TriangleIndices.Count; i += 3) { Point3D p1 = meshGeometry.Positions[meshGeometry.TriangleIndices[i]]; Point3D p2 = meshGeometry.Positions[meshGeometry.TriangleIndices[i + 1]]; Point3D p3 = meshGeometry.Positions[meshGeometry.TriangleIndices[i + 2]]; double minZ = Math.Min(Math.Min(p1.Z, p2.Z), p3.Z); double maxZ = Math.Max(Math.Max(p1.Z, p2.Z), p3.Z); if (maxZ < bounds.SizeZ * hidePercent) { newMeshGeometry.Positions.Add(p1); newMeshGeometry.Positions.Add(p2); newMeshGeometry.Positions.Add(p3); newMeshGeometry.TriangleIndices.Add(newMeshGeometry.Positions.Count - 3); newMeshGeometry.TriangleIndices.Add(newMeshGeometry.Positions.Count - 2); newMeshGeometry.TriangleIndices.Add(newMeshGeometry.Positions.Count - 1); } } model.Geometry = newMeshGeometry; viewPort3d.InvalidateVisual(); } } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)