SWBF-msh-Blender-IO/addons/io_scene_swbf_msh/msh_material_properties.py

302 lines
15 KiB
Python
Raw Permalink Normal View History

2019-11-15 03:28:09 +00:00
""" Contains Blender properties and UI for .msh materials. """
import bpy
from bpy.props import StringProperty, BoolProperty, EnumProperty, FloatVectorProperty, IntProperty
from bpy.types import PropertyGroup
from .msh_material import *
2019-11-16 15:07:47 +00:00
from .msh_material_ui_strings import *
from .msh_material_utilities import _REVERSE_RENDERTYPES_MAPPING
2019-11-15 03:28:09 +00:00
from .msh_material_operators import GenerateMaterialNodesFromSWBFProperties
2019-11-15 03:28:09 +00:00
UI_MATERIAL_RENDERTYPES = (
('NORMAL_BF2', "00 Standard (SWBF2)", UI_RENDERTYPE_NORMAL_BF2_DESC),
2019-11-16 15:07:47 +00:00
('SCROLLING_BF2', "03 Scrolling (SWBF2)", UI_RENDERTYPE_SCROLLING_BF2_DESC),
('ENVMAPPED_BF2', "06 Envmapped (SWBF2)", UI_RENDERTYPE_ENVMAPPED_BF2_DESC),
('ANIMATED_BF2', "07 Animated (SWBF2)", UI_RENDERTYPE_ANIMATED_BF2_DESC),
('REFRACTION_BF2', "22 Refractive (SWBF2)", UI_RENDERTYPE_REFRACTION_BF2_DESC),
('BLINK_BF2', "25 Blink (SWBF2)", UI_RENDERTYPE_BLINK_BF2_DESC),
('NORMALMAPPED_TILED_BF2', "24 Normalmapped Tiled (SWBF2)", UI_RENDERTYPE_NORMALMAPPED_TILED_BF2_DESC),
('NORMALMAPPED_ENVMAPPED_BF2', "26 Normalmapped Envmapped (SWBF2)", UI_RENDERTYPE_NORMALMAPPED_ENVMAPPED_BF2_DESC),
('NORMALMAPPED_BF2', "27 Normalmapped (SWBF2)", UI_RENDERTYPE_NORMALMAPPED_BF2_DESC),
('NORMALMAPPED_TILED_ENVMAPPED_BF2', "29 Normalmapped Tiled Envmapped (SWBF2)", UI_RENDERTYPE_NORMALMAPPED_TILED_ENVMAPPED_BF2_DESC),
('UNSUPPORTED', "Other (SWBF1/2)", UI_RENDERTYPE_UNSUPPORTED_BF2_DESC))
2019-11-15 03:28:09 +00:00
def _make_anim_length_entry(length):
from math import sqrt
len_sqrt = int(sqrt(length))
return (
f'FRAMES_{length}',
f"{length} ({len_sqrt}x{len_sqrt})",
f"Input texture should be laid out as {len_sqrt}x{len_sqrt} frames.")
UI_MATERIAL_ANIMATION_LENGTHS = (
('FRAMES_1', "1 (1x1)", "Why do you have an animated texture with one frame?"),
_make_anim_length_entry(4),
_make_anim_length_entry(9),
_make_anim_length_entry(16),
_make_anim_length_entry(25),
_make_anim_length_entry(36),
_make_anim_length_entry(49),
_make_anim_length_entry(64),
_make_anim_length_entry(81),
_make_anim_length_entry(100),
_make_anim_length_entry(121),
_make_anim_length_entry(144),
_make_anim_length_entry(169),
_make_anim_length_entry(196),
_make_anim_length_entry(225))
class MaterialProperties(PropertyGroup):
rendertype: EnumProperty(name="Rendertype",
description="Rendertype for the material.",
items=UI_MATERIAL_RENDERTYPES,
default='NORMAL_BF2')
specular_color: FloatVectorProperty(name="Specular Colour",
description="Specular colour of the material. "
"Can be used to tint specular highlights "
"or reduce their strength.",
default=(1.0, 1.0, 1.0),
min=0.0, max=1.0,
soft_min=0.0, soft_max=1.0,
subtype="COLOR")
blended_transparency: BoolProperty(name="Blended",
description="Enable blended transparency.",
default=False)
additive_transparency: BoolProperty(name="Additive",
description="Enable additive transparency.",
default=False)
hardedged_transparency: BoolProperty(name="Hardedged",
description="Enable hardedged (alpha cutout/clip) transparency "
"with a treshold of 0.5/0x80/128.",
default=False)
unlit: BoolProperty(name="Unlit",
description="Makes the material unlit/emissive.",
default=False)
glow: BoolProperty(name="Glow",
description="Same as 'Unlit' but also enables the use of a glowmap "
"in the diffuse texture's alpha channel. The material will be significantly "
"significantly brightened based on how opaque the glowmap is.",
default=False)
perpixel: BoolProperty(name="Per-Pixel Lighting",
2019-11-16 15:07:47 +00:00
description="Use per-pixel lighting instead of per-vertex for diffuse lighting.",
2019-11-15 03:28:09 +00:00
default=False)
specular: BoolProperty(name="Specular Lighting",
description="Use specular lighting as well as diffuse lighting. A gloss map "
2019-11-16 15:07:47 +00:00
"in the diffuse map's and normal map's alpha channel can be used "
2019-11-15 03:28:09 +00:00
"to attenuate the specular lighting's strength. (More transparent = less strong).\n\n"
2019-11-16 15:07:47 +00:00
"The Specular Colour controls the colour of the reflected specular highlights, "
"like the diffuse map but for specular lighting and global across the material.",
2019-11-15 03:28:09 +00:00
default=False)
doublesided: BoolProperty(name="Doublesided",
2019-11-16 15:07:47 +00:00
description="Disable backface culling, causing both sides of the surface to be drawn. "
"Usually only the front facing surface is drawn.",
2019-11-15 03:28:09 +00:00
default=False)
detail_map_tiling_u: IntProperty(name="Detail Map Tiling U",
2019-11-17 04:02:45 +00:00
description="Tiling of the Detail Map in the U direction. (0 = no tiling).",
2019-11-15 03:28:09 +00:00
default=0,
min=0, max=255,
soft_min=0, soft_max=255)
detail_map_tiling_v: IntProperty(name="Detail Map Tiling V",
2019-11-17 04:02:45 +00:00
description="Tiling of the Detail Map in the V direction. (0 = no tiling).",
2019-11-15 03:28:09 +00:00
default=0,
min=0, max=255,
soft_min=0, soft_max=255)
normal_map_tiling_u: IntProperty(name="Normal Map Tiling U",
2019-11-17 04:02:45 +00:00
description="Tiling of the Normal Map in the U direction. (0 = no tiling).",
2019-11-15 03:28:09 +00:00
default=0,
min=0, max=255,
soft_min=0, soft_max=255)
normal_map_tiling_v: IntProperty(name="Normal Map Tiling V",
2019-11-17 04:02:45 +00:00
description="Tiling of the Normal Map in the V direction. (0 = no tiling).",
2019-11-15 03:28:09 +00:00
default=0,
min=0, max=255,
soft_min=0, soft_max=255)
scroll_speed_u: IntProperty(name="Scroll Speed U",
description="Texture scroll speed in the U direction.",
default=0,
min=0, max=255,
soft_min=0, soft_max=255)
scroll_speed_v: IntProperty(name="Scroll Speed V",
description="Texture scroll speed in the V direction.",
default=0,
min=0, max=255,
soft_min=0, soft_max=255)
animation_length: EnumProperty(name="Animation Length",
description="Number of frames in the texture animation.",
items=UI_MATERIAL_ANIMATION_LENGTHS,
default='FRAMES_4')
animation_speed: IntProperty(name="Animation Speed",
description="Animation speed in frames per second.",
default=1,
min=0, max=255,
soft_min=0, soft_max=255)
blink_min_brightness: IntProperty(name="Blink Minimum Brightness",
description="Minimum brightness to blink between.",
default=0,
min=0, max=255,
soft_min=0, soft_max=255)
blink_speed: IntProperty(name="Blink Speed",
description="Speed of blinking, higher is faster.",
default=0,
min=0, max=255,
soft_min=0, soft_max=255)
diffuse_map: StringProperty(name="Diffuse Map",
description="The basic diffuse map for the material. The alpha channel "
2019-11-17 04:02:45 +00:00
"is either the Transparency Map, Glow Map or Gloss Map, "
2019-11-15 03:28:09 +00:00
"depending on the selected rendertype and flags.",
default="white.tga",
subtype='FILE_PATH')
2019-11-15 03:28:09 +00:00
detail_map: StringProperty(name="Detail Map",
description="Detail maps allow you to add in 'detail' to the diffuse "
"map at runtime. Or they can be used as fake ambient occlusion "
"maps or even wacky emissive maps. See docs for more details.",
subtype='FILE_PATH')
2019-11-15 03:28:09 +00:00
normal_map: StringProperty(name="Normal Map",
description="Normal maps can provide added detail from lighting. "
"If Specular is enabled the alpha channel will be "
"the Gloss Map.",
subtype='FILE_PATH')
2019-11-15 03:28:09 +00:00
environment_map: StringProperty(name="Environment Map",
description="Environment map for the material. Provides static "
"reflections around the surface. Must be a cubemap.",
subtype='FILE_PATH')
2019-11-15 03:28:09 +00:00
distortion_map: StringProperty(name="Distortion Map",
description="Distortion maps control how Refractive materials "
"distort the scene behind them. Should be a normal map "
"with '-forceformat v8u8' in it's '.tga.option' file.",
subtype='FILE_PATH')
2019-11-15 03:28:09 +00:00
# Below props are for yet unsupported render types
data_value_0: IntProperty(name="", description="First data value")
data_value_1: IntProperty(name="", description="Second data value")
rendertype_value: IntProperty(name="Rendertype Value", description="Raw number value of rendertype.", min=0, max=31)
texture_0: StringProperty(name="1", description="First texture slot", subtype='FILE_PATH', default="white.tga")
texture_1: StringProperty(name="2", description="Second texture slot", subtype='FILE_PATH')
texture_2: StringProperty(name="3", description="Third texture slot", subtype='FILE_PATH')
texture_3: StringProperty(name="4", description="Fourth texture slot", subtype='FILE_PATH')
2019-11-15 03:28:09 +00:00
class MaterialPropertiesPanel(bpy.types.Panel):
""" Creates a Panel in the Object properties window """
bl_label = "SWBF .msh Properties"
bl_idname = "MATERIAL_PT_swbf_msh"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "material"
2019-11-15 03:28:09 +00:00
def draw(self, context):
2019-11-21 10:24:26 +00:00
if context.material is None:
return
2019-11-15 03:28:09 +00:00
layout = self.layout
material_props = context.material.swbf_msh_mat
2019-11-15 03:28:09 +00:00
layout.prop(material_props, "rendertype")
if "UNSUPPORTED" in material_props.rendertype:
layout.prop(material_props, "rendertype_value")
2019-11-15 03:28:09 +00:00
layout.prop(material_props, "specular_color")
if "REFRACTION" not in material_props.rendertype:
2019-11-16 15:07:47 +00:00
layout.label(text="Transparency Flags: ")
2019-11-15 03:28:09 +00:00
row = layout.row()
2019-11-16 15:07:47 +00:00
row.prop(material_props, "blended_transparency")
row.prop(material_props, "additive_transparency")
row.prop(material_props, "hardedged_transparency")
2019-11-15 03:28:09 +00:00
2019-11-16 15:07:47 +00:00
layout.label(text="Material Flags: ")
2019-11-15 03:28:09 +00:00
row = layout.row()
2019-11-16 15:07:47 +00:00
row.prop(material_props, "unlit")
row.prop(material_props, "glow")
row = layout.row()
row.prop(material_props, "perpixel")
row.prop(material_props, "specular")
layout.prop(material_props, "doublesided")
layout.label(text="Material Data: ")
row = layout.row()
if "SCROLLING" in material_props.rendertype:
row.prop(material_props, "scroll_speed_u")
row.prop(material_props, "scroll_speed_v")
elif "ANIMATED" in material_props.rendertype:
row.prop(material_props, "animation_length")
row = layout.row()
row.prop(material_props, "animation_speed")
elif "BLINK" in material_props.rendertype:
row.prop(material_props, "blink_min_brightness")
row.prop(material_props, "blink_speed")
elif "NORMALMAPPED_TILED" in material_props.rendertype:
row.prop(material_props, "normal_map_tiling_u")
row.prop(material_props, "normal_map_tiling_v")
elif "UNSUPPORTED" in material_props.rendertype:
row.prop(material_props, "data_value_0")
row.prop(material_props, "data_value_1")
2019-11-16 15:07:47 +00:00
else:
row.prop(material_props, "detail_map_tiling_u")
row.prop(material_props, "detail_map_tiling_v")
2019-11-15 03:28:09 +00:00
layout.label(text="Texture Maps: ")
if "UNSUPPORTED" not in material_props.rendertype:
layout.prop(material_props, "diffuse_map")
2019-11-15 03:28:09 +00:00
if "REFRACTION" not in material_props.rendertype:
layout.prop(material_props, "detail_map")
if "NORMALMAPPED" in material_props.rendertype:
layout.prop(material_props, "normal_map")
2019-11-15 03:28:09 +00:00
if "ENVMAPPED" in material_props.rendertype:
layout.prop(material_props, "environment_map")
2019-11-15 03:28:09 +00:00
if "REFRACTION" in material_props.rendertype:
layout.prop(material_props, "distortion_map")
else:
layout.prop(material_props, "texture_0")
layout.prop(material_props, "texture_1")
layout.prop(material_props, "texture_2")
layout.prop(material_props, "texture_3")
2019-11-15 03:28:09 +00:00
op_props = layout.operator("swbf_msh.generate_material_nodes", text="Generate Nodes")
op_props.material_name = context.material.name
op_props.fail_silently = False