Changeset 13558
- Timestamp:
- 01/20/16 13:08:13 (9 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlans/PackingPlan3DView.Designer.cs
r13532 r13558 82 82 this.elementHost.Size = new System.Drawing.Size(229, 290); 83 83 this.elementHost.TabIndex = 6; 84 this.elementHost.Text = "elementHost 1";84 this.elementHost.Text = "elementHost"; 85 85 this.elementHost.Child = this.packingPlan3D; 86 86 // -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlans/PackingPlan3DView.cs
r13532 r13558 37 37 } 38 38 39 40 protected override void DeregisterContentEvents() {41 base.DeregisterContentEvents();42 }43 protected override void RegisterContentEvents() {44 base.RegisterContentEvents();45 }46 47 39 public new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Content { 48 40 get { return (PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>)base.Content; } … … 55 47 binSelection.Items.Clear(); 56 48 if (Content == null) { 57 packingPlan3D.Clear();49 packingPlan3D.Packing = null; 58 50 } else { 59 51 int i = 0; … … 62 54 63 55 binSelection.SelectedIndex = 0; 64 UpdateModel(); 65 packingPlan3D.Focus(); // for mouse wheel? 66 // packingPlan3D.StartRendering(); 56 ShowSelectedPacking(); 67 57 } 68 58 } 69 59 70 private void UpdateModel() {60 private void ShowSelectedPacking() { 71 61 int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0; 72 packingPlan3D.ShowContainer(Content.BinPackings[currentBin]); 73 // var bin = Content.BinPackings[currentBin].BinMeasures; 74 // // packingPlan3D.InitializeContainer(bin.Width, bin.Height, bin.Depth); 75 // foreach (var entry in Content.BinPackings[currentBin].ItemMeasures) { 76 // var position = Content.BinPackings[currentBin].ItemPositions[entry.Key]; 77 // packingPlan3D.AddItemToContainer( 78 // position.Rotated ? entry.Value.Depth : entry.Value.Width, 79 // entry.Value.Height, 80 // position.Rotated ? entry.Value.Width : entry.Value.Depth, 81 // position.X, position.Y, position.Z, entry.Key, entry.Value.Material); 82 // } 62 packingPlan3D.Packing = Content.BinPackings[currentBin]; 83 63 } 84 64 85 65 private void binSelection_SelectedIndexChanged(object sender, EventArgs e) { 86 UpdateModel();87 88 66 itemSelection.SelectedIndex = -1; 89 67 itemSelection.Items.Clear(); 68 69 // add items of this container 90 70 int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0; 91 packingPlan3D.ShowContainer(Content.BinPackings[currentBin]); 71 var packing = Content.BinPackings[currentBin]; 72 foreach (var item in packing.ItemMeasures) { 73 itemSelection.Items.Add(item.Key); 74 } 92 75 76 ShowSelectedPacking(); 93 77 } 94 78 95 79 private void itemSelection_SelectedIndexChanged(object sender, EventArgs e) { 96 UpdateModel();97 98 80 int selectedItem = -1; 99 81 if ((itemSelection != null && itemSelection.SelectedItem != null) && Int32.TryParse(itemSelection.SelectedItem.ToString(), out selectedItem)) { … … 102 84 packingPlan3D.ClearSelection(); 103 85 } 104 105 // private void Content_QualityChanged(object sender, EventArgs e) {106 // if (InvokeRequired)107 // Invoke(new EventHandler(Content_QualityChanged), sender, e);108 // else {109 // binSelection.Items.Clear();110 // if (Content == null) {111 // packingPlan3D.InitializeContainer(0, 0, 0);112 // } else {113 // int i = 0;114 // foreach (var bp in Content.BinPackings)115 // binSelection.Items.Add(i++ + " (" + Math.Round(bp.PackingDensity * 100, 2) + "%)");116 // binSelection.SelectedIndex = 0;117 // UpdateModel();118 // // packingPlan3D.StartRendering();119 // }120 // }121 // }122 86 } 123 87 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Shapes/Container3DView.xaml
r13532 r13558 6 6 mc:Ignorable="d" 7 7 d:DesignHeight="300" d:DesignWidth="300" 8 MouseWheel="viewport3D1_MouseWheel" MouseMove="viewport3D1_MouseMove" MouseDown="viewport3D1_MouseDown" MouseUp="viewport3D1_MouseUp" 8 MouseMove="Container3DView_MouseMove" MouseDown="Container3DView_MouseDown" MouseUp="Container3DView_MouseUp" 9 MouseWheel="Container3DView_OnMouseWheel" 10 MouseEnter="Container3DView_OnMouseEnter" 11 Focusable="true" 9 12 > 10 13 <Grid> 11 14 <Viewport3D Name="viewport3D1" > 12 15 <Viewport3D.Camera> 13 <PerspectiveCamera x:Name="camMain" Position="0.5 3 3" LookDirection="0 -1 -1">16 <PerspectiveCamera x:Name="camMain" Position="0.5 5 5" LookDirection="0 -1 -1"> <!-- camera position for design time--> 14 17 </PerspectiveCamera> 15 18 </Viewport3D.Camera> … … 20 23 </ModelVisual3D> 21 24 <ModelVisual3D> 22 <ModelVisual3D.Content>23 <AmbientLight Color="DarkGray"/>24 </ModelVisual3D.Content>25 25 </ModelVisual3D> 26 26 <ModelVisual3D x:Name="MyModel"> 27 27 <ModelVisual3D.Content> 28 <GeometryModel3D> 29 <GeometryModel3D.Geometry> 30 <MeshGeometry3D x:Name="meshMain" 31 Positions="0 0 0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1" 32 TriangleIndices="2 3 1 2 1 0 7 1 3 7 5 1 6 5 7 6 4 5 6 2 0 2 0 4 2 7 3 2 6 7 0 1 5 0 5 4"> 33 </MeshGeometry3D> 34 </GeometryModel3D.Geometry> 35 <GeometryModel3D.Material> 36 <DiffuseMaterial x:Name="matDiffuseMain"> 37 <DiffuseMaterial.Brush> 38 <SolidColorBrush Color="LightGray"/> 39 </DiffuseMaterial.Brush> 40 </DiffuseMaterial> 41 </GeometryModel3D.Material> 42 </GeometryModel3D> 28 <Model3DGroup> 29 <GeometryModel3D> 30 <GeometryModel3D.Geometry> 31 <!-- two opaque cubes, one in front one in back--> 32 <MeshGeometry3D x:Name="meshMain" 33 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 34 0 0 0 1 0 0 0 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 1 1" 35 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 36 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 "> 37 </MeshGeometry3D> 38 </GeometryModel3D.Geometry> 39 <GeometryModel3D.Material> 40 <DiffuseMaterial> 41 <DiffuseMaterial.Brush> 42 <SolidColorBrush Color="LightGreen"/> 43 </DiffuseMaterial.Brush> 44 </DiffuseMaterial> 45 </GeometryModel3D.Material> 46 </GeometryModel3D> 47 <GeometryModel3D> 48 <GeometryModel3D.Geometry> 49 <!-- two transparent cubes, one in front one in back--> 50 <!-- draw transparent cubes from back to front and always draw outer and inner triangles and draw from front to back--> 51 <MeshGeometry3D x:Name="meshInsides" 52 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 53 -1 -1 -3 2 -1 -3 -1 2 -3 2 2 -3 -1 -1 -1 2 -1 -1 -1 2 -1 2 2 -1" 54 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 55 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 56 "> 57 </MeshGeometry3D> 58 </GeometryModel3D.Geometry> 59 <GeometryModel3D.Material> 60 <MaterialGroup> 61 <DiffuseMaterial> 62 <DiffuseMaterial.Brush> 63 <SolidColorBrush Opacity="0.1" Color="DarkGray"/> 64 </DiffuseMaterial.Brush> 65 </DiffuseMaterial> 66 </MaterialGroup> 67 </GeometryModel3D.Material> 68 </GeometryModel3D> 69 <GeometryModel3D> 70 <GeometryModel3D.Geometry> 71 <!-- two transparent cubes, one in front one in back--> 72 <!-- draw transparent cubes from back to front and always draw outer and inner triangles and draw from front to back--> 73 <MeshGeometry3D x:Name="meshTransparent" 74 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 75 -1 -1 -3 2 -1 -3 -1 2 -3 2 2 -3 -1 -1 -1 2 -1 -1 -1 2 -1 2 2 -1" 76 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 77 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 78 "> 79 </MeshGeometry3D> 80 </GeometryModel3D.Geometry> 81 <GeometryModel3D.Material> 82 <MaterialGroup> 83 <DiffuseMaterial> 84 <DiffuseMaterial.Brush> 85 <SolidColorBrush Opacity="0.1" Color="DarkGray"/> 86 </DiffuseMaterial.Brush> 87 </DiffuseMaterial> 88 </MaterialGroup> 89 </GeometryModel3D.Material> 90 </GeometryModel3D> 91 92 </Model3DGroup> 43 93 </ModelVisual3D.Content> 44 94 <ModelVisual3D.Transform> 45 95 <Transform3DGroup> 96 <ScaleTransform3D x:Name="scale" ScaleX="1" ScaleY="1" ScaleZ="1"/> 46 97 <TranslateTransform3D OffsetX="-0.5" OffsetY="-0.5" OffsetZ="-0.5" /> 47 98 <RotateTransform3D> … … 56 107 </RotateTransform3D> 57 108 <TranslateTransform3D OffsetX="0.5" OffsetY="0.5" OffsetZ="0.5" /> 58 <ScaleTransform3D x:Name ="scale" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="1" ScaleY="1" ScaleZ="1"> 59 </ScaleTransform3D> 109 <ScaleTransform3D x:Name="scaleZoom" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="1" ScaleY="1" ScaleZ="1"/> 60 110 </Transform3DGroup> 61 111 </ModelVisual3D.Transform> -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Shapes/Container3DView.xaml.cs
r13532 r13558 6 6 using System.Windows; 7 7 using System.Windows.Controls; 8 using System.Windows.Data;9 using System.Windows.Documents;10 8 using System.Windows.Input; 11 using System.Windows.Media;12 using System.Windows.Media.Imaging;13 9 using System.Windows.Media.Media3D; 14 using System.Windows.Navigation;15 using System.Windows.Shapes;16 10 using HeuristicLab.Encodings.PackingEncoding.PackingPlan; 17 11 using HeuristicLab.Problems.BinPacking.Dimensions; … … 25 19 private double startAngleX; 26 20 private double startAngleY; 27 private int selectedItemIndex; 21 private int selectedItemKey; 22 23 private BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> packing; 24 public BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Packing { 25 get { return packing; } 26 set { 27 if (packing != value) { 28 this.packing = value; 29 ClearSelection(); // also updates visualization 30 } 31 } 32 } 28 33 29 34 public Container3DView() { 30 35 InitializeComponent(); 36 camMain.Position = new Point3D(0.5, 2, 2); // for design time we use a different camera position 31 37 Clear(); 32 38 } 33 39 34 public void Clear() { 40 41 protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo) { 42 base.OnRenderSizeChanged(sizeInfo); 43 var s = Math.Min(sizeInfo.NewSize.Height, sizeInfo.NewSize.Width); 44 var mySize = new Size(s, s); 45 viewport3D1.RenderSize = mySize; 46 } 47 48 public void SelectItem(int itemKey) { 49 // selection of an item should make all other items semi-transparent 50 selectedItemKey = itemKey; 51 UpdateVisualization(); 52 } 53 public void ClearSelection() { 54 // remove all transparency 55 selectedItemKey = -1; 56 UpdateVisualization(); 57 } 58 59 private void UpdateVisualization() { 60 Clear(); 61 if (packing == null) return; // nothing to display 62 63 // draw all items 64 // order by Z position to reduce artifacts (because of transparent objects) 65 // TODO: improve code to reduce artifacts 66 // - from triangle definitions and lighting 67 // - from rotation and Z-ordering 68 69 foreach (var item in packing.ItemMeasures.OrderBy(i => packing.ItemPositions[i.Key].Z)) { 70 var position = packing.ItemPositions[item.Key]; 71 72 var w = position.Rotated ? item.Value.Depth : item.Value.Width; 73 var h = item.Value.Height; 74 var d = position.Rotated ? item.Value.Width : item.Value.Depth; 75 76 // ignore the item.Material 77 78 // if nothing is selected then draw all cubes opaque 79 // otherwise draw only the selected cube opaque and all others transparent 80 if (selectedItemKey < 0 || selectedItemKey == item.Key) { 81 AddCube(meshMain, position.X, position.Y, position.Z, w, h, d); 82 } else { 83 AddCube(meshTransparent, position.X, position.Y, position.Z, w, h, d, addInsideTriangles: true); 84 } 85 } 86 87 var container = packing.BinMeasures; 88 // draw a transparent container 89 AddCube(meshTransparent, container.Origin.X, container.Origin.Y, container.Origin.Z, container.Width, container.Height, container.Depth, addInsideTriangles: true); 90 91 // TODO: support cuboids with different side lengths 92 // apply scaling so that the container fits into the unit cube (necessary for the transformations) 93 scale.ScaleX = 1.0 / (container.Width); 94 scale.ScaleY = 1.0 / (container.Height); 95 scale.ScaleZ = 1.0 / (container.Depth); 96 } 97 98 99 private void Clear() { 100 meshInsides.Positions.Clear(); 101 meshInsides.TriangleIndices.Clear(); 102 35 103 meshMain.Positions.Clear(); 36 104 meshMain.TriangleIndices.Clear(); 105 106 meshTransparent.Positions.Clear(); 107 meshTransparent.TriangleIndices.Clear(); 37 108 38 109 mouseDown = false; 39 110 startAngleX = 0; 40 111 startAngleY = 0; 41 selectedItemIndex = -1; 42 43 AddCube(0, 0, 0, 1, 1, 1); // add an empty cube (TODO: remove) 44 } 45 46 47 public void ShowContainer(BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> packing) { 48 var container = packing.BinMeasures; 49 // TODO: draw transparent container 50 // packingPlan3D.InitializeContainer(bin.Width, bin.Height, bin.Depth); 51 52 foreach (var item in packing.ItemMeasures) { 53 var position = packing.ItemPositions[item.Key]; 54 55 // ignore the item.Key 56 // ignore the item.Material 57 58 AddCube(position.X, position.Y, position.Z, 59 position.Rotated ? item.Value.Depth : item.Value.Width, 60 item.Value.Height, 61 position.Rotated ? item.Value.Width : item.Value.Depth); 62 } 63 } 64 65 public void SelectItem(int itemIndex) { 66 // selection of an item should make all other items semi-transparent 67 selectedItemIndex = itemIndex; 68 } 69 public void ClearSelection() { 70 // remove all transparency 71 selectedItemIndex = -1; 72 } 73 74 private void viewport3D1_MouseWheel(object sender, MouseWheelEventArgs e) { 75 if (e.Delta > 0) { 76 camMain.Position -= 0.5 * camMain.LookDirection; 77 } else if (e.Delta < 0) { 78 camMain.Position += 0.5 * camMain.LookDirection; 79 } 80 } 81 82 private void viewport3D1_MouseMove(object sender, MouseEventArgs e) { 112 } 113 114 private void Container3DView_MouseMove(object sender, MouseEventArgs e) { 83 115 if (!mouseDown) return; 84 116 var pos = e.GetPosition((IInputElement)this); … … 87 119 } 88 120 89 private void viewport3D1_MouseDown(object sender, MouseButtonEventArgs e) {121 private void Container3DView_MouseDown(object sender, MouseButtonEventArgs e) { 90 122 startAngleX = rotateX.Angle; 91 123 startAngleY = rotateY.Angle; … … 94 126 } 95 127 96 private void viewport3D1_MouseUp(object sender, MouseButtonEventArgs e) {128 private void Container3DView_MouseUp(object sender, MouseButtonEventArgs e) { 97 129 mouseDown = false; 98 130 } 99 131 132 private void Container3DView_OnMouseWheel(object sender, MouseWheelEventArgs e) { 133 if (e.Delta > 0) { 134 scaleZoom.ScaleX *= 1.1; 135 scaleZoom.ScaleY *= 1.1; 136 scaleZoom.ScaleZ *= 1.1; 137 } else if (e.Delta < 0) { 138 scaleZoom.ScaleX /= 1.1; 139 scaleZoom.ScaleY /= 1.1; 140 scaleZoom.ScaleZ /= 1.1; 141 } 142 } 143 100 144 101 145 #region helper for cubes 102 146 103 private void AddCube(int x, int y, int z, int width, int height, int depth) { 104 AddTriangles(AddPoints(x, y, z, width, height, depth)); 105 } 106 107 private void AddTriangles(int[] pointIdx) { 147 private void AddCube(MeshGeometry3D mesh, int x, int y, int z, int width, int height, int depth, bool addInsideTriangles = false) { 148 AddOutsideTriangles(mesh, AddPoints(mesh, x, y, z, width, height, depth)); 149 if (addInsideTriangles) AddInsideTriangles(meshInsides, AddPoints(meshInsides, x, y, z, width, height, depth)); 150 } 151 152 private void AddOutsideTriangles(MeshGeometry3D mesh, int[] pointIdx) { 153 // point indices counter-clockwise 108 154 // back side 109 meshMain.TriangleIndices.Add(pointIdx[0]); 110 meshMain.TriangleIndices.Add(pointIdx[2]); 111 meshMain.TriangleIndices.Add(pointIdx[1]); 112 113 meshMain.TriangleIndices.Add(pointIdx[0]); 114 meshMain.TriangleIndices.Add(pointIdx[3]); 115 meshMain.TriangleIndices.Add(pointIdx[2]); 155 mesh.TriangleIndices.Add(pointIdx[0]); 156 mesh.TriangleIndices.Add(pointIdx[2]); 157 mesh.TriangleIndices.Add(pointIdx[1]); 158 159 mesh.TriangleIndices.Add(pointIdx[0]); 160 mesh.TriangleIndices.Add(pointIdx[3]); 161 mesh.TriangleIndices.Add(pointIdx[2]); 162 163 // bottom side 164 mesh.TriangleIndices.Add(pointIdx[5]); 165 mesh.TriangleIndices.Add(pointIdx[4]); 166 mesh.TriangleIndices.Add(pointIdx[0]); 167 168 mesh.TriangleIndices.Add(pointIdx[5]); 169 mesh.TriangleIndices.Add(pointIdx[0]); 170 mesh.TriangleIndices.Add(pointIdx[1]); 116 171 117 172 // right side 118 mesh Main.TriangleIndices.Add(pointIdx[2]);119 mesh Main.TriangleIndices.Add(pointIdx[6]);120 mesh Main.TriangleIndices.Add(pointIdx[5]);121 122 mesh Main.TriangleIndices.Add(pointIdx[1]);123 mesh Main.TriangleIndices.Add(pointIdx[2]);124 mesh Main.TriangleIndices.Add(pointIdx[5]);173 mesh.TriangleIndices.Add(pointIdx[2]); 174 mesh.TriangleIndices.Add(pointIdx[6]); 175 mesh.TriangleIndices.Add(pointIdx[5]); 176 177 mesh.TriangleIndices.Add(pointIdx[1]); 178 mesh.TriangleIndices.Add(pointIdx[2]); 179 mesh.TriangleIndices.Add(pointIdx[5]); 125 180 126 181 // left side 127 meshMain.TriangleIndices.Add(pointIdx[7]); 128 meshMain.TriangleIndices.Add(pointIdx[3]); 129 meshMain.TriangleIndices.Add(pointIdx[4]); 130 131 meshMain.TriangleIndices.Add(pointIdx[4]); 132 meshMain.TriangleIndices.Add(pointIdx[3]); 133 meshMain.TriangleIndices.Add(pointIdx[0]); 182 mesh.TriangleIndices.Add(pointIdx[7]); 183 mesh.TriangleIndices.Add(pointIdx[3]); 184 mesh.TriangleIndices.Add(pointIdx[4]); 185 186 mesh.TriangleIndices.Add(pointIdx[4]); 187 mesh.TriangleIndices.Add(pointIdx[3]); 188 mesh.TriangleIndices.Add(pointIdx[0]); 189 190 // top side 191 mesh.TriangleIndices.Add(pointIdx[3]); 192 mesh.TriangleIndices.Add(pointIdx[7]); 193 mesh.TriangleIndices.Add(pointIdx[6]); 194 195 mesh.TriangleIndices.Add(pointIdx[3]); 196 mesh.TriangleIndices.Add(pointIdx[6]); 197 mesh.TriangleIndices.Add(pointIdx[2]); 134 198 135 199 // front side 136 meshMain.TriangleIndices.Add(pointIdx[6]); 137 meshMain.TriangleIndices.Add(pointIdx[7]); 138 meshMain.TriangleIndices.Add(pointIdx[4]); 139 140 meshMain.TriangleIndices.Add(pointIdx[6]); 141 meshMain.TriangleIndices.Add(pointIdx[4]); 142 meshMain.TriangleIndices.Add(pointIdx[5]); 200 mesh.TriangleIndices.Add(pointIdx[6]); 201 mesh.TriangleIndices.Add(pointIdx[7]); 202 mesh.TriangleIndices.Add(pointIdx[4]); 203 204 mesh.TriangleIndices.Add(pointIdx[6]); 205 mesh.TriangleIndices.Add(pointIdx[4]); 206 mesh.TriangleIndices.Add(pointIdx[5]); 207 } 208 209 private void AddInsideTriangles(MeshGeometry3D mesh, int[] pointIdx) { 210 // for each cube we also draw the triangles facing inside because they are visible when a cube is transparent 211 // point indices clockwise 212 213 // back side 214 mesh.TriangleIndices.Add(pointIdx[1]); 215 mesh.TriangleIndices.Add(pointIdx[2]); 216 mesh.TriangleIndices.Add(pointIdx[0]); 217 218 mesh.TriangleIndices.Add(pointIdx[2]); 219 mesh.TriangleIndices.Add(pointIdx[3]); 220 mesh.TriangleIndices.Add(pointIdx[0]); 221 222 // bottom side 223 mesh.TriangleIndices.Add(pointIdx[0]); 224 mesh.TriangleIndices.Add(pointIdx[4]); 225 mesh.TriangleIndices.Add(pointIdx[5]); 226 227 mesh.TriangleIndices.Add(pointIdx[1]); 228 mesh.TriangleIndices.Add(pointIdx[0]); 229 mesh.TriangleIndices.Add(pointIdx[5]); 230 231 // right side 232 mesh.TriangleIndices.Add(pointIdx[5]); 233 mesh.TriangleIndices.Add(pointIdx[6]); 234 mesh.TriangleIndices.Add(pointIdx[2]); 235 236 mesh.TriangleIndices.Add(pointIdx[5]); 237 mesh.TriangleIndices.Add(pointIdx[2]); 238 mesh.TriangleIndices.Add(pointIdx[1]); 239 240 // left side 241 mesh.TriangleIndices.Add(pointIdx[4]); 242 mesh.TriangleIndices.Add(pointIdx[3]); 243 mesh.TriangleIndices.Add(pointIdx[7]); 244 245 mesh.TriangleIndices.Add(pointIdx[0]); 246 mesh.TriangleIndices.Add(pointIdx[3]); 247 mesh.TriangleIndices.Add(pointIdx[4]); 143 248 144 249 // top side 145 meshMain.TriangleIndices.Add(pointIdx[3]); 146 meshMain.TriangleIndices.Add(pointIdx[7]); 147 meshMain.TriangleIndices.Add(pointIdx[6]); 148 149 meshMain.TriangleIndices.Add(pointIdx[3]); 150 meshMain.TriangleIndices.Add(pointIdx[6]); 151 meshMain.TriangleIndices.Add(pointIdx[2]); 152 153 // bottom side 154 meshMain.TriangleIndices.Add(pointIdx[5]); 155 meshMain.TriangleIndices.Add(pointIdx[4]); 156 meshMain.TriangleIndices.Add(pointIdx[0]); 157 158 meshMain.TriangleIndices.Add(pointIdx[5]); 159 meshMain.TriangleIndices.Add(pointIdx[0]); 160 meshMain.TriangleIndices.Add(pointIdx[1]); 161 162 163 } 164 165 private int[] AddPoints(int x, int y, int z, int w, int h, int d) { 250 mesh.TriangleIndices.Add(pointIdx[6]); 251 mesh.TriangleIndices.Add(pointIdx[7]); 252 mesh.TriangleIndices.Add(pointIdx[3]); 253 254 mesh.TriangleIndices.Add(pointIdx[2]); 255 mesh.TriangleIndices.Add(pointIdx[6]); 256 mesh.TriangleIndices.Add(pointIdx[3]); 257 258 // front side 259 mesh.TriangleIndices.Add(pointIdx[4]); 260 mesh.TriangleIndices.Add(pointIdx[7]); 261 mesh.TriangleIndices.Add(pointIdx[6]); 262 263 mesh.TriangleIndices.Add(pointIdx[5]); 264 mesh.TriangleIndices.Add(pointIdx[4]); 265 mesh.TriangleIndices.Add(pointIdx[6]); 266 } 267 268 private int[] AddPoints(MeshGeometry3D mesh, int x, int y, int z, int w, int h, int d) { 166 269 // ground 167 mesh Main.Positions.Add(new Point3D(x, y, z));168 mesh Main.Positions.Add(new Point3D(x + w, y, z));169 mesh Main.Positions.Add(new Point3D(x + w, y + h, z));170 mesh Main.Positions.Add(new Point3D(x, y + h, z));270 mesh.Positions.Add(new Point3D(x, y, z)); 271 mesh.Positions.Add(new Point3D(x + w, y, z)); 272 mesh.Positions.Add(new Point3D(x + w, y + h, z)); 273 mesh.Positions.Add(new Point3D(x, y + h, z)); 171 274 // top 172 mesh Main.Positions.Add(new Point3D(x, y, z + d));173 mesh Main.Positions.Add(new Point3D(x + w, y, z + d));174 mesh Main.Positions.Add(new Point3D(x + w, y + h, z + d));175 mesh Main.Positions.Add(new Point3D(x, y + h, z + d));176 177 return Enumerable.Range(mesh Main.Positions.Count - 8, 8).ToArray();275 mesh.Positions.Add(new Point3D(x, y, z + d)); 276 mesh.Positions.Add(new Point3D(x + w, y, z + d)); 277 mesh.Positions.Add(new Point3D(x + w, y + h, z + d)); 278 mesh.Positions.Add(new Point3D(x, y + h, z + d)); 279 280 return Enumerable.Range(mesh.Positions.Count - 8, 8).ToArray(); 178 281 } 179 282 #endregion 283 284 private void Container3DView_OnMouseEnter(object sender, MouseEventArgs e) { 285 Focus(); // for mouse wheel events 286 } 180 287 } 181 288 }
Note: See TracChangeset
for help on using the changeset viewer.