Files
MosisUnreal/Scripts/create_phone_material.py

68 lines
2.2 KiB
Python

# Unreal Editor Python script to create the Mosis phone screen material
# Run this in the Editor: File > Execute Python Script
# Or from Python console: exec(open('Scripts/create_phone_material.py').read())
import unreal
def create_phone_screen_material():
"""Create an unlit emissive material for displaying the phone screen."""
asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
material_factory = unreal.MaterialFactoryNew()
# Create the material asset
material_path = "/Game/Mosis/Materials"
material_name = "M_PhoneScreen"
# Check if material already exists
if unreal.EditorAssetLibrary.does_asset_exist(f"{material_path}/{material_name}"):
unreal.log_warning(f"Material {material_name} already exists, skipping creation")
return unreal.load_asset(f"{material_path}/{material_name}")
# Create the material
material = asset_tools.create_asset(
material_name,
material_path,
unreal.Material,
material_factory
)
if not material:
unreal.log_error("Failed to create material")
return None
# Configure material properties for phone screen display
material.set_editor_property("shading_model", unreal.MaterialShadingModel.MSM_UNLIT)
material.set_editor_property("blend_mode", unreal.BlendMode.BLEND_OPAQUE)
material.set_editor_property("two_sided", False)
# Get the material editor subsystem to add nodes
mel = unreal.MaterialEditingLibrary
# Create texture parameter node
texture_param = mel.create_material_expression(
material,
unreal.MaterialExpressionTextureSampleParameter2D,
-400, 0
)
texture_param.set_editor_property("parameter_name", "PhoneScreen")
# Connect texture RGB to emissive color
mel.connect_material_property(
texture_param, "RGB",
unreal.MaterialProperty.MP_EMISSIVE_COLOR
)
# Recompile the material
mel.recompile_material(material)
# Save the asset
unreal.EditorAssetLibrary.save_asset(f"{material_path}/{material_name}")
unreal.log(f"Created material: {material_path}/{material_name}")
return material
if __name__ == "__main__":
create_phone_screen_material()