add auto rail uv
This commit is contained in:
parent
d644c55ae4
commit
c27505b1a5
@ -8,14 +8,20 @@ bl_info={
|
|||||||
"support":"TESTING"
|
"support":"TESTING"
|
||||||
}
|
}
|
||||||
|
|
||||||
# import system
|
# ============================================= import system
|
||||||
import bpy,bpy_extras
|
import bpy,bpy_extras
|
||||||
# import my code (with reload)
|
# import my code (with reload)
|
||||||
if "bpy" in locals():
|
if "bpy" in locals():
|
||||||
import importlib
|
import importlib
|
||||||
if "bm_import_export" in locals():
|
if "bm_import_export" in locals():
|
||||||
importlib.reload(bm_import_export)
|
importlib.reload(bm_import_export)
|
||||||
from . import bm_import_export
|
if "floor_rail_uv" in locals():
|
||||||
|
importlib.reload(floor_rail_uv)
|
||||||
|
if "utils" in locals():
|
||||||
|
importlib.reload(utils)
|
||||||
|
from . import utils, bm_import_export, floor_rail_uv
|
||||||
|
|
||||||
|
# ============================================= func block
|
||||||
|
|
||||||
class ImportBM(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
|
class ImportBM(bpy.types.Operator, bpy_extras.io_utils.ImportHelper):
|
||||||
"""Load a Ballance Map File"""
|
"""Load a Ballance Map File"""
|
||||||
@ -53,19 +59,56 @@ class ExportBM(bpy.types.Operator, bpy_extras.io_utils.ExportHelper):
|
|||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
bm_import_export.export_bm(context, self.filepath, self.export_mode, self.export_target, self.no_component_suffix)
|
bm_import_export.export_bm(context, self.filepath, self.export_mode, self.export_target, self.no_component_suffix)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
# ============================================= menu system
|
||||||
|
|
||||||
|
class RailUVOperator(bpy.types.Operator):
|
||||||
|
"""Create a UV for rail"""
|
||||||
|
bl_idname = "ballance.rail_uv"
|
||||||
|
bl_label = "Create Rail UV"
|
||||||
|
bl_options = {'UNDO'}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
floor_rail_uv.create_rail_uv()
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class FloorUVOperator(bpy.types.Operator):
|
||||||
|
"""Virtoolize the UV of floor"""
|
||||||
|
bl_idname = "ballance.floor_uv"
|
||||||
|
bl_label = "Virtoolize floor UV"
|
||||||
|
bl_options = {'UNDO'}
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
floor_rail_uv.virtoolize_floor_uv()
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
class ThreeDViewerMenu(bpy.types.Menu):
|
||||||
|
bl_label = "Ballance 3D"
|
||||||
|
bl_idname = "OBJECT_MT_ballance3d_menu"
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
|
||||||
|
layout.operator("ballance.rail_uv")
|
||||||
|
layout.operator("ballance.floor_uv")
|
||||||
|
|
||||||
|
# ============================================= blender call system
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
ImportBM,
|
ImportBM,
|
||||||
ExportBM
|
ExportBM,
|
||||||
|
RailUVOperator,
|
||||||
|
FloorUVOperator,
|
||||||
|
ThreeDViewerMenu
|
||||||
)
|
)
|
||||||
|
|
||||||
def menu_func_bm_import(self, context):
|
def menu_func_bm_import(self, context):
|
||||||
self.layout.operator(ImportBM.bl_idname, text="Ballance Map (.bm)")
|
self.layout.operator(ImportBM.bl_idname, text="Ballance Map (.bm)")
|
||||||
|
|
||||||
|
|
||||||
def menu_func_bm_export(self, context):
|
def menu_func_bm_export(self, context):
|
||||||
self.layout.operator(ExportBM.bl_idname, text="Ballance Map (.bm)")
|
self.layout.operator(ExportBM.bl_idname, text="Ballance Map (.bm)")
|
||||||
|
def menu_func_ballance_3d(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.menu(ThreeDViewerMenu.bl_idname)
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
for cls in classes:
|
for cls in classes:
|
||||||
@ -73,11 +116,15 @@ def register():
|
|||||||
|
|
||||||
bpy.types.TOPBAR_MT_file_import.append(menu_func_bm_import)
|
bpy.types.TOPBAR_MT_file_import.append(menu_func_bm_import)
|
||||||
bpy.types.TOPBAR_MT_file_export.append(menu_func_bm_export)
|
bpy.types.TOPBAR_MT_file_export.append(menu_func_bm_export)
|
||||||
|
|
||||||
|
bpy.types.VIEW3D_HT_header.append(menu_func_ballance_3d)
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
bpy.types.TOPBAR_MT_file_import.remove(menu_func_bm_import)
|
bpy.types.TOPBAR_MT_file_import.remove(menu_func_bm_import)
|
||||||
bpy.types.TOPBAR_MT_file_export.remove(menu_func_bm_export)
|
bpy.types.TOPBAR_MT_file_export.remove(menu_func_bm_export)
|
||||||
|
|
||||||
|
bpy.types.VIEW3D_HT_header.remove(menu_func_ballance_3d)
|
||||||
|
|
||||||
for cls in classes:
|
for cls in classes:
|
||||||
bpy.utils.unregister_class(cls)
|
bpy.utils.unregister_class(cls)
|
||||||
|
|
||||||
|
34
ballance_blender_plugin/floor_rail_uv.py
Normal file
34
ballance_blender_plugin/floor_rail_uv.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import bpy,bmesh
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
def create_rail_uv():
|
||||||
|
meshList = []
|
||||||
|
for obj in bpy.context.selected_objects:
|
||||||
|
if obj.type != 'MESH':
|
||||||
|
continue
|
||||||
|
|
||||||
|
if obj.data.uv_layers.active.data == None:
|
||||||
|
utils.ShowMessageBox("You should create a UV layer for this object firstly. Then execute this operator.", "No UV layer", 'ERROR')
|
||||||
|
return
|
||||||
|
|
||||||
|
meshList.append(obj.data)
|
||||||
|
|
||||||
|
for mesh in meshList:
|
||||||
|
# vecList = mesh.vertices[:]
|
||||||
|
uv_layer = mesh.uv_layers.active.data
|
||||||
|
for poly in mesh.polygons:
|
||||||
|
for loop_index in range(poly.loop_start, poly.loop_start + poly.loop_total):
|
||||||
|
# index = mesh.loops[loop_index].vertex_index
|
||||||
|
uv_layer[loop_index].uv[0] = 0 # vecList[index].co[0]
|
||||||
|
uv_layer[loop_index].uv[1] = 1 # vecList[index].co[1]
|
||||||
|
|
||||||
|
|
||||||
|
def virtoolize_floor_uv():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def mesh_triangulate(me):
|
||||||
|
bm = bmesh.new()
|
||||||
|
bm.from_mesh(me)
|
||||||
|
bmesh.ops.triangulate(bm, faces=bm.faces)
|
||||||
|
bm.to_mesh(me)
|
||||||
|
bm.free()
|
8
ballance_blender_plugin/utils.py
Normal file
8
ballance_blender_plugin/utils.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import bpy
|
||||||
|
|
||||||
|
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
self.layout.label(text=message)
|
||||||
|
|
||||||
|
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
|
Loading…
Reference in New Issue
Block a user