update message box and rail_uv
This commit is contained in:
parent
a8203dcb9c
commit
35655a671d
@ -105,7 +105,7 @@ def import_bm(context,filepath,externalTexture,blenderTempFolder, textureOpt, ma
|
||||
# judge version first
|
||||
gotten_version = read_uint32(findex)
|
||||
if (gotten_version != bm_current_version):
|
||||
utils.ShowMessageBox("Unsupported BM spec. Expect: {} Gotten: {}".format(bm_current_version, gotten_version), "Unsupported BM spec", 'WARNING')
|
||||
utils.ShowMessageBox(("Unsupported BM spec. Expect: {} Gotten: {}".format(bm_current_version, gotten_version), ), "Unsupported BM spec", 'ERROR')
|
||||
findex.close()
|
||||
tempFolderObj.cleanup()
|
||||
return
|
||||
|
@ -33,13 +33,16 @@ def check_target():
|
||||
if obj.data.uv_layers.active is None:
|
||||
noUVObject.append(obj.name)
|
||||
|
||||
result = ("All objects: {}, Skipped: {}, No UV Count: {}. Following object don't have UV: ".format(len(bpy.context.selected_objects), invalidObjectCount, len(noUVObject)) +
|
||||
", ".join(noUVObject[:4]) +
|
||||
(". Too much objects don't have UV. Please open terminal to browse them." if len(noUVObject) > 4 else ""))
|
||||
|
||||
if len(noUVObject) > 4:
|
||||
print("Following object don't have UV:")
|
||||
for item in noUVObject:
|
||||
print(item)
|
||||
|
||||
utils.ShowMessageBox(result, "Check result", 'INFO')
|
||||
utils.ShowMessageBox((
|
||||
"All objects: {}".format(len(bpy.context.selected_objects)),
|
||||
"Skipped: {}".format(invalidObjectCount),
|
||||
"No UV Count: {}".format(len(noUVObject)),
|
||||
"",
|
||||
"Following object don't have UV: "
|
||||
) + tuple(noUVObject[:4]) +
|
||||
(("Too much objects don't have UV. Please open terminal to browse them." if len(noUVObject) > 4 else "") ,), "Check result", 'INFO')
|
||||
|
@ -1,4 +1,5 @@
|
||||
import bpy,bmesh
|
||||
import mathutils
|
||||
import bpy.types
|
||||
from . import utils, preferences
|
||||
|
||||
@ -34,7 +35,10 @@ class BALLANCE_OT_rail_uv(bpy.types.Operator):
|
||||
return wm.invoke_props_dialog(self)
|
||||
|
||||
def execute(self, context):
|
||||
create_rail_uv()
|
||||
if context.scene.BallanceBlenderPluginProperty.material_picker == None:
|
||||
utils.ShowMessageBox(("No specific material", ), "Lost parameter", 'ERROR')
|
||||
else:
|
||||
create_rail_uv(self.uv_type, context.scene.BallanceBlenderPluginProperty.material_picker, self.uv_scale)
|
||||
return {'FINISHED'}
|
||||
|
||||
def draw(self, context):
|
||||
@ -55,8 +59,8 @@ def check_rail_target():
|
||||
return True
|
||||
return False
|
||||
|
||||
def create_rail_uv():
|
||||
meshList = []
|
||||
def create_rail_uv(rail_type, material_pointer, scale_size):
|
||||
objList = []
|
||||
ignoredObj = []
|
||||
for obj in bpy.context.selected_objects:
|
||||
if obj.type != 'MESH':
|
||||
@ -69,16 +73,42 @@ def create_rail_uv():
|
||||
# create a empty uv for it.
|
||||
obj.data.uv_layers.new(do_init=False)
|
||||
|
||||
meshList.append(obj.data)
|
||||
objList.append(obj)
|
||||
|
||||
for mesh in meshList:
|
||||
# vecList = mesh.vertices[:]
|
||||
for obj in objList:
|
||||
mesh = obj.data
|
||||
|
||||
# clean it material and set rail first
|
||||
obj.data.materials.clear()
|
||||
obj.data.materials.append(material_pointer)
|
||||
|
||||
real_scale = 1.0
|
||||
if rail_type == 'SCALE':
|
||||
real_scale = scale_size
|
||||
elif rail_type == 'UNIFORM':
|
||||
# calc proper scale
|
||||
targetObjBbox = [mathutils.Vector(corner) for corner in obj.bound_box]
|
||||
maxLength = max(
|
||||
max([vec.x for vec in targetObjBbox]) - min([vec.x for vec in targetObjBbox]),
|
||||
max([vec.y for vec in targetObjBbox]) - min([vec.y for vec in targetObjBbox])
|
||||
)
|
||||
real_scale = 1.0 / maxLength
|
||||
|
||||
# copy mesh vec for scale or uniform mode
|
||||
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]
|
||||
# get correspond vec index
|
||||
index = mesh.loops[loop_index].vertex_index
|
||||
if rail_type == 'POINT':
|
||||
# set to 1 point
|
||||
uv_layer[loop_index].uv[0] = 0
|
||||
uv_layer[loop_index].uv[1] = 1
|
||||
else:
|
||||
# following xy -> uv scale
|
||||
uv_layer[loop_index].uv[0] = vecList[index].co[0] * real_scale
|
||||
uv_layer[loop_index].uv[1] = vecList[index].co[1] * real_scale
|
||||
|
||||
if len(ignoredObj) != 0:
|
||||
utils.ShowMessageBox("Following objects are not processed due to they are not suit for this function now: " + ', '.join(ignoredObj), "Execution result", 'INFO')
|
||||
utils.ShowMessageBox(("Following objects are not processed due to they are not suit for this function now: ", ) + tuple(ignoredObj), "Execution result", 'INFO')
|
||||
|
@ -1,9 +1,11 @@
|
||||
import bpy
|
||||
from bpy_extras.io_utils import unpack_list
|
||||
|
||||
def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):
|
||||
def ShowMessageBox(message, title, icon):
|
||||
|
||||
def draw(self, context):
|
||||
self.layout.label(text=message)
|
||||
layout = self.layout
|
||||
for item in message:
|
||||
layout.label(text=item, translate=False)
|
||||
|
||||
bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)
|
||||
|
Loading…
Reference in New Issue
Block a user