Commit 3b367f98 authored by lode_leroy's avatar lode_leroy

fix detection of binary STL

git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@56 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent d25605d6
import re import re, os
from struct import unpack from struct import unpack
from pycam.Geometry import * from pycam.Geometry import *
...@@ -52,12 +52,16 @@ def ImportModel(filename, use_kdtree=True): ...@@ -52,12 +52,16 @@ def ImportModel(filename, use_kdtree=True):
f = open(filename,"rb") f = open(filename,"rb")
header = f.read(80) header = f.read(80)
numfacets = unpack("<I",f.read(4))[0]
binary = False binary = False
if header[0:5] == "solid":
if os.path.getsize(filename) == (84 + 50*numfacets):
binary = True
elif header.find("solid ")>=0:
binary = False binary = False
f.seek(0) f.seek(0)
else: else:
binary = True binary = true
if use_kdtree: if use_kdtree:
kdtree = PointKdtree([],3,1,epsilon) kdtree = PointKdtree([],3,1,epsilon)
...@@ -69,8 +73,6 @@ def ImportModel(filename, use_kdtree=True): ...@@ -69,8 +73,6 @@ def ImportModel(filename, use_kdtree=True):
p3 = None p3 = None
if binary: if binary:
numfacets = unpack("<I",f.read(4))[0]
for i in range(1,numfacets): for i in range(1,numfacets):
a1 = unpack("<f",f.read(4))[0] a1 = unpack("<f",f.read(4))[0]
a2 = unpack("<f",f.read(4))[0] a2 = unpack("<f",f.read(4))[0]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment