[ad_1]
What happens in this code is that the selected object is shown according to the value entered in the textbox and the rest of the object is hidden. Example :- The selected object is 90mm in total. Now if I enter 50 in the textbox, the 1mm to 50mm object is shown and the 51mm to 90mm object is hidden. Now what I want to do is that the object from 51mm to 90mm should be removed.
私が試したこと:
C#
private void viewPort3d_MouseDown(object sender, MouseButtonEventArgs e) { if (e.ClickCount == 2 && e.ChangedButton == MouseButton.Left) { // 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; if (model != null) { 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 double hideDepth = 0.0; var Z = depth / 1000.0; double.TryParse(depthTextBox.Text, out hideDepth); // Calculate the percentage of the object to be hidden double hidePercent = hideDepth / Z; // Iterate through all the mesh triangles and hide those above the hidePercent var meshGeometry = model.Geometry as MeshGeometry3D; if (meshGeometry != null) { 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) { // Hide the triangle by setting its normal to (0,0,-1) meshGeometry.Normals[meshGeometry.TriangleIndices[i]] = new Vector3D(0, 0, -1); meshGeometry.Normals[meshGeometry.TriangleIndices[i + 1]] = new Vector3D(0, 0, -1); meshGeometry.Normals[meshGeometry.TriangleIndices[i + 2]] = new Vector3D(0, 0, -1); } } // Invalidate the visual to refresh the changes model.Geometry = meshGeometry; viewPort3d.InvalidateVisual(); } } } } }
解決策 1
これはあなたが探しているものです: コレクションビューソース | 検索結果 | WPF について知っておくべき 2,000 の事柄[^]
[ad_2]
コメント