From ef459a210de8008f0a44d1eb2ff2316a25190538 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Wed, 25 Jan 2023 14:57:30 +0800 Subject: [PATCH] [feat] promote virtools material - set the default value of virtools material like virtools creation. - add preset in virtools panel for convenient using. --- .../PROPS_virtools_material.py | 50 +++++++++++++- ballance_blender_plugin/UTILS_constants.py | 69 +++++++++++++++---- .../UTILS_virtools_prop.py | 48 +++++++------ ballance_blender_plugin/__init__.py | 1 + 4 files changed, 132 insertions(+), 36 deletions(-) diff --git a/ballance_blender_plugin/PROPS_virtools_material.py b/ballance_blender_plugin/PROPS_virtools_material.py index 0aca2b2..7aa7bc8 100644 --- a/ballance_blender_plugin/PROPS_virtools_material.py +++ b/ballance_blender_plugin/PROPS_virtools_material.py @@ -43,6 +43,48 @@ class BALLANCE_OT_parse_virtools_material(bpy.types.Operator): return {'FINISHED'} +class BALLANCE_OT_preset_virtools_material(bpy.types.Operator): + """Preset Virtools Material with Original Ballance Data.""" + bl_idname = "ballance.preset_virtools_material" + bl_label = "Preset Virtools Material" + bl_options = {'UNDO'} + + preset_type: bpy.props.EnumProperty( + name="Preset", + description="The preset which you want to apply.", + items=tuple( + (str(idx), item["human-readable"], "Suit for: " + ", ".join(item["member"])) + for idx, item in enumerate(UTILS_constants.floor_materialStatistic) + ), + ) + + @classmethod + def poll(cls, context): + return context.material is not None + + def invoke(self, context, event): + wm = context.window_manager + return wm.invoke_props_dialog(self) + + def draw(self, context): + self.layout.prop(self, "preset_type") + + def execute(self, context): + preset_idx = int(self.preset_type) + preset_data = UTILS_constants.floor_materialStatistic[preset_idx] + + # get data self and only change core colors + mtl = context.material + vtmtl = UTILS_virtools_prop.get_virtools_material(mtl) + + vtmtl.ambient = preset_data['data']['ambient'] + vtmtl.diffuse = preset_data['data']['diffuse'] + vtmtl.specular = preset_data['data']['specular'] + vtmtl.emissive = preset_data['data']['emissive'] + vtmtl.specular_power = preset_data['data']['power'] + + return {'FINISHED'} + class BALLANCE_PT_virtools_material(bpy.types.Panel): """Show Virtools Material Properties.""" bl_label = "Virtools Material" @@ -69,7 +111,9 @@ class BALLANCE_PT_virtools_material(bpy.types.Panel): layout.enabled = target.enable_virtools_material # draw layout - layout.label(text="Basic Parameters") + row = layout.row() + row.label(text="Basic Parameters") + row.operator(BALLANCE_OT_preset_virtools_material.bl_idname, text="", icon="PRESET") layout.prop(target, 'ambient') layout.prop(target, 'diffuse') layout.prop(target, 'specular') @@ -86,6 +130,6 @@ class BALLANCE_PT_virtools_material(bpy.types.Panel): layout.separator() layout.label(text="Operations") - layout.operator("ballance.apply_virtools_material", icon="NODETREE") - layout.operator("ballance.parse_virtools_material", icon="HIDE_OFF") + layout.operator(BALLANCE_OT_apply_virtools_material.bl_idname, icon="NODETREE") + layout.operator(BALLANCE_OT_parse_virtools_material.bl_idname, icon="HIDE_OFF") diff --git a/ballance_blender_plugin/UTILS_constants.py b/ballance_blender_plugin/UTILS_constants.py index ab0397b..8bd585f 100644 --- a/ballance_blender_plugin/UTILS_constants.py +++ b/ballance_blender_plugin/UTILS_constants.py @@ -169,13 +169,14 @@ floor_textureReflactionMap = { "BallStone": "Ball_Stone.bmp" } -# WARNING: this data is shared with `BallanceVirtoolsPlugin/bvh/features/mapping/fix_texture.cpp` +# WARNING: this data is shared with `BallanceVirtoolsPlugin/bvh/features/mapping/bmfile_fix_texture.cpp` floor_materialStatistic = [ { + "human-readable": "Floor Side", "member": [ - "FloorSide", - "FloorTopBorder_ForSide", - "FloorTopBorderless_ForSide" + "FloorSide", + "FloorTopBorder_ForSide", + "FloorTopBorderless_ForSide" ], "data": { "ambient": (0, 0, 0), @@ -186,12 +187,13 @@ floor_materialStatistic = [ } }, { + "human-readable": "Floor Top", "member": [ - "FloorTopBorder", - "FloorTopBorderless", - "FloorTopFlat", - "FloorTopProfil", - "FloorTopProfilFlat" + "FloorTopBorder", + "FloorTopBorderless", + "FloorTopFlat", + "FloorTopProfil", + "FloorTopProfilFlat" ], "data": { "ambient": (0, 0, 0), @@ -202,8 +204,9 @@ floor_materialStatistic = [ } }, { + "human-readable": "Transform Paper", "member": [ - "BallPaper" + "BallPaper" ], "data": { "ambient": (25 / 255.0, 25 / 255.0, 25 / 255.0), @@ -213,10 +216,11 @@ floor_materialStatistic = [ "power": 0 } }, - { + { + "human-readable": "Transform Stone & Wood", "member": [ - "BallStone", - "BallWood" + "BallStone", + "BallWood" ], "data": { "ambient": (25 / 255.0, 25 / 255.0, 25 / 255.0), @@ -225,6 +229,45 @@ floor_materialStatistic = [ "emissive": (60 / 255.0, 60 / 255.0, 60 / 255.0), "power": 0 } + }, + { + "human-readable": "Rail", + "member": [ + "Rail" + ], + "data": { + "ambient": (0.0, 0.0, 0.0), + "diffuse": (100 / 255.0, 118 / 255.0, 133 / 255.0), + "specular": (210 / 255.0, 210 / 255.0, 210 / 255.0), + "emissive": (124 / 255.0, 134 / 255.0, 150 / 255.0), + "power": 10 + } + }, + { + "human-readable": "Wood Path", + "member": [ + "WoodPanel" + ], + "data": { + "ambient": (2 / 255.0, 2 / 255.0, 2 / 255.0), + "diffuse": (1.0, 1.0, 1.0), + "specular": (59 / 255.0, 59 / 255.0, 59 / 255.0), + "emissive": (30 / 255.0, 30 / 255.0, 30 / 255.0), + "power": 25 + } + }, + { + "human-readable": "Wood Chip", + "member": [ + "WoodPlain2" + ], + "data": { + "ambient": (25 / 255.0, 25 / 255.0, 25 / 255.0), + "diffuse": (1.0, 1.0, 1.0), + "specular": (100 / 255.0, 100 / 255.0, 100 / 255.0), + "emissive": (50 / 255.0, 50 / 255.0, 50 / 255.0), + "power": 50 + } } ] diff --git a/ballance_blender_plugin/UTILS_virtools_prop.py b/ballance_blender_plugin/UTILS_virtools_prop.py index 3a24a68..c881c88 100644 --- a/ballance_blender_plugin/UTILS_virtools_prop.py +++ b/ballance_blender_plugin/UTILS_virtools_prop.py @@ -7,29 +7,37 @@ class BALLANCE_PG_virtools_material(bpy.types.PropertyGroup): default=False, ) - ambient: bpy.props.FloatVectorProperty(name="Ambient", - subtype='COLOR', - min=0.0, - max=1.0, - default=[0.0,0.0,0.0]) + ambient: bpy.props.FloatVectorProperty( + name="Ambient", + subtype='COLOR', + min=0.0, + max=1.0, + default=[76 / 255, 76 / 255, 76 / 255] + ) - diffuse: bpy.props.FloatVectorProperty(name="Diffuse", - subtype='COLOR', - min=0.0, - max=1.0, - default=[0.0,0.0,0.0]) + diffuse: bpy.props.FloatVectorProperty( + name="Diffuse", + subtype='COLOR', + min=0.0, + max=1.0, + default=[178 / 255, 178 / 255, 178 / 255] + ) - specular: bpy.props.FloatVectorProperty(name="Specular", - subtype='COLOR', - min=0.0, - max=1.0, - default=[0.0,0.0,0.0]) + specular: bpy.props.FloatVectorProperty( + name="Specular", + subtype='COLOR', + min=0.0, + max=1.0, + default=[127 / 255, 127 / 255, 127 / 255] + ) - emissive: bpy.props.FloatVectorProperty(name="Emissive", - subtype='COLOR', - min=0.0, - max=1.0, - default=[0.0,0.0,0.0]) + emissive: bpy.props.FloatVectorProperty( + name="Emissive", + subtype='COLOR', + min=0.0, + max=1.0, + default=[0.0, 0.0, 0.0] + ) specular_power: bpy.props.FloatProperty( name="Specular Power", diff --git a/ballance_blender_plugin/__init__.py b/ballance_blender_plugin/__init__.py index d2484a9..3f09e9c 100644 --- a/ballance_blender_plugin/__init__.py +++ b/ballance_blender_plugin/__init__.py @@ -153,6 +153,7 @@ classes = ( PROPS_virtools_group.BALLANCE_PT_virtools_group, PROPS_virtools_material.BALLANCE_OT_apply_virtools_material, PROPS_virtools_material.BALLANCE_OT_parse_virtools_material, + PROPS_virtools_material.BALLANCE_OT_preset_virtools_material, PROPS_virtools_material.BALLANCE_PT_virtools_material, OBJS_group_opers.BALLANCE_OT_select_virtools_group,