Geomview 로 메쉬 내보내기 (Export)
RhinoScript
Summary: 메쉬 개체를 Geomview 의 OFF 파일 형식으로 내보내는 방법을 소개합니다.
참조
질문
메쉬 개체를 Geomview 의 Object File Format (OFF) 으로 내보낼 수 있습니까?
답변
RhinoScript 의 메쉬 개체 메서드를 사용하면 가능합니다.
다음의 샘플 스크립트에는 다음과 같은 하위 루틴이 있습니다:
- ExportOff - 메쉬 개체를 OFF 파일로 내보냅니다.
이 스크립트를 그대로 사용하려면 다음 링크를 클릭하여 다운로드하시기 바랍니다.
이 스크립트를 실행하려면 바탕화면에 압축 파일을 풀고 해당 파일을 마우스로 끌어, 실행 중인 Rhino 창에 가져다 놓은 후 마우스 단추를 놓으면 됩니다. 그 결과, ExportOff 명령 앨리어스가 추가됩니다.
다음은 스크립트 소스 코드입니다.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' ExportOff.rvb -- February 2009 ' If this code works, it was written by Dale Fugier. ' If not, I don't know who wrote it. ' Works with Rhino 4.0. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Option Explicit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Exports a mesh object to a Geomview .OFF file ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub ExportOff ' Local variables Dim strMesh, strFilter, strFileName Dim objFSO, objStream, i Dim v_count, v_list, v Dim f_count, f_list, f ' Pick a mesh object strMesh = Rhino.GetObject("Select mesh", 32) If IsNull(strMesh) Then Exit Sub ' Prompt the user to specify a file name strFilter = "Geomview OFF (*.off)|*.off|" strFileName = Rhino.SaveFileName("Save As", strFilter) If IsNull(strFileName) Then Exit Sub ' Get the file system object Set objFSO = CreateObject("Scripting.FileSystemObject") ' Open a text file to write to On Error Resume Next Set objStream = objFSO.CreateTextFile(strFileName, True) If Err Then MsgBox Err.Description Exit Sub End If ' Write the header objStream.WriteLine("OFF") objStream.WriteLine("#") objStream.WriteLine("# " & strFileName) objStream.WriteLine("#") ' Write the vertex, face, and edge counts v_count = Rhino.MeshVertexCount(strMesh) f_count = Rhino.MeshFaceCount(strMesh) objStream.WriteLine(CStr(v_count) & " " & CStr(f_count) & " " & CStr(v_count*f_count)) ' Write the vertices v_list = Rhino.MeshVertices(strMesh) For Each v In v_list objStream.WriteLine(CStr(v(0)) & " " & CStr(v(1)) & " " & CStr(v(2))) Next ' Write the faces f_list = Rhino.MeshFaceVertices(strMesh) For Each f In f_list If f(2) = f(3) Then objStream.WriteLine(CStr(3) & " " & CStr(f(0)) & " " & CStr(f(1)) & " " & CStr(f(2))) Else objStream.WriteLine(CStr(4) & " " & CStr(f(0)) & " " & CStr(f(1)) & " " & CStr(f(2)) & " " & CStr(f(3))) End If Next ' Close the file objStream.Close End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Rhino.AddStartupScript Rhino.LastLoadedScriptFile Rhino.AddAlias "ExportOff", "_NoEcho _-RunScript (ExportOff)"