diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index 0172e06d87..3799e6da3b 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -181,6 +181,14 @@ def getPreferences(): return preferences +# ************************************************************************************************ +# ********** backwards compatibility **************** + +def export(exportList,filename,colors=None,preferences=None): + import exportIFC + exportIFC.export(exportList,filename,colors,preferences) + + # ************************************************************************************************ # ********** open and import IFC **************** diff --git a/src/Mod/Arch/importOBJ.py b/src/Mod/Arch/importOBJ.py index 12919344ce..62443d6ab2 100644 --- a/src/Mod/Arch/importOBJ.py +++ b/src/Mod/Arch/importOBJ.py @@ -66,6 +66,7 @@ def getIndices(obj,shape,offsetv,offsetvn): elist = [] flist = [] curves = None + mesh = None if isinstance(shape,Part.Shape): for e in shape.Edges: @@ -77,8 +78,8 @@ def getIndices(obj,shape,offsetv,offsetvn): myshape.Placement=obj.LinkPlacement else: myshape = obj.Shape.copy(False) - myshape.Placement=obj.getGlobalPlacement() - mesh=MeshPart.meshFromShape(Shape=myshape, LinearDeflection=0.1, AngularDeflection=0.7, Relative=True) + myshape.Placement = obj.getGlobalPlacement() + mesh = MeshPart.meshFromShape(Shape=myshape, LinearDeflection=0.1, AngularDeflection=0.7, Relative=True) FreeCAD.Console.PrintWarning(translate("Arch","Found a shape containing curves, triangulating")+"\n") break except: # unimplemented curve type @@ -89,10 +90,11 @@ def getIndices(obj,shape,offsetv,offsetvn): else: myshape = obj.Shape.copy(False) myshape.Placement=obj.getGlobalPlacement() - mesh=MeshPart.meshFromShape(Shape=myshape, LinearDeflection=0.1, AngularDeflection=0.7, Relative=True) + mesh = MeshPart.meshFromShape(Shape=myshape, LinearDeflection=0.1, AngularDeflection=0.7, Relative=True) FreeCAD.Console.PrintWarning(translate("Arch","Found a shape containing curves, triangulating")+"\n") break elif isinstance(shape,Mesh.Mesh): + mesh = shape curves = shape.Topology if mesh: for v in mesh.Topology[0]: diff --git a/src/Mod/Arch/importWebGL.py b/src/Mod/Arch/importWebGL.py index b950c29068..09e70e57aa 100644 --- a/src/Mod/Arch/importWebGL.py +++ b/src/Mod/Arch/importWebGL.py @@ -62,7 +62,7 @@ template = """ window.onload = function() { var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight; - var VIEW_ANGLE = 35, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000; + var VIEW_ANGLE = 35, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 200000; renderer = new THREE.WebGLRenderer(); renderer.setSize( SCREEN_WIDTH, SCREEN_HEIGHT ); @@ -117,30 +117,42 @@ template = """ if open.__module__ in ['__builtin__','io']: pythonopen = open -def export(exportList,filename): +def export(exportList,filename,colors=None,camera=None): "exports the given objects to an .html file" - html = getHTML(exportList) + html = getHTML(exportList,colors,camera) outfile = pythonopen(filename,"w") outfile.write(html) outfile.close() FreeCAD.Console.PrintMessage(translate("Arch", "Successfully written", utf8_decode=True) + ' ' + filename + "\n") -def getHTML(objectsList): +def getHTML(objectsList,colors=None,camera=None): "returns the complete HTML code of a viewer for the given objects" # get objects data objectsData = '' for obj in objectsList: - objectsData += getObjectData(obj) - t = template.replace("$CameraData",getCameraData()) + colordata = None + if colors: + if obj.Name in colors: + colordata = colors[obj.Name] + objectsData += getObjectData(obj,color=colordata) + t = template.replace("$CameraData",getCameraData(camera)) t = t.replace("$ObjectsData",objectsData) return t -def getCameraData(): +def getCameraData(camera=None): "returns the position and direction of the camera as three.js snippet" result = "" + if camera: + global cameraPosition + if isinstance(camera,str): + import OfflineRenderingUtils + camnode = OfflineRenderingUtils.getCoinCamera(camera) + cameraPosition = camnode.position.getValue().getValue() + elif hasattr(camera,"position"): + cameraPosition = camera.position.getValue().getValue() if cameraPosition: result += "camera.position.set("+str(cameraPosition[0])+","+str(cameraPosition[1])+","+str(cameraPosition[2])+");\n" elif FreeCADGui: @@ -156,7 +168,7 @@ def getCameraData(): # print(result) return result -def getObjectData(obj,wireframeMode=wireframeStyle): +def getObjectData(obj,wireframeMode=wireframeStyle,color=None): """returns the geometry data of an object as three.js snippet. wireframeMode can be multimaterial, faceloop, or None""" @@ -199,7 +211,9 @@ def getObjectData(obj,wireframeMode=wireframeStyle): if result: # adding a base material - if FreeCADGui: + if color: + rgb = Draft.getrgb(color,testbw=False) + elif FreeCADGui: col = obj.ViewObject.ShapeColor rgb = Draft.getrgb(col,testbw=False) else: