public void ReadA(Stream s) { asciiReader = new StreamReader(s); Meshes.Add(new MeshBuilder(true, true)); Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue)); while (!asciiReader.EndOfStream) { var line = asciiReader.ReadLine().Trim(); if (line.Length == 0 || line.StartsWith("\0") || line.StartsWith("#") || line.StartsWith("!") || line.StartsWith("$")) { continue; } string id, values; SplitLine(line, out id, out values); switch (id) { case "solid": break; case "facet": ReadTriangleA(values); break; case "endsolid": break; } } asciiReader.Close(); }
public void UpdateModel() { CreateGeometry(); var c = new Model3DGroup(); var mat = MaterialHelper.CreateMaterial(Fill); double l = HeadLength * Diameter; for (int i = 0; i < Positions.Count; i++) { var p = Positions[i]; var d = Directions[i]; var headModel = new GeometryModel3D { Geometry = _head, Material = mat, Transform = CreateHeadTransform(p + d, d) }; c.Children.Add(headModel); var u = d; u.Normalize(); var bodyModel = new GeometryModel3D { Geometry = _body, Material = mat, Transform = CreateBodyTransform(p, u * (1.0 - l / d.Length)) }; c.Children.Add(bodyModel); } _element.Content = c; }
private static void FillChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var el = (MeshElement3D)d; el.Material = MaterialHelper.CreateMaterial(el.Fill); el.BackMaterial = el.Material; }
public override object ProvideValue(System.IServiceProvider serviceProvider) { var diffuse = new SolidColorBrush(color); var specular = BrushHelper.CreateGrayBrush(SpecularIntensity); return(MaterialHelper.CreateMaterial(diffuse, null, specular, Opacity, SpecularPower)); }
protected void MaterialChanged() { if (!_doUpdates) { return; } GeometryModel3D model = Model; if (model == null) { return; } if (Material == null) { // use a default blue material model.Material = MaterialHelper.CreateMaterial(Brushes.Blue); } else { model.Material = Material; } // the back material may be null (invisible) model.BackMaterial = BackMaterial; }
private Material GetMaterial(string materialName) { MaterialDefinition mat; if (Materials.TryGetValue(materialName, out mat)) { return(mat.GetMaterial(TexturePath)); } return(MaterialHelper.CreateMaterial(Brushes.Gold)); }
private void addFace(Vector3D normal, Vector3D up, Brush b, string text) { var grid = new Grid { Width = 20, Height = 20 }; grid.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); Material material = MaterialHelper.CreateMaterial(new ImageBrush(bmp)); double a = Size; var builder = new MeshBuilder(); builder.AddCubeFace(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 += face_MouseLeftButtonDown; //element.MouseEnter += face_MouseEnter; //element.MouseLeave += face_MouseLeave; _normal.Add(element, normal); _up.Add(element, up); Children.Add(element); }
public void UpdateModel() { CreateGeometry(); var c = new Model3DGroup(); Material mat = MaterialHelper.CreateMaterial(Fill); for (int i = 0; i < Positions.Count; i++) { Point3D p0 = Positions[i]; var sphereModel = new GeometryModel3D(); sphereModel.Geometry = _sphere; sphereModel.Material = mat; sphereModel.Transform = new TranslateTransform3D(p0.X, p0.Y, p0.Z); c.Children.Add(sphereModel); } _element.Content = c; }
public override void Calculate(TerrainModel model, MeshGeometry3D mesh) { var normals = MeshGeometryHelper.CalculateNormals(mesh); var texcoords = new PointCollection(); for (int i = 0; i < normals.Count; i++) { double slopedir = Math.Atan2(normals[i].Y, normals[i].X) * 180 / Math.PI; if (slopedir < 0) { slopedir += 360; } double u = slopedir / 360; texcoords.Add(new Point(u, u)); } TextureCoordinates = texcoords; Material = MaterialHelper.CreateMaterial(Brush); }
public void UpdateModel() { CreateGeometry(); var c = new Model3DGroup(); var mat = MaterialHelper.CreateMaterial(Fill); for (int i = 0; i < Segments; i++) { var p0 = Positions[SegmentIndices[i * 2]]; var p1 = Positions[SegmentIndices[i * 2 + 1]]; var d = p1 - p0; var tubeModel = new GeometryModel3D { Geometry = _tube, Material = mat, Transform = CreateSegmentTransform(p0, d) }; c.Children.Add(tubeModel); } _element.Content = c; }
public void ReadB(Stream s) { long length = binaryReader.BaseStream.Length; if (length < 84) { throw new FileFormatException("Incomplete file"); } String header = ReadHeaderB(); UInt32 numberTriangles = ReadNumberTrianglesB(); index = 0; Meshes.Add(new MeshBuilder(true, true)); Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue)); for (int i = 0; i < numberTriangles; i++) { ReadTriangleB(); } binaryReader.Close(); }
public override void Calculate(TerrainModel model, MeshGeometry3D mesh) { var normals = MeshGeometryHelper.CalculateNormals(mesh); var texcoords = new PointCollection(); var up = new Vector3D(0, 0, 1); for (int i = 0; i < normals.Count; i++) { double slope = Math.Acos(Vector3D.DotProduct(normals[i], up)) * 180 / Math.PI; double u = slope / 40; if (u > 1) { u = 1; } if (u < 0) { u = 0; } texcoords.Add(new Point(u, u)); } TextureCoordinates = texcoords; Material = MaterialHelper.CreateMaterial(Brush); }
private void ReadTriangleA(String normal) { Vector3D n = ParseNormalA(normal); ReadLineA("outer"); Point3D v1 = ReadVertexA(); Point3D v2 = ReadVertexA(); Point3D v3 = ReadVertexA(); ReadLineA("endloop"); ReadLineA("endfacet"); if (Materials.Count < index + 1) { Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue)); } if (Meshes.Count < index + 1) { Meshes.Add(new MeshBuilder(true, true)); } Meshes[index].AddTriangle(v1, v2, v3); }
private void ReadSurface(int size) { Surfaces = new Collection <string>(); Meshes = new Collection <MeshBuilder>(); Materials = new Collection <Material>(); string name = ReadString(size); var names = name.Split('\0'); for (int i = 0; i < names.Length; i++) { string n = names[i]; Surfaces.Add(n); Meshes.Add(new MeshBuilder()); Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue)); // If the length of the string (including the null) is odd, an extra null byte is added. // Then skip the next empty string. if ((n.Length + 1) % 2 == 1) { i++; } } }
private void ReadTriangleB() { Color current; bool hasColor = false; bool sameColor = true; float ni = ReadFloatB(); float nj = ReadFloatB(); float nk = ReadFloatB(); Vector3D n = new Vector3D(ni, nj, nk); float v1x = ReadFloatB(); float v1y = ReadFloatB(); float v1z = ReadFloatB(); Point3D v1 = new Point3D(v1x, v1y, v1z); float v2x = ReadFloatB(); float v2y = ReadFloatB(); float v2z = ReadFloatB(); Point3D v2 = new Point3D(v2x, v2y, v2z); float v3x = ReadFloatB(); float v3y = ReadFloatB(); float v3z = ReadFloatB(); Point3D v3 = new Point3D(v3x, v3y, v3z); //UInt16 attrib = ReadUInt16(); var attrib = Convert.ToString(ReadUInt16B(), 2).PadLeft(16, '0').ToCharArray(); hasColor = attrib[0].Equals('1'); if (hasColor) { int blue = attrib[15].Equals('1') ? 1 : 0; blue = attrib[14].Equals('1') ? blue + 2 : blue; blue = attrib[13].Equals('1') ? blue + 4 : blue; blue = attrib[12].Equals('1') ? blue + 8 : blue; blue = attrib[11].Equals('1') ? blue + 16 : blue; int b = blue * 8; int green = attrib[10].Equals('1') ? 1 : 0; green = attrib[9].Equals('1') ? green + 2 : green; green = attrib[8].Equals('1') ? green + 4 : green; green = attrib[7].Equals('1') ? green + 8 : green; green = attrib[6].Equals('1') ? green + 16 : green; int g = green * 8; int red = attrib[5].Equals('1') ? 1 : 0; red = attrib[4].Equals('1') ? red + 2 : red; red = attrib[3].Equals('1') ? red + 4 : red; red = attrib[2].Equals('1') ? red + 8 : red; red = attrib[1].Equals('1') ? red + 16 : red; int r = red * 8; current = Color.FromRgb(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b)); sameColor = Color.Equals(last, current); if (!sameColor) { last = current; index++; } if (Materials.Count < index + 1) { Materials.Add(MaterialHelper.CreateMaterial(current)); } } else { if (Materials.Count < index + 1) { Materials.Add(MaterialHelper.CreateMaterial(Brushes.Blue)); } } if (Meshes.Count < index + 1) { Meshes.Add(new MeshBuilder(true, true)); } Meshes[index].AddTriangle(v1, v2, v3); }
public Group(string name) { Name = name; Material = MaterialHelper.CreateMaterial(Brushes.Green); MeshBuilder = new MeshBuilder(); }