Changeset 14708
- Timestamp:
- 03/01/17 11:31:41 (8 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.BinPacking.Views/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml
r14162 r14708 30 30 MouseWheel="Container3DView_OnMouseWheel" 31 31 MouseEnter="Container3DView_OnMouseEnter" 32 KeyDown="Container3DView_OnKeyDown" 32 33 Focusable="true" 33 34 > … … 48 49 <ModelVisual3D.Content> 49 50 <Model3DGroup> 50 <GeometryModel3D>51 <GeometryModel3D.Geometry>52 <!-- two opaque cubes, one in front one in back-->53 <MeshGeometry3D x:Name="meshMain"54 Positions="0 0 -2.5 1 0 -2.5 0 1 -2.5 1 1 -2.5 0 0 -1.5 1 0 -1.5 0 1 -1.5 1 1 -1.555 0 0 0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1"56 TriangleIndices="10 11 9 10 9 8 15 9 11 15 13 9 14 13 15 14 12 13 14 10 12 10 8 12 10 15 11 10 14 15 0 9 13 8 13 1257 2 3 1 2 1 0 7 1 3 7 5 1 6 5 7 6 4 5 6 2 4 2 0 4 2 7 3 2 6 7 0 1 5 0 5 4 ">58 </MeshGeometry3D>59 </GeometryModel3D.Geometry>60 <GeometryModel3D.Material>61 <DiffuseMaterial>62 <DiffuseMaterial.Brush>63 <SolidColorBrush Color="LightGreen"/>64 </DiffuseMaterial.Brush>65 </DiffuseMaterial>66 </GeometryModel3D.Material>67 </GeometryModel3D>68 <GeometryModel3D>69 <GeometryModel3D.Geometry>70 <!-- two transparent cubes, one in front one in back-->71 <!-- draw transparent cubes from back to front and always draw outer and inner triangles and draw from front to back-->72 <MeshGeometry3D x:Name="meshInsides"73 Positions="-1 -1 -1 2 -1 -1 -1 2 -1 2 2 -1 -1 -1 2 2 -1 2 -1 2 2 2 2 274 -1 -1 -3 2 -1 -3 -1 2 -3 2 2 -3 -1 -1 -1 2 -1 -1 -1 2 -1 2 2 -1"75 TriangleIndices="9 11 10 8 9 10 11 9 15 9 13 15 15 13 14 13 12 14 12 10 14 12 8 10 11 15 10 15 14 10 13 9 8 12 13 876 1 3 2 0 1 2 3 1 7 1 5 7 7 5 6 5 4 6 4 2 6 4 0 2 3 7 2 7 6 2 5 1 0 4 5 077 ">78 </MeshGeometry3D>79 </GeometryModel3D.Geometry>80 <GeometryModel3D.Material>81 <MaterialGroup>82 <DiffuseMaterial>83 <DiffuseMaterial.Brush>84 <SolidColorBrush Opacity="0.1" Color="DarkGray"/>85 </DiffuseMaterial.Brush>86 </DiffuseMaterial>87 </MaterialGroup>88 </GeometryModel3D.Material>89 </GeometryModel3D>90 <GeometryModel3D>91 <GeometryModel3D.Geometry>92 <!-- two transparent cubes, one in front one in back-->93 <!-- draw transparent cubes from back to front and always draw outer and inner triangles and draw from front to back-->94 <MeshGeometry3D x:Name="meshTransparent"95 Positions="-1 -1 -1 2 -1 -1 -1 2 -1 2 2 -1 -1 -1 2 2 -1 2 -1 2 2 2 2 296 -1 -1 -3 2 -1 -3 -1 2 -3 2 2 -3 -1 -1 -1 2 -1 -1 -1 2 -1 2 2 -1"97 TriangleIndices="2 3 1 2 1 0 7 1 3 7 5 1 6 5 7 6 4 5 6 2 4 2 0 4 2 7 3 2 6 7 0 1 5 0 5 498 10 11 9 10 9 8 15 9 11 15 13 9 14 13 15 14 12 13 14 10 12 10 8 12 10 15 11 10 14 15 0 9 13 8 13 1299 ">100 </MeshGeometry3D>101 </GeometryModel3D.Geometry>102 <GeometryModel3D.Material>103 <MaterialGroup>104 <DiffuseMaterial>105 <DiffuseMaterial.Brush>106 <SolidColorBrush Opacity="0.1" Color="DarkGray"/>107 </DiffuseMaterial.Brush>108 </DiffuseMaterial>109 </MaterialGroup>110 </GeometryModel3D.Material>111 </GeometryModel3D>112 113 51 </Model3DGroup> 114 52 </ModelVisual3D.Content> -
trunk/sources/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs
r14162 r14708 19 19 20 20 using System; 21 using System.Collections.Generic; 21 22 using System.Linq; 22 23 using System.Windows; 23 24 using System.Windows.Controls; 24 25 using System.Windows.Input; 26 using System.Windows.Media; 25 27 using System.Windows.Media.Media3D; 26 28 using HeuristicLab.Problems.BinPacking3D; … … 28 30 namespace HeuristicLab.Problems.BinPacking.Views { 29 31 public partial class Container3DView : UserControl { 32 private static readonly Color[] colors = new[] { 33 Color.FromRgb(0x40, 0x6A, 0xB7), 34 Color.FromRgb(0xB1, 0x6D, 0x01), 35 Color.FromRgb(0x4E, 0x8A, 0x06), 36 Color.FromRgb(0x75, 0x50, 0x7B), 37 Color.FromRgb(0x72, 0x9F, 0xCF), 38 Color.FromRgb(0xA4, 0x00, 0x00), 39 Color.FromRgb(0xAD, 0x7F, 0xA8), 40 Color.FromRgb(0x29, 0x50, 0xCF), 41 Color.FromRgb(0x90, 0xB0, 0x60), 42 Color.FromRgb(0xF5, 0x89, 0x30), 43 Color.FromRgb(0x55, 0x57, 0x53), 44 Color.FromRgb(0xEF, 0x59, 0x59), 45 Color.FromRgb(0xED, 0xD4, 0x30), 46 Color.FromRgb(0x63, 0xC2, 0x16), 47 }; 48 49 private static readonly Color hiddenColor = Color.FromArgb(0x1A, 0xAA, 0xAA, 0xAA); 50 private static readonly Color containerColor = Color.FromArgb(0x7F, 0xAA, 0xAA, 0xAA); 51 30 52 private Point startPos; 31 53 private bool mouseDown = false; 54 private bool ctrlDown = false; 32 55 private double startAngleX; 33 56 private double startAngleY; … … 45 68 } 46 69 70 private Dictionary<int, DiffuseMaterial> materials; 71 47 72 public Container3DView() { 48 73 InitializeComponent(); 49 74 camMain.Position = new Point3D(0.5, 3, 3); // for design time we use a different camera position 75 materials = new Dictionary<int, DiffuseMaterial>(); 50 76 Clear(); 51 77 } … … 74 100 if (packing == null) return; // nothing to display 75 101 76 // draw all items 77 // order by Z position to reduce artifacts (because of transparent objects) 78 // TODO: improve code to reduce artifacts 79 // - from triangle definitions and lighting 80 // - from rotation and Z-ordering 81 82 foreach (var item in packing.Items.OrderBy(i => packing.Positions[i.Key].Z)) { 102 var modelGroup = (Model3DGroup)MyModel.Content; 103 var hiddenMaterial = new DiffuseMaterial(new SolidColorBrush(hiddenColor)); 104 105 foreach (var item in packing.Items) { 83 106 var position = packing.Positions[item.Key]; 84 107 … … 87 110 var d = position.Rotated ? item.Value.Width : item.Value.Depth; 88 111 89 // ignore the item.Material 90 91 // if nothing is selected then draw all cubes opaque 92 // otherwise draw only the selected cube opaque and all others transparent 93 if (selectedItemKey < 0 || selectedItemKey == item.Key) { 94 AddCube(meshMain, position.X, position.Y, position.Z, w, h, d); 95 } else { 96 AddCube(meshTransparent, position.X, position.Y, position.Z, w, h, d, addInsideTriangles: true); 112 var model = new GeometryModel3D { Geometry = new MeshGeometry3D() }; 113 DiffuseMaterial material; 114 if (selectedItemKey >= 0 && selectedItemKey != item.Key) 115 material = hiddenMaterial; 116 else { 117 if (!materials.TryGetValue(item.Value.Material, out material)) { 118 var color = colors[(item.Value.Material - 1) % colors.Length]; 119 material = new DiffuseMaterial { Brush = new SolidColorBrush(color) }; 120 materials[item.Value.Material] = material; 121 } 97 122 } 123 model.Material = material; 124 modelGroup.Children.Add(model); 125 126 AddSolidCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d); 98 127 } 99 128 100 129 var container = packing.BinShape; 101 // draw a transparent container 102 AddCube(meshTransparent, container.Origin.X, container.Origin.Y, container.Origin.Z, container.Width, container.Height, container.Depth, addInsideTriangles: true); 103 104 // TODO: support cuboids with different side lengths 105 // apply scaling so that the container fits into the unit cube (necessary for the transformations) 106 scale.ScaleX = 1.0 / (container.Width); 107 scale.ScaleY = 1.0 / (container.Height); 108 scale.ScaleZ = 1.0 / (container.Depth); 130 var containerModel = new GeometryModel3D(new MeshGeometry3D(), new DiffuseMaterial(new SolidColorBrush(containerColor))); 131 modelGroup.Children.Add(containerModel); 132 AddWireframeCube((MeshGeometry3D)containerModel.Geometry, container.Origin.X - .5, container.Origin.Y - .5, container.Origin.Z - .5, container.Width + 1, container.Height + 1, container.Depth + 1); 133 134 var ratio = Math.Max(container.Width, Math.Max(container.Height, container.Depth)); 135 scale.ScaleX = 1.0 / ratio; 136 scale.ScaleY = 1.0 / ratio; 137 scale.ScaleZ = 1.0 / ratio; 138 139 scale.CenterX = .5; 140 scale.CenterY = .5; 141 scale.CenterZ = 0; 109 142 } 110 143 111 144 112 145 private void Clear() { 113 meshInsides.Positions.Clear(); 114 meshInsides.TriangleIndices.Clear(); 115 116 meshMain.Positions.Clear(); 117 meshMain.TriangleIndices.Clear(); 118 119 meshTransparent.Positions.Clear(); 120 meshTransparent.TriangleIndices.Clear(); 121 146 ((Model3DGroup)MyModel.Content).Children.Clear(); 147 materials.Clear(); 148 122 149 mouseDown = false; 123 150 startAngleX = 0; … … 128 155 if (!mouseDown) return; 129 156 var pos = e.GetPosition((IInputElement)this); 157 130 158 rotateX.Angle = startAngleX + (pos.X - startPos.X) / 4; 131 159 rotateY.Angle = startAngleY + (pos.Y - startPos.Y) / 4; … … 155 183 } 156 184 185 private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) { 186 Focus(); // for mouse wheel events 187 } 188 189 private void Container3DView_OnKeyDown(object sender, KeyEventArgs e) { 190 ctrlDown = e.Key.HasFlag(Key.LeftCtrl) || e.Key.HasFlag(Key.RightCtrl); 191 } 192 157 193 158 194 #region helper for cubes 159 160 private void AddCube(MeshGeometry3D mesh, int x, int y, int z, int width, int height, int depth, bool addInsideTriangles = false) { 161 AddOutsideTriangles(mesh, AddPoints(mesh, x, y, z, width, height, depth)); 162 if (addInsideTriangles) AddInsideTriangles(meshInsides, AddPoints(meshInsides, x, y, z, width, height, depth)); 163 } 164 165 private void AddOutsideTriangles(MeshGeometry3D mesh, int[] pointIdx) { 166 // point indices counter-clockwise 167 // back side 168 mesh.TriangleIndices.Add(pointIdx[0]); 169 mesh.TriangleIndices.Add(pointIdx[2]); 170 mesh.TriangleIndices.Add(pointIdx[1]); 171 172 mesh.TriangleIndices.Add(pointIdx[0]); 173 mesh.TriangleIndices.Add(pointIdx[3]); 174 mesh.TriangleIndices.Add(pointIdx[2]); 175 176 // bottom side 177 mesh.TriangleIndices.Add(pointIdx[5]); 178 mesh.TriangleIndices.Add(pointIdx[4]); 179 mesh.TriangleIndices.Add(pointIdx[0]); 180 181 mesh.TriangleIndices.Add(pointIdx[5]); 182 mesh.TriangleIndices.Add(pointIdx[0]); 183 mesh.TriangleIndices.Add(pointIdx[1]); 184 185 // right side 186 mesh.TriangleIndices.Add(pointIdx[2]); 187 mesh.TriangleIndices.Add(pointIdx[6]); 188 mesh.TriangleIndices.Add(pointIdx[5]); 189 190 mesh.TriangleIndices.Add(pointIdx[1]); 191 mesh.TriangleIndices.Add(pointIdx[2]); 192 mesh.TriangleIndices.Add(pointIdx[5]); 193 194 // left side 195 mesh.TriangleIndices.Add(pointIdx[7]); 196 mesh.TriangleIndices.Add(pointIdx[3]); 197 mesh.TriangleIndices.Add(pointIdx[4]); 198 199 mesh.TriangleIndices.Add(pointIdx[4]); 200 mesh.TriangleIndices.Add(pointIdx[3]); 201 mesh.TriangleIndices.Add(pointIdx[0]); 202 203 // top side 204 mesh.TriangleIndices.Add(pointIdx[3]); 205 mesh.TriangleIndices.Add(pointIdx[7]); 206 mesh.TriangleIndices.Add(pointIdx[6]); 207 208 mesh.TriangleIndices.Add(pointIdx[3]); 209 mesh.TriangleIndices.Add(pointIdx[6]); 210 mesh.TriangleIndices.Add(pointIdx[2]); 211 212 // front side 213 mesh.TriangleIndices.Add(pointIdx[6]); 214 mesh.TriangleIndices.Add(pointIdx[7]); 215 mesh.TriangleIndices.Add(pointIdx[4]); 216 217 mesh.TriangleIndices.Add(pointIdx[6]); 218 mesh.TriangleIndices.Add(pointIdx[4]); 219 mesh.TriangleIndices.Add(pointIdx[5]); 220 } 221 222 private void AddInsideTriangles(MeshGeometry3D mesh, int[] pointIdx) { 223 // for each cube we also draw the triangles facing inside because they are visible when a cube is transparent 224 // point indices clockwise 225 226 // back side 227 mesh.TriangleIndices.Add(pointIdx[1]); 228 mesh.TriangleIndices.Add(pointIdx[2]); 229 mesh.TriangleIndices.Add(pointIdx[0]); 230 231 mesh.TriangleIndices.Add(pointIdx[2]); 232 mesh.TriangleIndices.Add(pointIdx[3]); 233 mesh.TriangleIndices.Add(pointIdx[0]); 234 235 // bottom side 236 mesh.TriangleIndices.Add(pointIdx[0]); 237 mesh.TriangleIndices.Add(pointIdx[4]); 238 mesh.TriangleIndices.Add(pointIdx[5]); 239 240 mesh.TriangleIndices.Add(pointIdx[1]); 241 mesh.TriangleIndices.Add(pointIdx[0]); 242 mesh.TriangleIndices.Add(pointIdx[5]); 243 244 // right side 245 mesh.TriangleIndices.Add(pointIdx[5]); 246 mesh.TriangleIndices.Add(pointIdx[6]); 247 mesh.TriangleIndices.Add(pointIdx[2]); 248 249 mesh.TriangleIndices.Add(pointIdx[5]); 250 mesh.TriangleIndices.Add(pointIdx[2]); 251 mesh.TriangleIndices.Add(pointIdx[1]); 252 253 // left side 254 mesh.TriangleIndices.Add(pointIdx[4]); 255 mesh.TriangleIndices.Add(pointIdx[3]); 256 mesh.TriangleIndices.Add(pointIdx[7]); 257 258 mesh.TriangleIndices.Add(pointIdx[0]); 259 mesh.TriangleIndices.Add(pointIdx[3]); 260 mesh.TriangleIndices.Add(pointIdx[4]); 261 262 // top side 263 mesh.TriangleIndices.Add(pointIdx[6]); 264 mesh.TriangleIndices.Add(pointIdx[7]); 265 mesh.TriangleIndices.Add(pointIdx[3]); 266 267 mesh.TriangleIndices.Add(pointIdx[2]); 268 mesh.TriangleIndices.Add(pointIdx[6]); 269 mesh.TriangleIndices.Add(pointIdx[3]); 270 271 // front side 272 mesh.TriangleIndices.Add(pointIdx[4]); 273 mesh.TriangleIndices.Add(pointIdx[7]); 274 mesh.TriangleIndices.Add(pointIdx[6]); 275 276 mesh.TriangleIndices.Add(pointIdx[5]); 277 mesh.TriangleIndices.Add(pointIdx[4]); 278 mesh.TriangleIndices.Add(pointIdx[6]); 279 } 280 281 private int[] AddPoints(MeshGeometry3D mesh, int x, int y, int z, int w, int h, int d) { 195 /// <summary> 196 /// Creates a solid cube by adding the respective points and triangles. 197 /// </summary> 198 /// <param name="mesh">The mesh to which points and triangles are added.</param> 199 /// <param name="x">The leftmost point</param> 200 /// <param name="y">The frontmost point</param> 201 /// <param name="z">The lowest point</param> 202 /// <param name="width">The extension to the right</param> 203 /// <param name="height">The extension to the back</param> 204 /// <param name="depth">The extension to the top</param> 205 private void AddSolidCube(MeshGeometry3D mesh, int x, int y, int z, int width, int height, int depth) { 282 206 // ground 283 207 mesh.Positions.Add(new Point3D(x, y, z)); 284 mesh.Positions.Add(new Point3D(x + w , y, z));285 mesh.Positions.Add(new Point3D(x + w , y + h, z));286 mesh.Positions.Add(new Point3D(x, y + h , z));208 mesh.Positions.Add(new Point3D(x + width, y, z)); 209 mesh.Positions.Add(new Point3D(x + width, y + height, z)); 210 mesh.Positions.Add(new Point3D(x, y + height, z)); 287 211 // top 288 mesh.Positions.Add(new Point3D(x, y, z + d)); 289 mesh.Positions.Add(new Point3D(x + w, y, z + d)); 290 mesh.Positions.Add(new Point3D(x + w, y + h, z + d)); 291 mesh.Positions.Add(new Point3D(x, y + h, z + d)); 292 293 return Enumerable.Range(mesh.Positions.Count - 8, 8).ToArray(); 212 mesh.Positions.Add(new Point3D(x, y, z + depth)); 213 mesh.Positions.Add(new Point3D(x + width, y, z + depth)); 214 mesh.Positions.Add(new Point3D(x + width, y + height, z + depth)); 215 mesh.Positions.Add(new Point3D(x, y + height, z + depth)); 216 217 // front 218 AddPlane(mesh, 0, 1, 5, 4); 219 // right side 220 AddPlane(mesh, 1, 2, 6, 5); 221 // back 222 AddPlane(mesh, 3, 7, 6, 2); 223 // left side 224 AddPlane(mesh, 0, 4, 7, 3); 225 // top 226 AddPlane(mesh, 4, 5, 6, 7); 227 // bottom 228 AddPlane(mesh, 0, 3, 2, 1); 229 } 230 231 /// <summary> 232 /// Creates a wireframe cube by adding the respective points and triangles. 233 /// </summary> 234 /// <param name="mesh">The mesh to which points and triangles are added.</param> 235 /// <param name="x">The leftmost point</param> 236 /// <param name="y">The frontmost point</param> 237 /// <param name="z">The lowest point</param> 238 /// <param name="width">The extension to the right</param> 239 /// <param name="height">The extension to the back</param> 240 /// <param name="depth">The extension to the top</param> 241 /// <param name="thickness">The thickness of the frame</param> 242 private void AddWireframeCube(MeshGeometry3D mesh, double x, double y, double z, double width, double height, double depth, double thickness = double.NaN) { 243 // default thickness of the wireframe is 5% of smallest dimension 244 if (double.IsNaN(thickness)) 245 thickness = Math.Min(width, Math.Min(height, depth)) * 0.05; 246 247 // The cube contains of 8 corner, each corner has 4 points: 248 // 1. The corner point 249 // 2. A point on the edge to the right of the corner 250 // 3. A point on the edge atop or below the corner 251 // 4. A point on the edge to the left of the corner 252 253 // Point 0, Front Left Bottom 254 mesh.Positions.Add(new Point3D(x, y, z)); 255 mesh.Positions.Add(new Point3D(x + thickness, y, z)); 256 mesh.Positions.Add(new Point3D(x, y, z + thickness)); 257 mesh.Positions.Add(new Point3D(x, y + thickness, z)); 258 259 // Point 1, Front Right Bottom 260 mesh.Positions.Add(new Point3D(x + width, y, z)); 261 mesh.Positions.Add(new Point3D(x + width, y + thickness, z)); 262 mesh.Positions.Add(new Point3D(x + width, y, z + thickness)); 263 mesh.Positions.Add(new Point3D(x + width - thickness, y, z)); 264 265 // Point 2, Back Right Bottom 266 mesh.Positions.Add(new Point3D(x + width, y + height, z)); 267 mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z)); 268 mesh.Positions.Add(new Point3D(x + width, y + height, z + thickness)); 269 mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z)); 270 271 // Point 3, Back Left Bottom 272 mesh.Positions.Add(new Point3D(x, y + height, z)); 273 mesh.Positions.Add(new Point3D(x, y + height - thickness, z)); 274 mesh.Positions.Add(new Point3D(x, y + height, z + thickness)); 275 mesh.Positions.Add(new Point3D(x + thickness, y + height, z)); 276 277 // Point 4, Front Left Top 278 mesh.Positions.Add(new Point3D(x, y, z + depth)); 279 mesh.Positions.Add(new Point3D(x + thickness, y, z + depth)); 280 mesh.Positions.Add(new Point3D(x, y, z + depth - thickness)); 281 mesh.Positions.Add(new Point3D(x, y + thickness, z + depth)); 282 283 // Point 5, Front Right Top 284 mesh.Positions.Add(new Point3D(x + width, y, z + depth)); 285 mesh.Positions.Add(new Point3D(x + width, y + thickness, z + depth)); 286 mesh.Positions.Add(new Point3D(x + width, y, z + depth - thickness)); 287 mesh.Positions.Add(new Point3D(x + width - thickness, y, z + depth)); 288 289 // Point 6, Back Right Top 290 mesh.Positions.Add(new Point3D(x + width, y + height, z + depth)); 291 mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + depth)); 292 mesh.Positions.Add(new Point3D(x + width, y + height, z + depth - thickness)); 293 mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + depth)); 294 295 // Point 7, Back Left Top 296 mesh.Positions.Add(new Point3D(x, y + height, z + depth)); 297 mesh.Positions.Add(new Point3D(x, y + height - thickness, z + depth)); 298 mesh.Positions.Add(new Point3D(x, y + height, z + depth - thickness)); 299 mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth)); 300 301 AddPlane(mesh, 0, 4, 6, 2); 302 AddPlane(mesh, 0, 3, 5, 4); 303 304 AddPlane(mesh, 4, 8, 10, 6); 305 AddPlane(mesh, 4, 7, 9, 8); 306 307 AddPlane(mesh, 8, 12, 14, 10); 308 AddPlane(mesh, 8, 11, 13, 12); 309 310 AddPlane(mesh, 0, 2, 14, 12); 311 AddPlane(mesh, 0, 12, 15, 1); 312 313 AddPlane(mesh, 0, 1, 17, 16); 314 AddPlane(mesh, 0, 16, 19, 3); 315 316 AddPlane(mesh, 4, 20, 23, 7); 317 AddPlane(mesh, 4, 5, 21, 20); 318 319 AddPlane(mesh, 8, 24, 27, 11); 320 AddPlane(mesh, 8, 9, 25, 24); 321 322 AddPlane(mesh, 12, 28, 31, 15); 323 AddPlane(mesh, 12, 13, 29, 28); 324 325 AddPlane(mesh, 16, 18, 22, 20); 326 AddPlane(mesh, 16, 20, 21, 19); 327 328 AddPlane(mesh, 20, 22, 26, 24); 329 AddPlane(mesh, 20, 24, 25, 23); 330 331 AddPlane(mesh, 24, 28, 29, 27); 332 AddPlane(mesh, 24, 26, 30, 28); 333 334 AddPlane(mesh, 28, 30, 18, 16); 335 AddPlane(mesh, 28, 16, 17, 31); 336 } 337 338 /// <summary> 339 /// Adds a plane by two triangles. The indices of the points have to be given 340 /// in counter-clockwise sequence. 341 /// </summary> 342 /// <param name="mesh">The mesh to add the triangles to</param> 343 /// <param name="a">The index of the first point</param> 344 /// <param name="b">The index of the second point</param> 345 /// <param name="c">The index of the third point</param> 346 /// <param name="d">The index of the fourth point</param> 347 private void AddPlane(MeshGeometry3D mesh, int a, int b, int c, int d) { 348 // two triangles form a plane 349 mesh.TriangleIndices.Add(a); 350 mesh.TriangleIndices.Add(b); 351 mesh.TriangleIndices.Add(d); 352 mesh.TriangleIndices.Add(c); 353 mesh.TriangleIndices.Add(d); 354 mesh.TriangleIndices.Add(b); 294 355 } 295 356 #endregion 296 357 297 private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) {298 Focus(); // for mouse wheel events299 }300 358 } 301 359 }
Note: See TracChangeset
for help on using the changeset viewer.