+ 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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user