Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions io_scene_kicad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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()

27 changes: 14 additions & 13 deletions io_scene_kicad/export_kicad.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand All @@ -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="",
Expand All @@ -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
Expand All @@ -177,15 +178,15 @@ 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
fw('#VRML V2.0 utf8\n')
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)))
Expand Down