+ added RFE #233 - Arch module OBJ exporter
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5019 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
parent
ff9c3fafdb
commit
4abc03fbce
|
@ -17,6 +17,7 @@ SET(Arch_SRCS
|
|||
Commands.py
|
||||
SectionPlane.py
|
||||
importDAE.py
|
||||
importOBJ.py
|
||||
Window.py
|
||||
)
|
||||
SOURCE_GROUP("" FILES ${Arch_SRCS})
|
||||
|
|
|
@ -56,6 +56,7 @@ class ArchWorkbench(Workbench):
|
|||
FreeCADGui.addLanguagePath(":/translations")
|
||||
FreeCADGui.addPreferencePage(":/ui/archprefs-base.ui","Arch")
|
||||
FreeCAD.addImportType("Industry Foundation Classes (*.ifc)","importIFC")
|
||||
FreeCAD.addExportType("Wavefront OBJ - Arch module (*.obj)","importOBJ")
|
||||
try:
|
||||
import collada
|
||||
except:
|
||||
|
|
|
@ -18,6 +18,7 @@ data_DATA = \
|
|||
ifcReader.py \
|
||||
importDAE.py \
|
||||
importIFC.py \
|
||||
importOBJ.py \
|
||||
Init.py \
|
||||
InitGui.py \
|
||||
Site.py \
|
||||
|
|
50
src/Mod/Arch/importOBJ.py
Normal file
50
src/Mod/Arch/importOBJ.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
import FreeCAD
|
||||
from draftlibs import fcgeo
|
||||
|
||||
pythonopen = open
|
||||
|
||||
def findVert(aVertex,aList):
|
||||
"finds aVertex in aList, returns index"
|
||||
for i in range(len(aList)):
|
||||
if (aVertex.X == aList[i].X) and (aVertex.Y == aList[i].Y) and (aVertex.Z == aList[i].Z):
|
||||
return i
|
||||
|
||||
def getIndices(shape,offset):
|
||||
"returns a list with 2 lists: vertices and face indexes, offsetted with the given amount"
|
||||
vlist = []
|
||||
flist = []
|
||||
for v in shape.Vertexes:
|
||||
vlist.append(" "+str(round(v.X,4))+" "+str(round(v.Z,4))+" "+str(round(v.Y,4)))
|
||||
for f in shape.Faces:
|
||||
fi = ""
|
||||
# OCC vertices are unsorted. We need to sort in the right order...
|
||||
edges = fcgeo.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)
|
||||
flist.append(fi)
|
||||
return vlist,flist
|
||||
|
||||
def export(exportList,filename):
|
||||
"called when freecad exports a file"
|
||||
outfile = pythonopen(filename,"wb")
|
||||
ver = FreeCAD.Version()
|
||||
outfile.write("# FreeCAD v" + ver[0] + "." + ver[1] + " build" + ver[2] + " Arch module\n")
|
||||
outfile.write("# http://free-cad.sf.net\n")
|
||||
offset = 1
|
||||
for obj in exportList:
|
||||
if obj.isDerivedFrom("Part::Feature"):
|
||||
vlist,flist = getIndices(obj.Shape,offset)
|
||||
offset += len(vlist)
|
||||
outfile.write("o " + obj.Name + "\n")
|
||||
for v in vlist:
|
||||
outfile.write("v" + v + "\n")
|
||||
for f in flist:
|
||||
outfile.write("f" + f + "\n")
|
||||
outfile.close()
|
||||
FreeCAD.Console.PrintMessage("successfully written "+filename)
|
||||
|
||||
|
||||
|
|
@ -407,7 +407,25 @@ def sortEdges(lEdges, aVertex=None):
|
|||
linstances += [i,j-1,instance]
|
||||
return [count]+linstances
|
||||
|
||||
if (len(lEdges) < 2): return lEdges
|
||||
if (len(lEdges) < 2):
|
||||
if aVertex == None:
|
||||
return lEdges
|
||||
else:
|
||||
result = lookfor(aVertex,lEdges)
|
||||
if result[0] != 0:
|
||||
if isSameVertex(aVertex,result[3].Vertexes[0]):
|
||||
print "1keeping"
|
||||
return lEdges
|
||||
else:
|
||||
print "1flipping"
|
||||
if isinstance(result[3].Curve,Part.Line):
|
||||
return [Part.Line(aVertex.Point,result[3].Vertexes[0].Point).toShape()]
|
||||
elif isinstance(result[3].Curve,Part.Circle):
|
||||
mp = findMidpoint(result[3])
|
||||
return [Part.Arc(aVertex.Point,mp,result[3].Vertexes[0].Point).toShape()]
|
||||
else:
|
||||
return lEdges
|
||||
|
||||
olEdges = [] # ol stands for ordered list
|
||||
if aVertex == None:
|
||||
for i in range(len(lEdges)*2) :
|
||||
|
@ -424,8 +442,10 @@ def sortEdges(lEdges, aVertex=None):
|
|||
del lEdges[result[1]]
|
||||
next = sortEdges(lEdges, result[3].Vertexes[-((-result[2])^1)])
|
||||
if isSameVertex(aVertex,result[3].Vertexes[0]):
|
||||
print "keeping"
|
||||
olEdges += [result[3]] + next
|
||||
else:
|
||||
print "flipping"
|
||||
if isinstance(result[3].Curve,Part.Line):
|
||||
newedge = Part.Line(aVertex.Point,result[3].Vertexes[0].Point).toShape()
|
||||
olEdges += [newedge] + next
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
<File Id="ArchIfcReaderPy" Name="ifcReader.py" DiskId="1" />
|
||||
<File Id="importDAEPy" Name="importDAE.py" DiskId="1" />
|
||||
<File Id="importIFCPy" Name="importIFC.py" DiskId="1" />
|
||||
<File Id="importOBJPy" Name="importOBJ.py" DiskId="1" />
|
||||
<File Id="ArchSitePy" Name="Site.py" DiskId="1" />
|
||||
<File Id="ArchStructurePy" Name="Structure.py" DiskId="1" />
|
||||
<File Id="ArchWallPy" Name="Wall.py" DiskId="1" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user