From 31a874c33f069ec8bc0d2c697b693ff06b844ba9 Mon Sep 17 00:00:00 2001 From: krautsource Date: Sun, 5 Dec 2021 19:31:15 +0100 Subject: [PATCH] Quick'n'dirty changes for compatibility with Blender 2.80+, removing support for the following material properties: transparency, emissive color and ambient color amount. --- io_scene_kicad/__init__.py | 25 +++++++++++++------------ io_scene_kicad/export_kicad.py | 27 ++++++++++++++------------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/io_scene_kicad/__init__.py b/io_scene_kicad/__init__.py index 6a82580..6c0a113 100644 --- a/io_scene_kicad/__init__.py +++ b/io_scene_kicad/__init__.py @@ -22,8 +22,8 @@ "name": "KiCadVRML2 (KiCad's idea of VRML2, terribly broken loader)", "author": "made by Campbell Barton, broken by Andrey Zabolotnyi", "version": (0, 1), - "blender": (2, 74, 0), - "location": "File > Export", + "blender": (2, 80, 0), + "location": "File > Import-Export", "description": "Exports mesh objects to VRML2 for KiCad", "warning": "", "support": 'COMMUNITY', @@ -48,16 +48,14 @@ PointerProperty, ) from bpy_extras.io_utils import (ExportHelper, - orientation_helper_factory, + orientation_helper, path_reference_mode, axis_conversion, ) -ExportKiCadVRMLOrientationHelper = orientation_helper_factory("ExportKiCadVRMLOrientationHelper", axis_forward='Y', axis_up='Z') - - -class ExportKiCadVRMLPrefs(PropertyGroup, ExportKiCadVRMLOrientationHelper): +@orientation_helper(axis_forward='Y', axis_up='Z') +class ExportKiCadVRMLPrefs(PropertyGroup): use_selection = BoolProperty( name="Selection Only", @@ -107,7 +105,7 @@ def execute(self, context): global_matrix = axis_conversion(to_forward=prefs.axis_forward, to_up=prefs.axis_up, - ).to_4x4() * Matrix.Scale(prefs.global_scale, 4) + ).to_4x4() @ Matrix.Scale(prefs.global_scale, 4) keywords["global_matrix"] = global_matrix return export_kicad.save(self, context, **keywords) @@ -133,18 +131,21 @@ def menu_func_export(self, context): def register(): - #bpy.utils.register_class(ExportKiCadVRML) - bpy.utils.register_module(__name__) + bpy.utils.register_class(ExportKiCadVRMLPrefs) + bpy.utils.register_class(ExportKiCadVRML) + #bpy.utils.register_module(__name__) bpy.types.Scene.export_kicad_vrml_prefs = PointerProperty (type = ExportKiCadVRMLPrefs) - bpy.types.INFO_MT_file_export.append(menu_func_export) + bpy.types.TOPBAR_MT_file_export.append(menu_func_export) def unregister(): - bpy.types.INFO_MT_file_export.remove(menu_func_export) + bpy.types.TOPBAR_MT_file_export.remove(menu_func_export) + bpy.utils.unregister_class(ExportKiCadVRMLPrefs) bpy.utils.unregister_class(ExportKiCadVRML) if __name__ == "__main__": register() + diff --git a/io_scene_kicad/export_kicad.py b/io_scene_kicad/export_kicad.py index a6b1d34..61873ad 100644 --- a/io_scene_kicad/export_kicad.py +++ b/io_scene_kicad/export_kicad.py @@ -40,14 +40,14 @@ def save_bmesh(fw, bm, materials): if m is None: continue fw('\t\t\t# Material %r\n' % materialid(m.name)) - fw("\t\t\tdiffuseColor %.3g %.3g %.3g\n" % m.diffuse_color[:]) - emissive_color = list (m.diffuse_color[:]) - for x in range (len (emissive_color)): - emissive_color [x] *= m.emit - fw("\t\t\temissiveColor %.3g %.3g %.3g\n" % tuple (emissive_color)) + fw("\t\t\tdiffuseColor %.3g %.3g %.3g %.3g\n" % m.diffuse_color[:]) + # emissive_color = list (m.diffuse_color[:]) + # for x in range (len (emissive_color)): + # emissive_color [x] *= m.emit + # fw("\t\t\temissiveColor %.3g %.3g %.3g\n" % tuple (emissive_color)) fw("\t\t\tspecularColor %.3g %.3g %.3g\n" % m.specular_color[:]) - fw("\t\t\tambientIntensity %.3g\n" % m.ambient) - fw("\t\t\ttransparency %.3g\n" % (1-m.alpha)) + #fw("\t\t\tambientIntensity %.3g\n" % m.ambient) + #fw("\t\t\ttransparency %.3g\n" % (1-m.alpha)) fw("\t\t\tshininess %.3g\n" % m.specular_intensity) break @@ -99,7 +99,8 @@ def save_object(fw, global_matrix, if is_editmode: bpy.ops.object.editmode_toggle() - me = obj.to_mesh(scene, True, 'PREVIEW', calc_tessface=False) + #me = obj.to_mesh(scene, True, 'PREVIEW', calc_tessface=False) + me = obj.to_mesh() bm = bmesh.new() bm.from_mesh(me) @@ -117,7 +118,7 @@ def save_object(fw, global_matrix, # Blender 2.74 fails triangulation if we do it after transform. # If we do it before, it's ok. bmesh.ops.triangulate(bm, faces=bm.faces) - bm.transform(global_matrix * obj.matrix_world) + bm.transform(global_matrix @ obj.matrix_world) save_bmesh(fw, bm, me.materials) @@ -130,7 +131,7 @@ def vrmlid(n): def materialid(n): """ Transform a material name for VRML compatibility, but no leading '_', we might reimport wrl and keep material names.""" return n.replace ('.', '_').replace (' ','-') - + def save(operator, context, filepath="", @@ -151,7 +152,7 @@ def save(operator, top = None toploc = None for obj in objects: - if (obj.type != 'MESH') or obj.hide: + if (obj.type != 'MESH') or obj.hide_viewport: continue cur = obj @@ -177,7 +178,7 @@ def save(operator, return {'CANCELLED'} if not (top is None): - global_matrix *= mathutils.Matrix.Translation (-toploc) + global_matrix @= mathutils.Matrix.Translation (-toploc) file = open(filepath, 'w', encoding='utf-8') fw = file.write @@ -185,7 +186,7 @@ def save(operator, fw('#modeled using blender3d http://blender.org\n') for obj in objects: - if (obj.type != 'MESH') or obj.hide: + if (obj.type != 'MESH') or obj.hide_viewport: continue fw("\n# %r\nDEF %s Transform {\nchildren [\n" % (obj.name, vrmlid (obj.name)))