참고 링크 https://en.wikipedia.org/wiki/STL_(file_format)
ASCII STL[edit]
An ASCII STL file begins with the line
solid name
where name is an optional string (though if name is omitted there must still be a space after solid). The file continues with any number of triangles, each represented as follows:
facet normal ni nj nk outer loop vertex v1<sub style="line-height: 1; font-size: 11.2px;">x</sub> v1<sub style="line-height: 1; font-size: 11.2px;">y</sub> v1<sub style="line-height: 1; font-size: 11.2px;">z</sub> vertex v2<sub style="line-height: 1; font-size: 11.2px;">x</sub> v2<sub style="line-height: 1; font-size: 11.2px;">y</sub> v2<sub style="line-height: 1; font-size: 11.2px;">z</sub> vertex v3<sub style="line-height: 1; font-size: 11.2px;">x</sub> v3<sub style="line-height: 1; font-size: 11.2px;">y</sub> v3<sub style="line-height: 1; font-size: 11.2px;">z</sub> endloopendfacet
where each n or v is a floating-point number in sign-mantissa-"e"-sign-exponent format, e.g., "2.648000e-002" (noting that each v must be non-negative). The file concludes with
endsolid name
The structure of the format suggests that other possibilities exist (e.g., facets with more than one "loop", or loops with more than three vertices). In practice, however, all facets are simple triangles.
White space (spaces, tabs, newlines) may be used anywhere in the file except within numbers or words. The spaces between "facet" and "normal" and between "outer" and "loop" are required.[6]
위와 같이 아스키코드로 제작 하였습니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | public void ModelSaveToSTL() { List<Vector3> _Vertex = new List<Vector3>(); List<Vector3> _Nomal = new List<Vector3>(); StreamWriter sw = new StreamWriter(pathForDocumentsFile("sample.stl")); List<GameObject> _ObjectList = GameObject.FindGameObjectWithTag("Manager").GetComponent<ObjectManager>().Objects; sw.WriteLine("solid ModelSTL"); //Model Name int index = 0; foreach (GameObject G in _ObjectList) { foreach (int _tri in G.GetComponent<MeshFilter>().mesh.triangles) { _Vertex.Add(G.GetComponent<MeshFilter>().mesh.vertices[_tri] + G.transform.position); _Nomal.Add(G.GetComponent<MeshFilter>().mesh.normals[_tri]); } index += G.GetComponent<MeshFilter>().mesh.triangles.Length/3; } sw.WriteLine(index.ToString()); int Nomalcount = 0; int Vertexcount = 0; for (int i = 0; i < index; i++) { Vector3 Vt = ((_Nomal[Nomalcount++] + _Nomal[Nomalcount++] + _Nomal[Nomalcount++]) / 3.0f); sw.WriteLine("facet normal "+ Vt.x.ToString() + " " + Vt.y.ToString() + " " + Vt.z.ToString() ); // Nomal sw.WriteLine("outer loop"); sw.WriteLine("vertex " + _Vertex[Vertexcount].x.ToString() + " " + _Vertex[Vertexcount].y.ToString() + " " + _Vertex[Vertexcount].z.ToString() ); //Vertex01 Vertexcount++; sw.WriteLine("vertex " + _Vertex[Vertexcount].x.ToString() + " " + _Vertex[Vertexcount].y.ToString() + " " + _Vertex[Vertexcount].z.ToString() ); //Vertex02 Vertexcount++; sw.WriteLine("vertex " + _Vertex[Vertexcount].x.ToString() + " " + _Vertex[Vertexcount].y.ToString() + " " + _Vertex[Vertexcount].z.ToString() ); //Vertex03 Vertexcount++; sw.WriteLine("endloop"); sw.WriteLine("endfacet"); } sw.WriteLine("endsolid ModelSTL"); sw.Flush(); sw.Close(); Debug.Log("저장 완료"); } | cs |
직접 저장해보고 STL 뷰어로 확인하니 이상없었습니다.
'프로그래밍 > Unity3D' 카테고리의 다른 글
[Unity3D] 코드를 이용하여 기본도형 메시 만들기 (0) | 2016.02.22 |
---|---|
[Unity3D] 유니티를 이용하여 Gmail 보내기 (0) | 2016.02.22 |
[Unity3D] 카메라를 기준으로 캐릭터의 forward와 Right Vector구하기 (0) | 2016.02.22 |
[Unity3D] 플랫폼별 각 경로들 (0) | 2016.02.22 |
[Unity3D] 파일 입출력 기본 (0) | 2016.02.22 |