/// <summary> /// _3DModel 변환 /// </summary> /// <param name="filename"></param> /// <param name="extension"></param> /// <returns></returns> public Object3DModel Get3DModel(string filename, string extension) { Object3DModel stlModel = new Object3DModel(); Metadata metadata = new Metadata(); metadata.formatVersion = "3"; metadata.generatedBy = "Mersh"; stlModel.metadata = metadata; stlModel.scale = "1.0"; stlModel.materials = new string[] { }; stlModel.morphTargets = new string[] { }; stlModel.morphColors = new string[] { }; stlModel.normals = new string[] { }; stlModel.colors = new string[] { }; stlModel.uvs = new string[, ] { }; int indexF = 0; int indexV = 0; if (extension == ".stl") { STLDocument facets = STLDocument.Open(filename); int index = 0; stlModel.faces = new int[facets.Count() * 4]; stlModel.vertices = new float[facets.Count() * 9]; foreach (var facet in facets) { stlModel.faces[index] = 0; index++; foreach (var vertice in facet.Vertices) { VertexM m = new VertexM(); stlModel.faces[index] = indexF; stlModel.vertices[indexV] = vertice.X; indexV++; stlModel.vertices[indexV] = vertice.Y; indexV++; stlModel.vertices[indexV] = vertice.Z; indexV++; indexF++; index++; } } } if (extension == ".obj") { VertexList = new List <QuantumConcepts.Formats.StereoLithography.Vertex>(); OBJDocument objDoc = new OBJDocument().LoadObj(filename); stlModel.faces = new int[objDoc.FaceList.Count() * 4]; stlModel.vertices = new float[objDoc.VertexList.Count() * 9]; for (int i = 0; i < objDoc.FaceList.Count; i++) { stlModel.faces[indexF] = 0; indexF++; stlModel.faces[indexF] = objDoc.FaceList[i].VertexIndexList[0] - 1; indexF++; stlModel.faces[indexF] = objDoc.FaceList[i].VertexIndexList[1] - 1; indexF++; stlModel.faces[indexF] = objDoc.FaceList[i].VertexIndexList[2] - 1; indexF++; } for (int i = 0; i < objDoc.VertexList.Count; i++) { VertexM m = new VertexM(); stlModel.vertices[indexV] = (float)objDoc.VertexList[i].X; indexV++; stlModel.vertices[indexV] = (float)objDoc.VertexList[i].Y; indexV++; stlModel.vertices[indexV] = (float)objDoc.VertexList[i].Z; indexV++; } } return(stlModel); }