Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/17 07:56:01 (7 years ago)
Author:
gkronber
Message:

#2650: merged r14597:14737 from trunk to branch

Location:
branches/symbreg-factors-2650
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/symbreg-factors-2650

  • branches/symbreg-factors-2650/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml

    r14162 r14751  
    3030             MouseWheel="Container3DView_OnMouseWheel"
    3131             MouseEnter="Container3DView_OnMouseEnter"
     32             KeyDown="Container3DView_OnKeyDown"
    3233             Focusable="true"
    3334             >
     
    4849                <ModelVisual3D.Content>
    4950                    <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.5
    55                                            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 12
    57                                                  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 2
    74                                            -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 8
    76                                                  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 0
    77                                                  ">
    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 2
    96                                            -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 4                                                 
    98                                                  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 12
    99                                                  ">
    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 
    11351                    </Model3DGroup>
    11452                </ModelVisual3D.Content>
  • branches/symbreg-factors-2650/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs

    r14162 r14751  
    1919
    2020using System;
     21using System.Collections.Generic;
    2122using System.Linq;
    2223using System.Windows;
    2324using System.Windows.Controls;
    2425using System.Windows.Input;
     26using System.Windows.Media;
    2527using System.Windows.Media.Media3D;
    2628using HeuristicLab.Problems.BinPacking3D;
     
    2830namespace HeuristicLab.Problems.BinPacking.Views {
    2931  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
    3052    private Point startPos;
    3153    private bool mouseDown = false;
     54    private bool ctrlDown = false;
    3255    private double startAngleX;
    3356    private double startAngleY;
     
    4568    }
    4669
     70    private Dictionary<int, DiffuseMaterial> materials;
     71
    4772    public Container3DView() {
    4873      InitializeComponent();
    4974      camMain.Position = new Point3D(0.5, 3, 3); // for design time we use a different camera position
     75      materials = new Dictionary<int, DiffuseMaterial>();
    5076      Clear();
    5177    }
     
    74100      if (packing == null) return; // nothing to display
    75101
    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) {
    83106        var position = packing.Positions[item.Key];
    84107
     
    87110        var d = position.Rotated ? item.Value.Width : item.Value.Depth;
    88111
    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 colorIdx = item.Value.Material;
     119            while (colorIdx < 0) colorIdx += colors.Length;
     120            colorIdx = colorIdx % colors.Length;
     121            var color = colors[colorIdx];
     122            material = new DiffuseMaterial { Brush = new SolidColorBrush(color) };
     123            materials[item.Value.Material] = material;
     124          }
    97125        }
     126        model.Material = material;
     127        modelGroup.Children.Add(model);
     128
     129        AddSolidCube((MeshGeometry3D)model.Geometry, position.X, position.Y, position.Z, w, h, d);
    98130      }
    99131
    100132      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);
     133      var containerModel = new GeometryModel3D(new MeshGeometry3D(), new DiffuseMaterial(new SolidColorBrush(containerColor)));
     134      modelGroup.Children.Add(containerModel);
     135      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);
     136
     137      var ratio = Math.Max(container.Width, Math.Max(container.Height, container.Depth));
     138      scale.ScaleX = 1.0 / ratio;
     139      scale.ScaleY = 1.0 / ratio;
     140      scale.ScaleZ = 1.0 / ratio;
     141
     142      scale.CenterX = .5;
     143      scale.CenterY = .5;
     144      scale.CenterZ = 0;
    109145    }
    110146
    111147
    112148    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 
     149      ((Model3DGroup)MyModel.Content).Children.Clear();
     150      materials.Clear();
     151     
    122152      mouseDown = false;
    123153      startAngleX = 0;
     
    128158      if (!mouseDown) return;
    129159      var pos = e.GetPosition((IInputElement)this);
     160     
    130161      rotateX.Angle = startAngleX + (pos.X - startPos.X) / 4;
    131162      rotateY.Angle = startAngleY + (pos.Y - startPos.Y) / 4;
     
    155186    }
    156187
     188    private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) {
     189      Focus(); // for mouse wheel events
     190    }
     191
     192    private void Container3DView_OnKeyDown(object sender, KeyEventArgs e) {
     193      ctrlDown = e.Key.HasFlag(Key.LeftCtrl) || e.Key.HasFlag(Key.RightCtrl);
     194    }
     195
    157196
    158197    #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) {
     198    /// <summary>
     199    /// Creates a solid cube by adding the respective points and triangles.
     200    /// </summary>
     201    /// <param name="mesh">The mesh to which points and triangles are added.</param>
     202    /// <param name="x">The leftmost point</param>
     203    /// <param name="y">The frontmost point</param>
     204    /// <param name="z">The lowest point</param>
     205    /// <param name="width">The extension to the right</param>
     206    /// <param name="height">The extension to the back</param>
     207    /// <param name="depth">The extension to the top</param>
     208    private void AddSolidCube(MeshGeometry3D mesh, int x, int y, int z, int width, int height, int depth) {
    282209      // ground
    283210      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));
     211      mesh.Positions.Add(new Point3D(x + width, y, z));
     212      mesh.Positions.Add(new Point3D(x + width, y + height, z));
     213      mesh.Positions.Add(new Point3D(x, y + height, z));
    287214      // 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();
     215      mesh.Positions.Add(new Point3D(x, y, z + depth));
     216      mesh.Positions.Add(new Point3D(x + width, y, z + depth));
     217      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth));
     218      mesh.Positions.Add(new Point3D(x, y + height, z + depth));
     219
     220      // front
     221      AddPlane(mesh, 0, 1, 5, 4);
     222      // right side
     223      AddPlane(mesh, 1, 2, 6, 5);
     224      // back
     225      AddPlane(mesh, 3, 7, 6, 2);
     226      // left side
     227      AddPlane(mesh, 0, 4, 7, 3);
     228      // top
     229      AddPlane(mesh, 4, 5, 6, 7);
     230      // bottom
     231      AddPlane(mesh, 0, 3, 2, 1);
     232    }
     233
     234    /// <summary>
     235    /// Creates a wireframe cube by adding the respective points and triangles.
     236    /// </summary>
     237    /// <param name="mesh">The mesh to which points and triangles are added.</param>
     238    /// <param name="x">The leftmost point</param>
     239    /// <param name="y">The frontmost point</param>
     240    /// <param name="z">The lowest point</param>
     241    /// <param name="width">The extension to the right</param>
     242    /// <param name="height">The extension to the back</param>
     243    /// <param name="depth">The extension to the top</param>
     244    /// <param name="thickness">The thickness of the frame</param>
     245    private void AddWireframeCube(MeshGeometry3D mesh, double x, double y, double z, double width, double height, double depth, double thickness = double.NaN) {
     246      // default thickness of the wireframe is 5% of smallest dimension
     247      if (double.IsNaN(thickness))
     248        thickness = Math.Min(width, Math.Min(height, depth)) * 0.05;
     249
     250      // The cube contains of 8 corner, each corner has 4 points:
     251      // 1. The corner point
     252      // 2. A point on the edge to the right of the corner
     253      // 3. A point on the edge atop or below the corner
     254      // 4. A point on the edge to the left of the corner
     255
     256      // Point 0, Front Left Bottom
     257      mesh.Positions.Add(new Point3D(x, y, z));
     258      mesh.Positions.Add(new Point3D(x + thickness, y, z));
     259      mesh.Positions.Add(new Point3D(x, y, z + thickness));
     260      mesh.Positions.Add(new Point3D(x, y + thickness, z));
     261
     262      // Point 1, Front Right Bottom
     263      mesh.Positions.Add(new Point3D(x + width, y, z));
     264      mesh.Positions.Add(new Point3D(x + width, y + thickness, z));
     265      mesh.Positions.Add(new Point3D(x + width, y, z + thickness));
     266      mesh.Positions.Add(new Point3D(x + width - thickness, y, z));
     267
     268      // Point 2, Back Right Bottom
     269      mesh.Positions.Add(new Point3D(x + width, y + height, z));
     270      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z));
     271      mesh.Positions.Add(new Point3D(x + width, y + height, z + thickness));
     272      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z));
     273
     274      // Point 3, Back Left Bottom
     275      mesh.Positions.Add(new Point3D(x, y + height, z));
     276      mesh.Positions.Add(new Point3D(x, y + height - thickness, z));
     277      mesh.Positions.Add(new Point3D(x, y + height, z + thickness));
     278      mesh.Positions.Add(new Point3D(x + thickness, y + height, z));
     279
     280      // Point 4, Front Left Top
     281      mesh.Positions.Add(new Point3D(x, y, z + depth));
     282      mesh.Positions.Add(new Point3D(x + thickness, y, z + depth));
     283      mesh.Positions.Add(new Point3D(x, y, z + depth - thickness));
     284      mesh.Positions.Add(new Point3D(x, y + thickness, z + depth));
     285
     286      // Point 5, Front Right Top
     287      mesh.Positions.Add(new Point3D(x + width, y, z + depth));
     288      mesh.Positions.Add(new Point3D(x + width, y + thickness, z + depth));
     289      mesh.Positions.Add(new Point3D(x + width, y, z + depth - thickness));
     290      mesh.Positions.Add(new Point3D(x + width - thickness, y, z + depth));
     291
     292      // Point 6, Back Right Top
     293      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth));
     294      mesh.Positions.Add(new Point3D(x + width - thickness, y + height, z + depth));
     295      mesh.Positions.Add(new Point3D(x + width, y + height, z + depth - thickness));
     296      mesh.Positions.Add(new Point3D(x + width, y + height - thickness, z + depth));
     297
     298      // Point 7, Back Left Top
     299      mesh.Positions.Add(new Point3D(x, y + height, z + depth));
     300      mesh.Positions.Add(new Point3D(x, y + height - thickness, z + depth));
     301      mesh.Positions.Add(new Point3D(x, y + height, z + depth - thickness));
     302      mesh.Positions.Add(new Point3D(x + thickness, y + height, z + depth));
     303
     304      AddPlane(mesh, 0, 4, 6, 2);
     305      AddPlane(mesh, 0, 3, 5, 4);
     306
     307      AddPlane(mesh, 4, 8, 10, 6);
     308      AddPlane(mesh, 4, 7, 9, 8);
     309
     310      AddPlane(mesh, 8, 12, 14, 10);
     311      AddPlane(mesh, 8, 11, 13, 12);
     312
     313      AddPlane(mesh, 0, 2, 14, 12);
     314      AddPlane(mesh, 0, 12, 15, 1);
     315
     316      AddPlane(mesh, 0, 1, 17, 16);
     317      AddPlane(mesh, 0, 16, 19, 3);
     318
     319      AddPlane(mesh, 4, 20, 23, 7);
     320      AddPlane(mesh, 4, 5, 21, 20);
     321
     322      AddPlane(mesh, 8, 24, 27, 11);
     323      AddPlane(mesh, 8, 9, 25, 24);
     324
     325      AddPlane(mesh, 12, 28, 31, 15);
     326      AddPlane(mesh, 12, 13, 29, 28);
     327
     328      AddPlane(mesh, 16, 18, 22, 20);
     329      AddPlane(mesh, 16, 20, 21, 19);
     330
     331      AddPlane(mesh, 20, 22, 26, 24);
     332      AddPlane(mesh, 20, 24, 25, 23);
     333
     334      AddPlane(mesh, 24, 28, 29, 27);
     335      AddPlane(mesh, 24, 26, 30, 28);
     336
     337      AddPlane(mesh, 28, 30, 18, 16);
     338      AddPlane(mesh, 28, 16, 17, 31);
     339    }
     340
     341    /// <summary>
     342    /// Adds a plane by two triangles. The indices of the points have to be given
     343    /// in counter-clockwise sequence.
     344    /// </summary>
     345    /// <param name="mesh">The mesh to add the triangles to</param>
     346    /// <param name="a">The index of the first point</param>
     347    /// <param name="b">The index of the second point</param>
     348    /// <param name="c">The index of the third point</param>
     349    /// <param name="d">The index of the fourth point</param>
     350    private void AddPlane(MeshGeometry3D mesh, int a, int b, int c, int d) {
     351      // two triangles form a plane
     352      mesh.TriangleIndices.Add(a);
     353      mesh.TriangleIndices.Add(b);
     354      mesh.TriangleIndices.Add(d);
     355      mesh.TriangleIndices.Add(c);
     356      mesh.TriangleIndices.Add(d);
     357      mesh.TriangleIndices.Add(b);
    294358    }
    295359    #endregion
    296360
    297     private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) {
    298       Focus(); // for mouse wheel events
    299     }
    300361  }
    301362}
Note: See TracChangeset for help on using the changeset viewer.