Commit 9b516b30 authored by frankie's avatar frankie 💬

folder reorganisation and 2.80 version of io_softskin & quad2tricross

parent 5c36ee6e
import os
import bpy
from bpy_extras.io_utils import ExportHelper
from bpy.props import (
EnumProperty,
BoolProperty,
FloatProperty,
IntProperty,
StringProperty
)
from . import constants
bl_info = {
'name': "Softskin SSM Format",
'author': "frankiezafe",
'version': (1,0,0),
'blender': (2, 80, 0),
'location': "File > Import-Export",
'description': "Export binary meshes for softskin",
'warning': "",
'wiki_url': "https://gitlab.com/frankiezafe/SoftSkin/wikis/home",
'tracker_url': "https://gitlab.com/frankiezafe/SoftSkin/issues",
'category': 'Import-Export'
}
if "bpy" in locals():
import imp
if "export_ssm" in locals():
imp.reload(export_ssm)
class ExportSSM(bpy.types.Operator, ExportHelper):
"""Tooltip"""
bl_idname = "export_object.ssm"
bl_label = "Export SSM"
bl_options = {"PRESET"}
filename_ext = ".%s" % constants.SSM_EXT
filter_glob = StringProperty(default="*.%s" % constants.SSM_EXT, options={"HIDDEN"})
dump_data = BoolProperty(
name="Console dump",
description="Dumps an overview of the data in the terminal.",
default=False,
)
generate_json = BoolProperty(
name="JSON",
description="Generate a JSON file containing the same info as the binary.",
default=False,
)
@property
def check_extension(self):
return True
def execute(self, context):
if not self.filepath:
raise Exception("filepath not set")
return
if not bpy.context.active_object:
raise Exception("no object selected")
return
from . import export_ssm
exporter = export_ssm.SSMesh()
exporter.__init__()
if exporter.load(context.active_object, self.properties.dump_data ):
if exporter.save(self.filepath, self.properties.generate_json ):
return {'FINISHED'}
return {'CANCELLED'}
def menu_func_export(self, context):
default_path = bpy.data.filepath.replace('.blend', constants.SSM_EXT)
self.layout.operator(ExportSSM.bl_idname, text="Softskin mesh (.%s)" % constants.SSM_EXT )
#operator.filepath = default_path
def register():
bpy.utils.register_class(ExportSSM)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(ExportSSM)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()
"""
All constant data used in the package should be defined here.
"""
import enum
import mathutils
# BINARY FLAGS
SOFTSKIN_VERSION = 100
SSM_NAME = "softskin mesh"
SSM_EXT = "ssm"
SSC_STRING_SIZE = 255 #num of char for free strings
SSC_MARKER_SIZE = 10 #num of char for marker strings
SSC_SSMSTARTMA = "ssmstartma"
SSC_END_MARKER = "end_marker"
SSH_GDOT_MARKER = "ssd_"
SSH_GANCHOR_MARKER = "ssa_"
SSH_GFIBER_MARKER = "ssf_"
SSH_GLIGAMENTS_MARKER = "ssl_"
class SSType(enum.IntEnum):
SSUNDEFINED = 0,
SSDOT = 1,
SSANCHOR = 2,
SSEDGE = 3,
SSFIBER = 4,
SSTENSOR = 5,
SSLIGAMENT = 6,
SSMUSCLE = 7
SSMat = mathutils.Matrix()
SSMat[0] = mathutils.Vector((-1,0,0,0))
SSMat[1] = mathutils.Vector((0,0,1,0))
SSMat[2] = mathutils.Vector((0,1,0,0))
SSMat[3] = mathutils.Vector((0,0,0,1))
\ No newline at end of file
This diff is collapsed.
import bpy
import bmesh
import mathutils
bl_info = {
"name": "Quad to Tri Cross",
'author': "frankiezafe",
'version': (1,0,0),
'blender': (2, 80, 0),
'location': "View3D > Mesh",
'description': "Turn all quads of the mesh into a cross (4) of triangles",
'warning': "",
'wiki_url': "https://gitlab.com/frankiezafe/SoftSkin/wikis/home",
'tracker_url': "https://gitlab.com/frankiezafe/SoftSkin/issues",
'category': "Mesh"
}
class Quad2TriCrossOperator(bpy.types.Operator):
bl_idname = "mesh.quad2tricross"
bl_label = "Quad to Tri Cross"
bl_options = {'REGISTER','UNDO'}
def execute(self, context):
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
def search_next_quad( mesh ):
for p in mesh.polygons:
if len(p.vertices) != 3:
p.select = True
vs = []
for i in p.vertices:
vs.append( i )
return vs
return None
vs = search_next_quad(obj.data)
while vs != None and len(vs) == 4:
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.delete(type='FACE')
# barycenter of points
bary = mathutils.Vector((0.0,0.0,0.0))
for i in vs:
bary += mathutils.Vector(obj.data.vertices[i].co)
bary /= len( vs )
bm = bmesh.from_edit_mesh(obj.data)
bm.verts.new(bary)
bmesh.update_edit_mesh(obj.data, False, True)
#select new vert
for i in range( 0, 4 ):
nexti = (i + 1) % 4
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
obj.data.vertices[ vs[i] ].select = True
obj.data.vertices[ vs[nexti] ].select = True
obj.data.vertices[ len( obj.data.vertices ) - 1 ].select = True
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.edge_face_add()
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
#vs = None
vs = search_next_quad(obj.data)
bpy.ops.object.mode_set(mode='EDIT')
return {'FINISHED'}
def quad2tricross_button(self, context):
self.layout.operator(Quad2TriCrossOperator.bl_idname)
def register():
bpy.utils.register_class(Quad2TriCrossOperator)
if __name__ != "__main__":
bpy.types.VIEW3D_MT_edit_mesh_faces.append(quad2tricross_button)
def unregister():
bpy.utils.unregister_class(Quad2TriCrossOperator)
if __name__ != "__main__":
bpy.types.VIEW3D_MT_edit_mesh_faces.remove(quad2tricross_button)
if __name__ == "__main__":
register()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment