Advertisement
Robomatics

Reading Binary STL Files

Jan 3rd, 2013
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.92 KB | None | 0 0
  1. 'Reading STL binary files
  2.  
  3.  Dim pointsstring() As Byte
  4.         Dim filelocation() As String = OpenFileDialog1.FileNames
  5.  
  6.         For i2 = 0 To filelocation.Length - 1
  7.  
  8.             If System.IO.File.Exists(filelocation(i2)) = True Then
  9.  
  10.                 GC.Collect()
  11.                 pointsstring = System.IO.File.ReadAllBytes(filelocation(i2))
  12.                 GC.Collect()
  13.  
  14.                 normals(objectcount) = New List(Of Vector3)
  15.                 points(objectcount) = New List(Of Vector3)
  16.                 Dim pointcount As UInt32 = BitConverter.ToUInt32(pointsstring, 80)
  17.                 Dim NX, NY, NZ, X1, X2, X3, Y1, Y2, Y3, Z1, Z2, Z3 As Single
  18.  
  19.                 For i = 84 To pointsstring.Length - 1 Step 50
  20.  
  21.                     NX = BitConverter.ToSingle(pointsstring, i + 0)
  22.                     NY = BitConverter.ToSingle(pointsstring, i + 4)
  23.                     NZ = BitConverter.ToSingle(pointsstring, i + 8)
  24.  
  25.                     normals(objectcount).Add(New Vector3(NX, NY, NZ))
  26.  
  27.                     X1 = BitConverter.ToSingle(pointsstring, i + 12)
  28.                     Y1 = BitConverter.ToSingle(pointsstring, i + 16)
  29.                     Z1 = BitConverter.ToSingle(pointsstring, i + 20)
  30.  
  31.                     points(objectcount).Add(New Vector3(X1, Y1, Z1))
  32.  
  33.                     X2 = BitConverter.ToSingle(pointsstring, i + 24)
  34.                     Y2 = BitConverter.ToSingle(pointsstring, i + 28)
  35.                     Z2 = BitConverter.ToSingle(pointsstring, i + 32)
  36.  
  37.                     points(objectcount).Add(New Vector3(X2, Y2, Z2))
  38.  
  39.                     X3 = BitConverter.ToSingle(pointsstring, i + 36)
  40.                     Y3 = BitConverter.ToSingle(pointsstring, i + 40)
  41.                     Z3 = BitConverter.ToSingle(pointsstring, i + 44)
  42.  
  43.                     points(objectcount).Add(New Vector3(X3, Y3, Z3))
  44.  
  45.                 Next
  46.  
  47.               objectcount = objectcount + 1
  48.             End If
  49.         Next
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement