참고 링크 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 |
1 2 3 4 5 6 7 8 | Transform CameraTransform = Camera.main.transform; Vector3 forwardVector3 = CameraTransform.forward; forwardVector3.y = 0; //y를 0으로 forwardVector3.Normalize(); //노말라이즈된 Forward 벡터를 구한다. //-X값과 Z값을 바꿔서 오른쪽 벡터를 구한다. Vector3 RightVector3 = new Vector3(forwardVector3.z, 0, -forwardVector3.x); | cs |
'프로그래밍 > Unity3D' 카테고리의 다른 글
[Unity3D] 유니티를 이용하여 Gmail 보내기 (0) | 2016.02.22 |
---|---|
[Unity3D] 유니티 메시를 STL(format)으로 변환하여 저장 하기. (0) | 2016.02.22 |
[Unity3D] 플랫폼별 각 경로들 (0) | 2016.02.22 |
[Unity3D] 파일 입출력 기본 (0) | 2016.02.22 |
[Unity3D] 좀더 쉬운 XML저장 방법 (0) | 2016.02.22 |
Editor
- Application.dataPath /*project*/Assets
Web Player
System.IO.Path.GetFullPath(".") | %Project% |
Application.dataPath | %Project%/Assets |
Application.persistentDataPath | %userprofile%\AppData\LocalLow/%Company%/%Product% |
Application.streamingAssetsPath | %Project%/Assets/StreamingAssets |
Application.temporaryCachePath | %LocalAppData%/Local/Temp/Temp/%Company%/%Product% |
Android
System.IO.Path.GetFullPath(".") | / |
Application.dataPath | /data/app/%BundleIdentifier%.apk |
Application.persistentDataPath | /data/data/%BundleIdentifier%/files |
Application.streamingAssetsPath | jar:file:///data/app/%BundleIdentifier%.apk/!/assets |
Application.temporaryCachePath | /data/data/%BundleIdentifier%/cache |
Android sdcard
Application.persistentDataPath | /mnt/sdcard/Android/data/%BundleIdentifier%/files |
Application.streamingAssetsPath | jar:file:///data/app/%BundleIdentifier%.apk/!/assets |
Application.temporaryCachePathz | /mnt/sdcard/Android/data/%BundleIdentifier%/cache |
iOS
System.IO.Path.GetFullPath(".") | / |
Application.dataPath | %ProvisioningProfile%/%BundleIdentifier%.app/Data |
Application.persistentDataPath | %ProvisioningProfile%/Documents |
Application.streamingAssetsPath | %ProvisioningProfile%/%BundleIdentifier%.app/Data/Raw |
Application.temporaryCachePath | %ProvisioningProfile%/Library/Caches |
// ** iPhone device
- Application.dataPath /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Assets
- Application.persistentDataPath : /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents
- Application.temporaryCachePath : /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Library/Caches
- iPhpone Simulator Path : /Users/<Name>/Library/Application Support/iPhone Simulator/4.1/Applications/<GUID>/
// ** Android
- Application.dataPath /mnt/asec/com.xxx.xxx/pkg.apk
- Application.persistentDataPath /data/data/com.xxx.xxx/files/
- Application.temporaryCachePath /data/data/com.xxx.xxx/cache/
* sdcard 사용시.
- Application.persistentDataPath /mnt/sdcard/Android/data/com.xxx.xxx/files/
- Application.temporaryCachePath /mnt/sdcard/Android/data/com.xxx.xxx/cache/
출처 :
'프로그래밍 > Unity3D' 카테고리의 다른 글
[Unity3D] 유니티 메시를 STL(format)으로 변환하여 저장 하기. (0) | 2016.02.22 |
---|---|
[Unity3D] 카메라를 기준으로 캐릭터의 forward와 Right Vector구하기 (0) | 2016.02.22 |
[Unity3D] 파일 입출력 기본 (0) | 2016.02.22 |
[Unity3D] 좀더 쉬운 XML저장 방법 (0) | 2016.02.22 |
[Unity3D] 멀티터치를 이용하여 줌인 줌아웃 구현 (0) | 2016.02.22 |