add rail_uv projection param. Update export bm UI (use PointerProperty)
This commit is contained in:
parent
ac9d196e3e
commit
582e96615a
@ -65,19 +65,29 @@ class BALLANCE_OT_export_bm(bpy.types.Operator, bpy_extras.io_utils.ExportHelper
|
|||||||
|
|
||||||
export_mode: bpy.props.EnumProperty(
|
export_mode: bpy.props.EnumProperty(
|
||||||
name="Export mode",
|
name="Export mode",
|
||||||
items=(('COLLECTION', "Selected collection", "Export the selected collection"),
|
items=(('COLLECTION', "Collection", "Export a collection"),
|
||||||
('OBJECT', "Selected objects", "Export the selected objects"),
|
('OBJECT', "Objects", "Export an objects"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
export_target: bpy.props.StringProperty(
|
|
||||||
name="Export target",
|
|
||||||
description="Which one will be exported",
|
|
||||||
)
|
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
export_bm(context, self.filepath, self.export_mode, self.export_target)
|
if (self.export_mode == 'COLLECTION' and context.scene.BallanceBlenderPluginProperty.collection_picker is None) or (self.export_mode == 'OBJECT' and context.scene.BallanceBlenderPluginProperty.object_picker is None):
|
||||||
|
utils.ShowMessageBox(("No specific target", ), "Lost parameter", 'ERROR')
|
||||||
|
else:
|
||||||
|
if self.export_mode == 'COLLECTION':
|
||||||
|
export_bm(context, self.filepath, self.export_mode, context.scene.BallanceBlenderPluginProperty.collection_picker)
|
||||||
|
elif self.export_mode == 'OBJECT':
|
||||||
|
export_bm(context, self.filepath, self.export_mode, context.scene.BallanceBlenderPluginProperty.object_picker)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.prop(self, "export_mode")
|
||||||
|
if self.export_mode == 'COLLECTION':
|
||||||
|
layout.prop(context.scene.BallanceBlenderPluginProperty, "collection_picker")
|
||||||
|
elif self.export_mode == 'OBJECT':
|
||||||
|
layout.prop(context.scene.BallanceBlenderPluginProperty, "object_picker")
|
||||||
|
|
||||||
# ========================================== method
|
# ========================================== method
|
||||||
|
|
||||||
bm_current_version = 12
|
bm_current_version = 12
|
||||||
@ -332,7 +342,7 @@ def import_bm(context,filepath,externalTexture,blenderTempFolder, textureOpt, ma
|
|||||||
|
|
||||||
tempFolderObj.cleanup()
|
tempFolderObj.cleanup()
|
||||||
|
|
||||||
def export_bm(context,filepath,export_mode, export_target):
|
def export_bm(context, filepath, export_mode, export_target):
|
||||||
# ============================================ alloc a temp folder
|
# ============================================ alloc a temp folder
|
||||||
tempFolderObj = tempfile.TemporaryDirectory()
|
tempFolderObj = tempfile.TemporaryDirectory()
|
||||||
tempFolder = tempFolderObj.name
|
tempFolder = tempFolderObj.name
|
||||||
@ -344,9 +354,9 @@ def export_bm(context,filepath,export_mode, export_target):
|
|||||||
|
|
||||||
# ============================================ find export target. don't need judge them in there. just collect them
|
# ============================================ find export target. don't need judge them in there. just collect them
|
||||||
if export_mode== "COLLECTION":
|
if export_mode== "COLLECTION":
|
||||||
objectList = bpy.data.collections[export_target].objects
|
objectList = export_target.objects
|
||||||
else:
|
else:
|
||||||
objectList = [bpy.data.objects[export_target]]
|
objectList = [export_target]
|
||||||
|
|
||||||
# try get forcedCollection
|
# try get forcedCollection
|
||||||
try:
|
try:
|
||||||
|
@ -8,6 +8,18 @@ class MyPropertyGroup(bpy.types.PropertyGroup):
|
|||||||
description="The material used for rail"
|
description="The material used for rail"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
collection_picker : bpy.props.PointerProperty(
|
||||||
|
type=bpy.types.Collection,
|
||||||
|
name="Collection",
|
||||||
|
description="The collection which will be exported"
|
||||||
|
)
|
||||||
|
|
||||||
|
object_picker : bpy.props.PointerProperty(
|
||||||
|
type=bpy.types.Object,
|
||||||
|
name="Object",
|
||||||
|
description="The object which will be exported"
|
||||||
|
)
|
||||||
|
|
||||||
class BallanceBlenderPluginPreferences(bpy.types.AddonPreferences):
|
class BallanceBlenderPluginPreferences(bpy.types.AddonPreferences):
|
||||||
bl_idname = __package__
|
bl_idname = __package__
|
||||||
|
|
||||||
|
@ -19,6 +19,16 @@ class BALLANCE_OT_rail_uv(bpy.types.Operator):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
projection_axis: bpy.props.EnumProperty(
|
||||||
|
name="Projection axis",
|
||||||
|
description="Projection axis",
|
||||||
|
items=(
|
||||||
|
("X", "X axis", "X axis"),
|
||||||
|
("Y", "Y axis", "Y axis"),
|
||||||
|
("Z", "Z axis", "Z axis")
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
uv_scale : bpy.props.FloatProperty(
|
uv_scale : bpy.props.FloatProperty(
|
||||||
name="Scale",
|
name="Scale",
|
||||||
description="The scale of UV",
|
description="The scale of UV",
|
||||||
@ -38,13 +48,15 @@ class BALLANCE_OT_rail_uv(bpy.types.Operator):
|
|||||||
if context.scene.BallanceBlenderPluginProperty.material_picker == None:
|
if context.scene.BallanceBlenderPluginProperty.material_picker == None:
|
||||||
utils.ShowMessageBox(("No specific material", ), "Lost parameter", 'ERROR')
|
utils.ShowMessageBox(("No specific material", ), "Lost parameter", 'ERROR')
|
||||||
else:
|
else:
|
||||||
create_rail_uv(self.uv_type, context.scene.BallanceBlenderPluginProperty.material_picker, self.uv_scale)
|
create_rail_uv(self.uv_type, context.scene.BallanceBlenderPluginProperty.material_picker, self.uv_scale, self.projection_axis)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
def draw(self, context):
|
def draw(self, context):
|
||||||
layout = self.layout
|
layout = self.layout
|
||||||
layout.prop(self, "uv_type")
|
layout.prop(self, "uv_type")
|
||||||
layout.prop(context.scene.BallanceBlenderPluginProperty, "material_picker")
|
layout.prop(context.scene.BallanceBlenderPluginProperty, "material_picker")
|
||||||
|
if self.uv_type != 'POINT':
|
||||||
|
layout.prop(self, "projection_axis")
|
||||||
if self.uv_type == 'SCALE':
|
if self.uv_type == 'SCALE':
|
||||||
layout.prop(self, "uv_scale")
|
layout.prop(self, "uv_scale")
|
||||||
|
|
||||||
@ -81,7 +93,7 @@ def get_distance(iterator):
|
|||||||
|
|
||||||
return max_value - min_value
|
return max_value - min_value
|
||||||
|
|
||||||
def create_rail_uv(rail_type, material_pointer, scale_size):
|
def create_rail_uv(rail_type, material_pointer, scale_size, projection_axis):
|
||||||
objList = []
|
objList = []
|
||||||
ignoredObj = []
|
ignoredObj = []
|
||||||
for obj in bpy.context.selected_objects:
|
for obj in bpy.context.selected_objects:
|
||||||
@ -111,10 +123,21 @@ def create_rail_uv(rail_type, material_pointer, scale_size):
|
|||||||
real_scale = scale_size
|
real_scale = scale_size
|
||||||
elif rail_type == 'UNIFORM':
|
elif rail_type == 'UNIFORM':
|
||||||
# calc proper scale
|
# calc proper scale
|
||||||
maxLength = max(
|
if projection_axis == 'X':
|
||||||
get_distance(vec.co[0] for vec in vecList),
|
maxLength = max(
|
||||||
get_distance(vec.co[1] for vec in vecList)
|
get_distance(vec.co[1] for vec in vecList),
|
||||||
)
|
get_distance(vec.co[2] for vec in vecList)
|
||||||
|
)
|
||||||
|
elif projection_axis == 'Y':
|
||||||
|
maxLength = max(
|
||||||
|
get_distance(vec.co[0] for vec in vecList),
|
||||||
|
get_distance(vec.co[2] for vec in vecList)
|
||||||
|
)
|
||||||
|
elif projection_axis == 'Z':
|
||||||
|
maxLength = max(
|
||||||
|
get_distance(vec.co[0] for vec in vecList),
|
||||||
|
get_distance(vec.co[1] for vec in vecList)
|
||||||
|
)
|
||||||
real_scale = 1.0 / maxLength
|
real_scale = 1.0 / maxLength
|
||||||
|
|
||||||
uv_layer = mesh.uv_layers.active.data
|
uv_layer = mesh.uv_layers.active.data
|
||||||
@ -128,8 +151,19 @@ def create_rail_uv(rail_type, material_pointer, scale_size):
|
|||||||
uv_layer[loop_index].uv[1] = 1
|
uv_layer[loop_index].uv[1] = 1
|
||||||
else:
|
else:
|
||||||
# following xy -> uv scale
|
# 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
|
# use Z axis: X->U Y->V
|
||||||
|
# use X axis: Y->U Z->V
|
||||||
|
# use Y axis: X->U Z->V
|
||||||
|
if projection_axis == 'X':
|
||||||
|
uv_layer[loop_index].uv[0] = vecList[index].co[1] * real_scale
|
||||||
|
uv_layer[loop_index].uv[1] = vecList[index].co[2] * real_scale
|
||||||
|
elif projection_axis == 'Y':
|
||||||
|
uv_layer[loop_index].uv[0] = vecList[index].co[0] * real_scale
|
||||||
|
uv_layer[loop_index].uv[1] = vecList[index].co[2] * real_scale
|
||||||
|
elif projection_axis == 'Z':
|
||||||
|
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:
|
if len(ignoredObj) != 0:
|
||||||
utils.ShowMessageBox(("Following objects are not processed due to they are not suit for this function now: ", ) + tuple(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')
|
||||||
|
Loading…
Reference in New Issue
Block a user