2020-11-17 11:59:21 +01:00
|
|
|
from typing import Callable, Dict, Optional
|
2018-01-04 16:22:16 +01:00
|
|
|
|
2020-11-17 18:54:53 +01:00
|
|
|
from bpy.types import Material, UILayout
|
2018-01-04 16:22:16 +01:00
|
|
|
|
2021-08-11 14:32:21 +02:00
|
|
|
import arm
|
2020-11-17 11:59:21 +01:00
|
|
|
from arm.material.shader import ShaderContext
|
2018-01-04 16:22:16 +01:00
|
|
|
|
2021-08-11 14:32:21 +02:00
|
|
|
if arm.is_reload(__name__):
|
2021-08-04 22:49:38 +02:00
|
|
|
arm.material.shader = arm.reload_module(arm.material.shader)
|
|
|
|
from arm.material.shader import ShaderContext
|
|
|
|
else:
|
|
|
|
drivers: Dict[str, Dict] = dict()
|
|
|
|
|
2021-08-11 14:32:21 +02:00
|
|
|
arm.enable_reload(__name__)
|
2018-01-04 16:22:16 +01:00
|
|
|
|
|
|
|
|
2020-11-17 11:59:21 +01:00
|
|
|
def add_driver(driver_name: str,
|
2020-11-17 18:54:53 +01:00
|
|
|
make_rpass: Callable[[str], Optional[ShaderContext]], make_rpath: Callable[[], None],
|
2020-11-18 08:41:28 +01:00
|
|
|
draw_props: Optional[Callable[[UILayout], None]], draw_mat_props: Optional[Callable[[UILayout, Material], None]]) -> None:
|
2020-11-17 11:59:21 +01:00
|
|
|
"""Register a new driver. If there already exists a driver with the given name, nothing happens.
|
|
|
|
|
2020-11-17 18:54:53 +01:00
|
|
|
@param driver_name Unique name for the new driver that will be displayed in the UI.
|
2020-11-17 11:59:21 +01:00
|
|
|
@param make_rpass Function to create render passes. Takes the rpass name as a parameter and may return `None`.
|
|
|
|
@param make_rpath Function to setup the render path.
|
2020-11-18 08:41:28 +01:00
|
|
|
@param draw_props Function to draw global driver properties inside the render path panel, may be `None`.
|
|
|
|
@param draw_mat_props Function to draw per-material driver properties in the material tab, may be `None`.
|
2020-11-17 11:59:21 +01:00
|
|
|
"""
|
|
|
|
global drivers
|
|
|
|
|
|
|
|
if driver_name in drivers:
|
|
|
|
return
|
|
|
|
|
|
|
|
drivers[driver_name] = {
|
|
|
|
'driver_name': driver_name,
|
|
|
|
'make_rpass': make_rpass,
|
2020-11-17 18:54:53 +01:00
|
|
|
'make_rpath': make_rpath,
|
|
|
|
'draw_props': draw_props,
|
|
|
|
'draw_mat_props': draw_mat_props
|
2020-11-17 11:59:21 +01:00
|
|
|
}
|