Integrating blender import export logic
This commit is contained in:
parent
7bd89c1649
commit
7e88fcc785
|
@ -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 = {
|
bl_info = {
|
||||||
"name": "Zero Editor MSH2 format",
|
"name": "Zero Editor MSH2 format",
|
||||||
"author": "Maxim Stewart",
|
"author": "Maxim Stewart",
|
||||||
|
@ -100,77 +102,7 @@ class ImportMSH2(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
|
||||||
import os
|
import os
|
||||||
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
|
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
|
||||||
|
|
||||||
data = {**keywords}
|
return import_msh2.load(context, **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")
|
|
||||||
|
|
||||||
|
|
||||||
class ExportMSH2(bpy.types.Operator, ExportHelper, IOOBJOrientationHelper):
|
class ExportMSH2(bpy.types.Operator, ExportHelper, IOOBJOrientationHelper):
|
||||||
|
@ -221,16 +153,8 @@ class ExportMSH2(bpy.types.Operator, ExportHelper, IOOBJOrientationHelper):
|
||||||
"check_existing",
|
"check_existing",
|
||||||
"filter_glob",
|
"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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
https://schlechtwetterfront.github.io/ze_filetypes/msh.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
from .msh2 import msh2
|
||||||
|
msh_handler = msh2.MSH2(None)
|
||||||
|
|
||||||
# def save(context,
|
def save(context,
|
||||||
# filepath,
|
filepath,
|
||||||
# *,
|
*,
|
||||||
# use_triangles=False,
|
use_triangles=False,
|
||||||
# use_edges=True,
|
use_edges=True,
|
||||||
# use_normals=False,
|
use_normals=False,
|
||||||
# use_smooth_groups=False,
|
use_smooth_groups=False,
|
||||||
# use_smooth_groups_bitflags=False,
|
use_smooth_groups_bitflags=False,
|
||||||
# use_uvs=True,
|
use_uvs=True,
|
||||||
# use_materials=True,
|
use_materials=True,
|
||||||
# use_mesh_modifiers=True,
|
use_mesh_modifiers=True,
|
||||||
# use_mesh_modifiers_render=False,
|
use_mesh_modifiers_render=False,
|
||||||
# use_blen_objects=True,
|
use_blen_objects=True,
|
||||||
# group_by_object=False,
|
group_by_object=False,
|
||||||
# group_by_material=False,
|
group_by_material=False,
|
||||||
# keep_vertex_order=False,
|
keep_vertex_order=False,
|
||||||
# use_vertex_groups=False,
|
use_vertex_groups=False,
|
||||||
# use_nurbs=True,
|
use_nurbs=True,
|
||||||
# use_selection=True,
|
use_selection=True,
|
||||||
# use_animation=False,
|
use_animation=False,
|
||||||
# global_matrix=None,
|
global_matrix=None,
|
||||||
# path_mode='AUTO'
|
path_mode='AUTO'
|
||||||
# ):
|
):
|
||||||
|
|
||||||
|
msh_handler.export_file(filepath)
|
||||||
|
return {'FINISHED'}
|
||||||
#
|
#
|
||||||
# _write(context, filepath,
|
# _write(context, filepath,
|
||||||
# EXPORT_TRI=use_triangles,
|
# EXPORT_TRI=use_triangles,
|
||||||
|
|
|
@ -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
|
https://schlechtwetterfront.github.io/ze_filetypes/msh.html
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
from .msh2 import msh2
|
||||||
|
msh_handler = msh2.MSH2(None)
|
||||||
|
|
||||||
|
|
||||||
# def load(context,
|
def load(context,
|
||||||
# filepath,
|
filepath,
|
||||||
# *,
|
*,
|
||||||
# global_clamp_size=0.0,
|
files,
|
||||||
# use_smooth_groups=True,
|
directory,
|
||||||
# use_edges=True,
|
global_clamp_size=0.0,
|
||||||
# use_split_objects=True,
|
use_smooth_groups=True,
|
||||||
# use_split_groups=True,
|
use_edges=True,
|
||||||
# use_image_search=True,
|
use_split_objects=True,
|
||||||
# use_groups_as_vgroups=False,
|
use_split_groups=True,
|
||||||
# use_cycles=True,
|
use_image_search=True,
|
||||||
# relpath=None,
|
use_groups_as_vgroups=False,
|
||||||
# global_matrix=None
|
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
|
Called by the user interface or another script.
|
||||||
# to be split into objects and then converted into mesh objects
|
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'}
|
||||||
|
|
Loading…
Reference in New Issue