Skip to content

Commit

Permalink
Arch: Fixed OBJ exporter to work with curves - fixes #1527
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed May 4, 2014
1 parent cb720fa commit 5c01cf0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 28 deletions.
67 changes: 41 additions & 26 deletions src/Mod/Arch/importOBJ.py
Expand Up @@ -42,34 +42,49 @@ def getIndices(shape,offset):
vlist = []
elist = []
flist = []
for v in shape.Vertexes:
vlist.append(" "+str(round(v.X,p))+" "+str(round(v.Y,p))+" "+str(round(v.Z,p)))
if not shape.Faces:
for e in shape.Edges:
if DraftGeomUtils.geomType(e) == "Line":
ei = " " + str(findVert(e.Vertexes[0],shape.Vertexes) + offset)
ei += " " + str(findVert(e.Vertexes[-1],shape.Vertexes) + offset)
elist.append(ei)
for f in shape.Faces:
if len(f.Wires) > 1:
# if we have holes, we triangulate
tris = f.tessellate(1)
for fdata in tris[1]:
fi = ""
for vi in fdata:
vdata = Part.Vertex(tris[0][vi])
fi += " " + str(findVert(vdata,shape.Vertexes) + offset)
flist.append(fi)
else:
curves = None
for e in shape.Edges:
if not isinstance(e.Curve,Part.Line):
if not curves:
curves = shape.tessellate(1)
FreeCAD.Console.PrintWarning(translate("Arch","Found a shape containing curves, triangulating\n"))
if curves:
for v in curves[0]:
vlist.append(" "+str(round(v.x,p))+" "+str(round(v.y,p))+" "+str(round(v.z,p)))
for f in curves[1]:
fi = ""
# OCC vertices are unsorted. We need to sort in the right order...
edges = DraftGeomUtils.sortEdges(f.Wire.Edges)
#print edges
for e in edges:
#print e.Vertexes[0].Point,e.Vertexes[1].Point
v = e.Vertexes[0]
fi += " " + str(findVert(v,shape.Vertexes) + offset)
for vi in f:
fi += " " + str(vi + offset)
flist.append(fi)
else:
for v in shape.Vertexes:
vlist.append(" "+str(round(v.X,p))+" "+str(round(v.Y,p))+" "+str(round(v.Z,p)))
if not shape.Faces:
for e in shape.Edges:
if DraftGeomUtils.geomType(e) == "Line":
ei = " " + str(findVert(e.Vertexes[0],shape.Vertexes) + offset)
ei += " " + str(findVert(e.Vertexes[-1],shape.Vertexes) + offset)
elist.append(ei)
for f in shape.Faces:
if len(f.Wires) > 1:
# if we have holes, we triangulate
tris = f.tessellate(1)
for fdata in tris[1]:
fi = ""
for vi in fdata:
vdata = Part.Vertex(tris[0][vi])
fi += " " + str(findVert(vdata,shape.Vertexes) + offset)
flist.append(fi)
else:
fi = ""
# OCC vertices are unsorted. We need to sort in the right order...
edges = DraftGeomUtils.sortEdges(f.OuterWire.Edges)
#print edges
for e in edges:
#print e.Vertexes[0].Point,e.Vertexes[1].Point
v = e.Vertexes[0]
fi += " " + str(findVert(v,shape.Vertexes) + offset)
flist.append(fi)
return vlist,elist,flist

def export(exportList,filename):
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Draft/Draft.py
Expand Up @@ -342,7 +342,6 @@ def removeHidden(objectslist):
for o in objectslist:
if o.ViewObject:
if not o.ViewObject.isVisible():

newlist.remove(o)
return newlist

Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Draft/DraftSnap.py
Expand Up @@ -1032,7 +1032,7 @@ def accept():
FreeCADGui.Snapper.off()
self.ui.offUi()
if callback:
if len(inspect.getargspec(callback).args) > 2:
if len(inspect.getargspec(callback).args) > 1:
callback(self.pt,obj)
else:
callback(self.pt)
Expand Down

0 comments on commit 5c01cf0

Please sign in to comment.