Integrating blender import export logic

This commit is contained in:
itdominator 2021-05-23 17:00:06 -05:00
parent 7bd89c1649
commit 7e88fcc785
3 changed files with 103 additions and 125 deletions

View File

@ -15,10 +15,12 @@
#
from .msh2 import msh2
# from .msh2 import msh2
# msh_handler = msh2.MSH2(None)
from . import import_msh2, export_msh2
msh_handler = msh2.MSH2(None)
bl_info = {
"name": "Zero Editor MSH2 format",
"author": "Maxim Stewart",
@ -100,77 +102,7 @@ class ImportMSH2(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
import os
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
data = {**keywords}
msh_handler.import_file(data["filepath"])
msh = msh_handler.get_mesh_obj()
sceen = bpy.context.scene
# Test adding mesh2 to blender
for model in msh.models:
name = model.name.decode("utf-8")
# print(model)
# print(model.name)
# print(model.index)
# print(model.collection)
# print("")
# Create a mesh data block
mesh2 = bpy.data.meshes.new("{}".format(name))
verts = []
edges = []
faces = []
segments = model.segments
for segment in segments:
if segment.classname == "SegmentGeometry":
vertices = segment.vertices
for vert in vertices:
x = vert.x
y = vert.y
z = vert.z
verts.append((x, y, z))
sfaces = segment.faces
for face in sfaces:
'''Using CCW order for importing.'''
faces.append(face.SIindices())
# Add the vertices to the mesh
mesh2.from_pydata(verts, edges, faces)
# Create an object that uses the mesh data
myobj = bpy.data.objects.new("{}_obj".format(name), mesh2)
# Link the object to the scene
sceen.objects.link(myobj)
return {'FINISHED'}
# 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")
return import_msh2.load(context, **keywords)
class ExportMSH2(bpy.types.Operator, ExportHelper, IOOBJOrientationHelper):
@ -221,16 +153,8 @@ class ExportMSH2(bpy.types.Operator, ExportHelper, IOOBJOrientationHelper):
"check_existing",
"filter_glob",
))
data = {**keywords}
# msh.export_file()
# print("")
# print("")
# print(context)
# print("")
# print("")
msh.export_file(data["filepath"])
return {'FINISHED'}
return export_msh2.save(context, **keywords)

View File

@ -24,30 +24,36 @@ Note, This exports mesh objects and materials only, nurbs and curves are not sup
https://schlechtwetterfront.github.io/ze_filetypes/msh.html
"""
import bpy
from .msh2 import msh2
msh_handler = msh2.MSH2(None)
# def save(context,
# filepath,
# *,
# use_triangles=False,
# use_edges=True,
# use_normals=False,
# use_smooth_groups=False,
# use_smooth_groups_bitflags=False,
# use_uvs=True,
# use_materials=True,
# use_mesh_modifiers=True,
# use_mesh_modifiers_render=False,
# use_blen_objects=True,
# group_by_object=False,
# group_by_material=False,
# keep_vertex_order=False,
# use_vertex_groups=False,
# use_nurbs=True,
# use_selection=True,
# use_animation=False,
# global_matrix=None,
# path_mode='AUTO'
# ):
def save(context,
filepath,
*,
use_triangles=False,
use_edges=True,
use_normals=False,
use_smooth_groups=False,
use_smooth_groups_bitflags=False,
use_uvs=True,
use_materials=True,
use_mesh_modifiers=True,
use_mesh_modifiers_render=False,
use_blen_objects=True,
group_by_object=False,
group_by_material=False,
keep_vertex_order=False,
use_vertex_groups=False,
use_nurbs=True,
use_selection=True,
use_animation=False,
global_matrix=None,
path_mode='AUTO'
):
msh_handler.export_file(filepath)
return {'FINISHED'}
#
# _write(context, filepath,
# EXPORT_TRI=use_triangles,

View File

@ -24,25 +24,73 @@ Note, This loads mesh objects and materials only, nurbs and curves are not suppo
https://schlechtwetterfront.github.io/ze_filetypes/msh.html
"""
import bpy
from .msh2 import msh2
msh_handler = msh2.MSH2(None)
# def load(context,
# filepath,
# *,
# global_clamp_size=0.0,
# use_smooth_groups=True,
# use_edges=True,
# use_split_objects=True,
# use_split_groups=True,
# use_image_search=True,
# use_groups_as_vgroups=False,
# use_cycles=True,
# relpath=None,
# global_matrix=None
# ):
# """
# Called by the user interface or another script.
# load_msh2(path) - should give acceptable results.
# This function passes the file and sends the data off
# to be split into objects and then converted into mesh objects
# """
def load(context,
filepath,
*,
files,
directory,
global_clamp_size=0.0,
use_smooth_groups=True,
use_edges=True,
use_split_objects=True,
use_split_groups=True,
use_image_search=True,
use_groups_as_vgroups=False,
use_cycles=True,
relpath=None,
global_matrix=None
):
"""
Called by the user interface or another script.
load_msh2(path) - should give acceptable results.
This function passes the file and sends the data off
to be split into objects and then converted into mesh objects
"""
msh_handler.import_file(filepath)
msh = msh_handler.get_mesh_obj()
sceen = bpy.context.scene
# Test adding mesh2 to blender
for model in msh.models:
name = model.name.decode("utf-8")
# print(model)
# print(model.name)
# print(model.index)
# print(model.collection)
# print("")
# Create a mesh data block
mesh2 = bpy.data.meshes.new("{}".format(name))
verts = []
edges = []
faces = []
segments = model.segments
for segment in segments:
if segment.classname == "SegmentGeometry":
vertices = segment.vertices
for vert in vertices:
x = vert.x
y = vert.y
z = vert.z
verts.append((x, y, z))
sfaces = segment.faces
for face in sfaces:
'''Using CCW order for importing.'''
faces.append(face.SIindices())
# Add the vertices to the mesh
mesh2.from_pydata(verts, edges, faces)
# Create an object that uses the mesh data
myobj = bpy.data.objects.new("{}_obj".format(name), mesh2)
# Link the object to the scene
sceen.objects.link(myobj)
return {'FINISHED'}