public bool ParseMesh(BinaryReader reader) { byte[] submeshHeader = reader.ReadBytes(7); if (!Utility.ByteArrayCompare(submeshHeader, ChunkIdTemplate)) { MessageBox.Show("Expected SUBMESH chunk header, got " + Encoding.ASCII.GetString(submeshHeader)); return(false); } Size = reader.ReadInt32(); StringBuilder builder = new StringBuilder(); byte readen = reader.ReadByte(); while (readen != 0) { builder.Append(Convert.ToChar(readen)); readen = reader.ReadByte(); } Name = builder.ToString(); Application.Current.Dispatcher.BeginInvoke((Action)(() => ((P3DElementView)TreeItem.Header).content.Text = Name)); // ((P3DElementView)TreeItem.Header).content.Text = Name; builder.Clear(); Flags = reader.ReadUInt32(); LocalPos = new P3DVertex(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Length = reader.ReadSingle(); Height = reader.ReadSingle(); Depth = reader.ReadSingle(); for (int i = 0; i < Parent.Parent.TextureChunk.TexNum; i++) { Info.Insert(i, new TextureInfo(this)); Info[i].TextureStart = reader.ReadInt16(); Info[i].NumFlat = reader.ReadInt16(); Info[i].NumFlatMetal = reader.ReadInt16(); Info[i].NumGouraud = reader.ReadInt16(); Info[i].NumGouraudMetal = reader.ReadInt16(); Info[i].NumGouraudMetalEnv = reader.ReadInt16(); Info[i].NumShining = reader.ReadInt16(); } NumVertices = reader.ReadInt16(); if (NumVertices < 1) { MessageBox.Show("Mesh doesn't have vertices"); return(false); } for (int i = 0; i < NumVertices; i++) { Vertices.Insert(i, new P3DVertex(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle())); } NumPolys = reader.ReadInt16(); if (NumPolys < 1) { MessageBox.Show("Mesh doesn't have polygons"); return(false); } for (int i = 0; i < NumPolys; i++) { Polygons.Insert(i, new TexturePolygon()); Polygons[i].P1 = reader.ReadInt16(); Polygons[i].U1 = reader.ReadSingle(); Polygons[i].V1 = reader.ReadSingle(); Polygons[i].P2 = reader.ReadInt16(); Polygons[i].U2 = reader.ReadSingle(); Polygons[i].V2 = reader.ReadSingle(); Polygons[i].P3 = reader.ReadInt16(); Polygons[i].U3 = reader.ReadSingle(); Polygons[i].V3 = reader.ReadSingle(); } for (int i = 0; i < Parent.Parent.TextureChunk.TexNum; i++) { short polyInTex = Info[i].TextureStart; for (int j = 0; j < Info[i].NumFlat; j++) { Polygons[polyInTex + j].Material = P3DMaterial.MAT_FLAT; Polygons[polyInTex + j].Texture = GetTextureList()[i].Name; } polyInTex += Info[i].NumFlat; for (int j = 0; j < Info[i].NumFlatMetal; j++) { Polygons[polyInTex + j].Material = P3DMaterial.MAT_FLAT_METAL; Polygons[polyInTex + j].Texture = GetTextureList()[i].Name; } polyInTex += Info[i].NumFlatMetal; for (int j = 0; j < Info[i].NumGouraud; j++) { Polygons[polyInTex + j].Material = P3DMaterial.MAT_GORAUD; Polygons[polyInTex + j].Texture = GetTextureList()[i].Name; } polyInTex += Info[i].NumGouraud; for (int j = 0; j < Info[i].NumGouraudMetal; j++) { Polygons[polyInTex + j].Material = P3DMaterial.MAT_GORAUD_METAL; Polygons[polyInTex + j].Texture = GetTextureList()[i].Name; } polyInTex += Info[i].NumGouraudMetal; for (int j = 0; j < Info[i].NumGouraudMetalEnv; j++) { Polygons[polyInTex + j].Material = P3DMaterial.MAT_GORAUD_METAL_ENV; Polygons[polyInTex + j].Texture = GetTextureList()[i].Name; } polyInTex += Info[i].NumGouraudMetalEnv; for (int j = 0; j < Info[i].NumShining; j++) { Polygons[polyInTex + j].Material = P3DMaterial.MAT_SHINING; Polygons[polyInTex + j].Texture = GetTextureList()[i].Name; } } return(true); }
private static List <Polygons> AccumulateDownPolygons(ConfigSettings config, List <Polygons> inputPolys, List <Polygons> allPartOutlines) { int numLayers = inputPolys.Count; long nozzleSize = config.ExtrusionWidth_um; long areaToTryAndBe = 20 * 20 * nozzleSize * nozzleSize; // 10 x 10 mm approximately (assuming .5 nozzle) List <Polygons> allDownOutlines = CreateEmptyPolygons(numLayers); for (int layerIndex = numLayers - 2; layerIndex >= 0; layerIndex--) { Polygons aboveRequiredSupport = inputPolys[layerIndex + 1]; // get all the polygons above us Polygons accumulatedAbove = allDownOutlines[layerIndex + 1].CreateUnion(aboveRequiredSupport); // experimental and not working well enough yet if (config.MinimizeSupportColumns) { // reduce the amount of support material used for (int i = accumulatedAbove.Count - 1; i >= 0; i--) { Polygon polygon = accumulatedAbove[i]; double polyArea = polygon.Area(); if (polyArea > areaToTryAndBe) { Polygons offsetPolygons = new Polygons() { polygon }.Offset(-config.ExtrusionWidth_um / 2); accumulatedAbove.RemoveAt(i); foreach (Polygon polyToAdd in offsetPolygons) { accumulatedAbove.Insert(i, polyToAdd); } } else if (polyArea < areaToTryAndBe * .9) { Polygons offsetPolygons = new Polygons() { polygon }.Offset(config.ExtrusionWidth_um / 2); accumulatedAbove.RemoveAt(i); foreach (Polygon polyToAdd in offsetPolygons) { accumulatedAbove.Insert(i, polyToAdd); } } } } // add in the support on this level Polygons curRequiredSupport = inputPolys[layerIndex]; Polygons totalSupportThisLayer = accumulatedAbove.CreateUnion(curRequiredSupport); // remove the solid polygons on this level Polygons remainingAbove = totalSupportThisLayer.CreateDifference(allPartOutlines[layerIndex]); allDownOutlines[layerIndex] = Clipper.CleanPolygons(remainingAbove, cleanDistance_um); } return(allDownOutlines); }