/// <summary> /// Sets our global object size with an extent object /// </summary> private void updateSize() { Size = new Extent { XMax = VertexList.Max(v => v.X), XMin = VertexList.Min(v => v.X), YMax = VertexList.Max(v => v.Y), YMin = VertexList.Min(v => v.Y), ZMax = VertexList.Max(v => v.Z), ZMin = VertexList.Min(v => v.Z) }; }
/// <summary> /// 3D파일 사이즈 구하기 /// </summary> /// <param name="path"></param> /// <param name="ext"></param> /// <returns></returns> public ModelingSize GetSizeFor3DFile(string path, string ext) { ModelingSize getSize = new ModelingSize(); double volume = 0; double x1 = 0; double y1 = 0; double z1 = 0; double x2 = 0; double y2 = 0; double z2 = 0; double x3 = 0; double y3 = 0; double z3 = 0; switch (ext) { case ".stl": STLDocument facets = STLDocument.Open(path); //stl Size = new Extent { XMax = facets.Facets.Max(f => f.Vertices.Max(v => v.X)), XMin = facets.Facets.Min(f => f.Vertices.Min(v => v.X)), YMax = facets.Facets.Max(f => f.Vertices.Max(v => v.Y)), YMin = facets.Facets.Min(f => f.Vertices.Min(v => v.Y)), ZMax = facets.Facets.Max(f => f.Vertices.Max(v => v.Z)), ZMin = facets.Facets.Min(f => f.Vertices.Min(v => v.Z)) }; for (int i = 0; i < facets.Facets.Count; i++) { x1 = facets.Facets[i].Vertices[0].X; y1 = facets.Facets[i].Vertices[0].Y; z1 = facets.Facets[i].Vertices[0].Z; x2 = facets.Facets[i].Vertices[1].X; y2 = facets.Facets[i].Vertices[1].Y; z2 = facets.Facets[i].Vertices[1].Z; x3 = facets.Facets[i].Vertices[2].X; y3 = facets.Facets[i].Vertices[2].Y; z3 = facets.Facets[i].Vertices[2].Z; volume += (-x3 * y2 * z1 + x2 * y3 * z1 + x3 * y1 * z2 - x1 * y3 * z2 - x2 * y1 * z3 + x1 * y2 * z3) / 6; } break; case ".obj": VertexList = new List<QuantumConcepts.Formats.StereoLithography.Vertex>(); OBJDocument objDoc = new OBJDocument().LoadObj(path); int[] idx = new int[3]; Size = new Extent { XMax = objDoc.VertexList.Where(w => (int)w.X != 0).Max(v => v.X), XMin = objDoc.VertexList.Where(w => (int)w.X != 0).Min(v => v.X), YMax = objDoc.VertexList.Where(w => (int)w.Y != 0).Max(v => v.Y), YMin = objDoc.VertexList.Where(w => (int)w.Y != 0).Min(v => v.Y), ZMax = objDoc.VertexList.Where(w => (int)w.Z != 0).Max(v => v.Z), ZMin = objDoc.VertexList.Where(w => (int)w.Z != 0).Min(v => v.Z) }; int vertexCnt = objDoc.VertexList.Count(); for (int i = 0; i < objDoc.FaceList.Count; i++) { idx[0] = objDoc.FaceList[i].VertexIndexList[0] - 1; idx[1] = objDoc.FaceList[i].VertexIndexList[1] - 1; idx[2] = objDoc.FaceList[i].VertexIndexList[2] - 1; if (idx[0] > 0 && idx[1] > 0 && idx[2] > 0) { if (idx[0] > vertexCnt && idx[1] > vertexCnt && idx[2] > vertexCnt) { //log 로 남겨보기 } else { x1 = objDoc.VertexList[idx[0]].X; y1 = objDoc.VertexList[idx[0]].Y; z1 = objDoc.VertexList[idx[0]].Z; x2 = objDoc.VertexList[idx[1]].X; y2 = objDoc.VertexList[idx[1]].Y; z2 = objDoc.VertexList[idx[1]].Z; x3 = objDoc.VertexList[idx[2]].X; y3 = objDoc.VertexList[idx[2]].Y; z3 = objDoc.VertexList[idx[2]].Z; volume += (-x3 * y2 * z1 + x2 * y3 * z1 + x3 * y1 * z2 - x1 * y3 * z2 - x2 * y1 * z3 + x1 * y2 * z3) / 6; } } else { //log 로 남겨보기 } } break; } volume = volume < 0 ? volume * -1 : volume; getSize.X = Math.Round(Size.XSize, 1); getSize.Y = Math.Round(Size.YSize, 1); getSize.Z = Math.Round(Size.ZSize, 1); getSize.ObjectVolume = Math.Round(volume, 1) / 1000; return getSize; }