/// <summary> /// Reads a triangle from a binary STL file. /// </summary> /// <param name="reader"> /// The reader. /// </param> private void ReadTriangle(BinaryReader reader) { float ni = ReadFloat(reader); float nj = ReadFloat(reader); float nk = ReadFloat(reader); #pragma warning disable 168 var n = new Vector3D(ni, nj, nk); #pragma warning restore 168 float x1 = ReadFloat(reader); float y1 = ReadFloat(reader); float z1 = ReadFloat(reader); var v1 = new Point3D(x1, y1, z1); float x2 = ReadFloat(reader); float y2 = ReadFloat(reader); float z2 = ReadFloat(reader); var v2 = new Point3D(x2, y2, z2); float x3 = ReadFloat(reader); float y3 = ReadFloat(reader); float z3 = ReadFloat(reader); var v3 = new Point3D(x3, y3, z3); var attrib = Convert.ToString(ReadUInt16(reader), 2).PadLeft(16, '0').ToCharArray(); var 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; #if !NETFX_CORE var currentColor = Color.FromRgb(Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b)); #else var currentColor = new Color(r / 255f, g / 255f, b / 255f); #endif if (!Color.Equals(this.lastColor, currentColor)) { this.lastColor = currentColor; this.index++; } if (this.Materials.Count < this.index + 1) { this.Materials.Add(new PhongMaterialCore() { DiffuseColor = currentColor.ToColor4() }); } } else { if (this.Materials.Count < this.index + 1) { this.Materials.Add(this.DefaultMaterial); } } if (this.Meshes.Count < this.index + 1) { this.Meshes.Add(new MeshBuilder(true, true)); } this.Meshes[this.index].AddTriangle(v1, v2, v3); // todo: add normal }
public bool Equals(Color c) { return(_color.Equals((System.Windows.Media.Color)c)); }