178 lines
5.0 KiB
Python
178 lines
5.0 KiB
Python
|
bl_info = {
|
||
|
"name": "gdsii OBJ format",
|
||
|
"author": "Julian Daube",
|
||
|
"version": (0, 9, 0),
|
||
|
"blender": (2, 78, 0),
|
||
|
"location": "File > Import-Export",
|
||
|
"description": "Import GdsII files",
|
||
|
"warning": "",
|
||
|
"category": "Import-Export"}
|
||
|
|
||
|
if "bpy" in locals():
|
||
|
import importlib
|
||
|
if "import_gds" in locals():
|
||
|
importlib.reload(import_gds)
|
||
|
|
||
|
import bpy
|
||
|
|
||
|
from bpy.props import (
|
||
|
BoolProperty,
|
||
|
FloatProperty,
|
||
|
StringProperty,
|
||
|
EnumProperty,
|
||
|
)
|
||
|
from bpy_extras.io_utils import (
|
||
|
ImportHelper,
|
||
|
ExportHelper,
|
||
|
orientation_helper_factory,
|
||
|
path_reference_mode,
|
||
|
axis_conversion,
|
||
|
)
|
||
|
|
||
|
IOOBJOrientationHelper = orientation_helper_factory("IOOBJOrientationHelper", axis_forward='-Z', axis_up='Y')
|
||
|
|
||
|
|
||
|
class ImportGDS(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
|
||
|
"""Load a GDSII File"""
|
||
|
bl_idname = "import_scene.gds"
|
||
|
bl_label = "Import GDSII"
|
||
|
bl_options = {'PRESET', 'UNDO'}
|
||
|
|
||
|
filename_ext = ".obj"
|
||
|
filter_glob = StringProperty(
|
||
|
default="*.gds",
|
||
|
options={'HIDDEN'},
|
||
|
)
|
||
|
|
||
|
use_edges = BoolProperty(
|
||
|
name="Lines",
|
||
|
description="Import lines and faces with 2 verts as edge",
|
||
|
default=True,
|
||
|
)
|
||
|
use_smooth_groups = BoolProperty(
|
||
|
name="Smooth Groups",
|
||
|
description="Surround smooth groups by sharp edges",
|
||
|
default=True,
|
||
|
)
|
||
|
|
||
|
use_split_objects = BoolProperty(
|
||
|
name="Object",
|
||
|
description="Import OBJ Objects into Blender Objects",
|
||
|
default=True,
|
||
|
)
|
||
|
use_split_groups = BoolProperty(
|
||
|
name="Group",
|
||
|
description="Import OBJ Groups into Blender Objects",
|
||
|
default=True,
|
||
|
)
|
||
|
|
||
|
use_groups_as_vgroups = BoolProperty(
|
||
|
name="Poly Groups",
|
||
|
description="Import OBJ groups as vertex groups",
|
||
|
default=False,
|
||
|
)
|
||
|
|
||
|
use_image_search = BoolProperty(
|
||
|
name="Image Search",
|
||
|
description="Search subdirs for any associated images "
|
||
|
"(Warning, may be slow)",
|
||
|
default=True,
|
||
|
)
|
||
|
|
||
|
split_mode = EnumProperty(
|
||
|
name="Split",
|
||
|
items=(('ON', "Split", "Split geometry, omits unused verts"),
|
||
|
('OFF', "Keep Vert Order", "Keep vertex order from file"),
|
||
|
),
|
||
|
)
|
||
|
|
||
|
global_clamp_size = FloatProperty(
|
||
|
name="Clamp Size",
|
||
|
description="Clamp bounds under this value (zero to disable)",
|
||
|
min=0.0, max=1000.0,
|
||
|
soft_min=0.0, soft_max=1000.0,
|
||
|
default=0.0,
|
||
|
)
|
||
|
|
||
|
def execute(self, context):
|
||
|
# print("Selected: " + context.active_object.name)
|
||
|
from . import import_gds
|
||
|
|
||
|
if self.split_mode == 'OFF':
|
||
|
self.use_split_objects = False
|
||
|
self.use_split_groups = False
|
||
|
else:
|
||
|
self.use_groups_as_vgroups = False
|
||
|
|
||
|
keywords = self.as_keywords(ignore=("axis_forward",
|
||
|
"axis_up",
|
||
|
"filter_glob",
|
||
|
"split_mode",
|
||
|
))
|
||
|
|
||
|
global_matrix = axis_conversion(from_forward=self.axis_forward,
|
||
|
from_up=self.axis_up,
|
||
|
).to_4x4()
|
||
|
|
||
|
keywords["global_matrix"] = global_matrix
|
||
|
keywords["use_cycles"] = (context.scene.render.engine == 'CYCLES')
|
||
|
|
||
|
if bpy.data.is_saved and context.user_preferences.filepaths.use_relative_paths:
|
||
|
import os
|
||
|
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
|
||
|
|
||
|
return import_gds.load(context, **keywords)
|
||
|
|
||
|
def draw(self, context):
|
||
|
layout = self.layout
|
||
|
|
||
|
row = layout.row(align=True)
|
||
|
row.prop(self, "use_smooth_groups")
|
||
|
row.prop(self, "use_edges")
|
||
|
|
||
|
box = layout.box()
|
||
|
row = box.row()
|
||
|
row.prop(self, "split_mode", expand=True)
|
||
|
|
||
|
row = box.row()
|
||
|
if self.split_mode == 'ON':
|
||
|
row.label(text="Split by:")
|
||
|
row.prop(self, "use_split_objects")
|
||
|
row.prop(self, "use_split_groups")
|
||
|
else:
|
||
|
row.prop(self, "use_groups_as_vgroups")
|
||
|
|
||
|
row = layout.split(percentage=0.67)
|
||
|
row.prop(self, "global_clamp_size")
|
||
|
layout.prop(self, "axis_forward")
|
||
|
layout.prop(self, "axis_up")
|
||
|
|
||
|
layout.prop(self, "use_image_search")
|
||
|
|
||
|
|
||
|
|
||
|
def menu_func_import(self, context):
|
||
|
self.layout.operator(ImportGDS.bl_idname, text="GDSII Stream (.gds)")
|
||
|
|
||
|
classes = (
|
||
|
ImportGDS,
|
||
|
)
|
||
|
|
||
|
|
||
|
def register():
|
||
|
for cls in classes:
|
||
|
bpy.utils.register_class(cls)
|
||
|
|
||
|
bpy.types.INFO_MT_file_import.append(menu_func_import)
|
||
|
|
||
|
|
||
|
def unregister():
|
||
|
bpy.types.INFO_MT_file_import.remove(menu_func_import)
|
||
|
|
||
|
for cls in classes:
|
||
|
bpy.utils.unregister_class(cls)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
register()
|