From f07f996c4895cc9375589cf9e260beec682af258 Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Mon, 4 Feb 2019 11:51:30 +0000 Subject: [PATCH] Collada Export Py3 Fixes To allow successful Collada Export for Py3 and Py2, tested import of DAE file with colours from Blender to ensure no regression on the import side. Note: I had to download Pycollada to enable testing in Conda build. --- src/Mod/Arch/importDAE.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Mod/Arch/importDAE.py b/src/Mod/Arch/importDAE.py index 6ac9bcc22b..c3e44d4264 100644 --- a/src/Mod/Arch/importDAE.py +++ b/src/Mod/Arch/importDAE.py @@ -42,6 +42,12 @@ __url__ = "http://www.freecadweb.org" DEBUG = True +try: + # Python 2 forward compatibility + range = xrange +except NameError: + pass + def checkCollada(): "checks if collada if available" global collada @@ -176,7 +182,10 @@ def export(exportList,filename,tessellation=1): colmesh.assetInfo.upaxis = collada.asset.UP_AXIS.Z_UP # authoring info cont = collada.asset.Contributor() - author = FreeCAD.ActiveDocument.CreatedBy.encode("utf8") + try: + author = FreeCAD.ActiveDocument.CreatedBy + except UnicodeEncodeError: + author = FreeCAD.ActiveDocument.CreatedBy.encode("utf8") author = author.replace("<","") author = author.replace(">","") cont.author = author @@ -215,19 +224,19 @@ def export(exportList,filename,tessellation=1): # vertex indices vindex = numpy.empty(len(Topology[0]) * 3) - for i in xrange(len(Topology[0])): + for i in range(len(Topology[0])): v = Topology[0][i] vindex[list(range(i*3, i*3+3))] = (v.x*scale,v.y*scale,v.z*scale) # normals nindex = numpy.empty(len(Facets) * 3) - for i in xrange(len(Facets)): + for i in range(len(Facets)): n = Facets[i].Normal nindex[list(range(i*3, i*3+3))] = (n.x,n.y,n.z) # face indices findex = numpy.empty(len(Topology[1]) * 6, numpy.int64) - for i in xrange(len(Topology[1])): + for i in range(len(Topology[1])): f = Topology[1][i] findex[list(range(i*6, i*6+6))] = (f[0],i,f[1],i,f[2],i)