public AddCubeFace ( System.Windows.Media.Media3D.Point3D center, System.Windows.Media.Media3D.Vector3D normal, System.Windows.Media.Media3D.Vector3D up, double dist, double width, double height ) : void | ||
center | System.Windows.Media.Media3D.Point3D | /// The center of the cube. /// |
normal | System.Windows.Media.Media3D.Vector3D | /// The normal vector for the face. /// |
up | System.Windows.Media.Media3D.Vector3D | /// The up vector for the face. /// |
dist | double | /// The distance from the center of the cube to the face. /// |
width | double | /// The width of the face. /// |
height | double | /// The height of the face. /// |
return | void |
/// <summary> /// Do the tessellation and return the <see cref="MeshGeometry3D"/>. /// </summary> /// <returns>The mesh geometry.</returns> protected override MeshGeometry3D Tessellate() { var b = new MeshBuilder(false, true); b.AddCubeFace( this.Center, new Vector3D(-1, 0, 0), new Vector3D(0, 0, 1), this.SideLength, this.SideLength, this.SideLength); b.AddCubeFace( this.Center, new Vector3D(1, 0, 0), new Vector3D(0, 0, -1), this.SideLength, this.SideLength, this.SideLength); b.AddCubeFace( this.Center, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), this.SideLength, this.SideLength, this.SideLength); b.AddCubeFace( this.Center, new Vector3D(0, 1, 0), new Vector3D(0, 0, -1), this.SideLength, this.SideLength, this.SideLength); b.AddCubeFace( this.Center, new Vector3D(0, 0, 1), new Vector3D(0, -1, 0), this.SideLength, this.SideLength, this.SideLength); b.AddCubeFace( this.Center, new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), this.SideLength, this.SideLength, this.SideLength); return b.ToMesh(); }
/// <summary> /// Adds a cube face. /// </summary> /// <param name="normal"> /// The normal. /// </param> /// <param name="up"> /// The up vector. /// </param> /// <param name="b"> /// The brush. /// </param> /// <param name="text"> /// The text. /// </param> private void AddCubeFace(Vector3D normal, Vector3D up, Brush b, string text) { var grid = new Grid { Width = 20, Height = 20, Background = b }; grid.Children.Add( new TextBlock { Text = text, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center, FontSize = 15, Foreground = Brushes.White }); grid.Arrange(new Rect(new Point(0, 0), new Size(20, 20))); var bmp = new RenderTargetBitmap((int)grid.Width, (int)grid.Height, 96, 96, PixelFormats.Default); bmp.Render(grid); var material = MaterialHelper.CreateMaterial(new ImageBrush(bmp)); double a = this.Size; var builder = new MeshBuilder(false, true); builder.AddCubeFace(this.Center, normal, up, a, a, a); var geometry = builder.ToMesh(); geometry.Freeze(); var model = new GeometryModel3D { Geometry = geometry, Material = material }; var element = new ModelUIElement3D { Model = model }; element.MouseLeftButtonDown += this.FaceMouseLeftButtonDown; this.faceNormals.Add(element, normal); this.faceUpVectors.Add(element, up); this.Children.Add(element); }
/// <summary> /// Do the tesselation and return the <see cref="MeshGeometry3D"/>. /// </summary> /// <returns>The mesh geometry.</returns> protected override MeshGeometry3D Tessellate() { var b = new MeshBuilder(false,true); b.AddCubeFace( this.Center, new Vector3D(-1, 0, 0), new Vector3D(0, 0, 1), this.Length, this.Width, this.Height); b.AddCubeFace( this.Center, new Vector3D(1, 0, 0), new Vector3D(0, 0, -1), this.Length, this.Width, this.Height); b.AddCubeFace( this.Center, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), this.Width, this.Length, this.Height); b.AddCubeFace( this.Center, new Vector3D(0, 1, 0), new Vector3D(0, 0, -1), this.Width, this.Length, this.Height); if (this.TopFace) { b.AddCubeFace( this.Center, new Vector3D(0, 0, 1), new Vector3D(0, -1, 0), this.Height, this.Length, this.Width); } if (this.BottomFace) { b.AddCubeFace( this.Center, new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), this.Height, this.Length, this.Width); } return b.ToMesh(); }
private static GeometryModel3D CreateFace(int face, Point3D center, double width, double length, double height, Brush brush) { var m = new GeometryModel3D(); var b = new MeshBuilder(false,true); switch (face) { case 0: b.AddCubeFace(center, new Vector3D(-1, 0, 0), new Vector3D(0, 0, 1), length, width, height); break; case 1: b.AddCubeFace(center, new Vector3D(1, 0, 0), new Vector3D(0, 0, -1), length, width, height); break; case 2: b.AddCubeFace(center, new Vector3D(0, -1, 0), new Vector3D(0, 0, 1), width, length, height); break; case 3: b.AddCubeFace(center, new Vector3D(0, 1, 0), new Vector3D(0, 0, -1), width, length, height); break; case 4: b.AddCubeFace(center, new Vector3D(0, 0, -1), new Vector3D(0, 1, 0), height, length, width); break; case 5: b.AddCubeFace(center, new Vector3D(0, 0, 1), new Vector3D(0, -1, 0), height, length, width); break; } m.Geometry = b.ToMesh(); m.Material = MaterialHelper.CreateMaterial(brush); return m; }
/// <summary> /// Add a rectangle geometry object centred at (0,0,0). /// </summary> /// <param name="shapeName">The 3DView object.</param> /// <param name="width">The width of the rectangle.</param> /// <param name="height">The height of the rectangle.</param> /// <param name="colour">A colour or gradient brush for the object.</param> /// <param name="materialType">A material for the object. /// The available options are: /// "E" Emmissive - constant brightness. /// "D" Diffusive - affected by lights. /// "S" Specular - specular highlights. /// </param> /// <returns>The 3DView Geometry name.</returns> public static Primitive AddRectangle(Primitive shapeName, Primitive width, Primitive height, Primitive colour, Primitive materialType) { UIElement obj; try { if (_objectsMap.TryGetValue((string)shapeName, out obj)) { InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate { try { if (obj.GetType() == typeof(Viewport3D)) { Viewport3D viewport3D = (Viewport3D)obj; ProjectionCamera camera = (ProjectionCamera)viewport3D.Camera; MeshBuilder builder = new MeshBuilder(true, true); builder.AddCubeFace(new Point3D(0, 0, 0), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0), 0, width, height); MeshGeometry3D mesh = builder.ToMesh(); return AddGeometry(viewport3D, mesh.Positions, mesh.TriangleIndices, mesh.Normals, mesh.TextureCoordinates, colour, materialType); } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return ""; }); return FastThread.InvokeWithReturn(ret).ToString(); } else { Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName); } } catch (Exception ex) { Utilities.OnError(Utilities.GetCurrentMethod(), ex); } return ""; }