WIP: MaterialX addon #104594
@ -2,18 +2,20 @@
|
|||||||
# Copyright 2022, AMD
|
# Copyright 2022, AMD
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
import nodeitems_utils
|
import nodeitems_utils
|
||||||
|
import sys
|
||||||
|
|
||||||
from . import node, categories, generate_node_classes, ui
|
from . import node, categories, generate_node_classes, ui
|
||||||
from ..utils import with_prefix
|
from .. import utils
|
||||||
|
|
||||||
|
|
||||||
|
sys.path.append(str(utils.ADDON_DATA_DIR))
|
||||||
generate_node_classes.generate_basic_classes()
|
generate_node_classes.generate_basic_classes()
|
||||||
|
|
||||||
gen_modules = [importlib.import_module(f"materialx.nodes.{f.name[:-len(f.suffix)]}")
|
gen_modules = [importlib.import_module(f"{utils.NODE_CLASSES_FOLDER}.{f.name[:-len(f.suffix)]}")
|
||||||
for f in Path(__file__).parent.glob("gen_*.py")]
|
for f in utils.NODE_CLASSES_DIR.glob("gen_*.py")]
|
||||||
|
|
||||||
mx_node_classes = []
|
mx_node_classes = []
|
||||||
for mod in gen_modules:
|
for mod in gen_modules:
|
||||||
@ -44,11 +46,11 @@ def register():
|
|||||||
register_ui()
|
register_ui()
|
||||||
register_nodes()
|
register_nodes()
|
||||||
|
|
||||||
nodeitems_utils.register_node_categories(with_prefix("MX_NODES"), categories.get_node_categories())
|
nodeitems_utils.register_node_categories(utils.with_prefix("MX_NODES"), categories.get_node_categories())
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
nodeitems_utils.unregister_node_categories(with_prefix("MX_NODES"))
|
nodeitems_utils.unregister_node_categories(utils.with_prefix("MX_NODES"))
|
||||||
|
|
||||||
unregister_nodes()
|
unregister_nodes()
|
||||||
unregister_ui()
|
unregister_ui()
|
||||||
|
@ -7,7 +7,7 @@ from collections import defaultdict
|
|||||||
import MaterialX as mx
|
import MaterialX as mx
|
||||||
|
|
||||||
from .. import utils
|
from .. import utils
|
||||||
|
from ..utils import NODE_CLASSES_DIR
|
||||||
from .. import logging
|
from .. import logging
|
||||||
log = logging.Log("nodes.generate_node_classes")
|
log = logging.Log("nodes.generate_node_classes")
|
||||||
|
|
||||||
@ -273,10 +273,10 @@ from bpy.props import (
|
|||||||
PointerProperty,
|
PointerProperty,
|
||||||
FloatVectorProperty,
|
FloatVectorProperty,
|
||||||
)
|
)
|
||||||
from .node import MxNode
|
from materialx.nodes.node import MxNode
|
||||||
|
|
||||||
|
|
||||||
FILE_PATH = r"{file_path.relative_to(utils.ADDON_ROOT_DIR)}"
|
FILE_PATH = r"{file_path}"
|
||||||
""")
|
""")
|
||||||
|
|
||||||
doc = mx.createDocument()
|
doc = mx.createDocument()
|
||||||
@ -311,7 +311,8 @@ mx_node_classes = [{', '.join(mx_node_class_names)}]
|
|||||||
|
|
||||||
|
|
||||||
def generate_basic_classes():
|
def generate_basic_classes():
|
||||||
gen_code_dir = utils.ADDON_ROOT_DIR / "nodes"
|
gen_code_dir = NODE_CLASSES_DIR
|
||||||
|
gen_code_dir.mkdir(exist_ok=True)
|
||||||
|
|
||||||
files = [
|
files = [
|
||||||
('PBR', "PBR", utils.MX_LIBS_DIR / "bxdf/standard_surface.mtlx"),
|
('PBR', "PBR", utils.MX_LIBS_DIR / "bxdf/standard_surface.mtlx"),
|
||||||
@ -332,3 +333,9 @@ def generate_basic_classes():
|
|||||||
log(f"Generating {module_file} from {file_path}")
|
log(f"Generating {module_file} from {file_path}")
|
||||||
module_code = generate_classes_code(file_path, prefix, category)
|
module_code = generate_classes_code(file_path, prefix, category)
|
||||||
module_file.write_text(module_code)
|
module_file.write_text(module_code)
|
||||||
|
|
||||||
|
module_file = gen_code_dir / "__init__.py"
|
||||||
|
module_file.write_text(
|
||||||
|
"""# Automatically generated classes for MaterialX nodes.
|
||||||
|
# Do not edit manually, changes will be overwritten.
|
||||||
|
""")
|
||||||
|
@ -16,8 +16,14 @@ log = logging.Log('utils')
|
|||||||
|
|
||||||
|
|
||||||
ADDON_ROOT_DIR = Path(__file__).parent
|
ADDON_ROOT_DIR = Path(__file__).parent
|
||||||
|
ADDON_DATA_DIR = Path(bpy.utils.user_resource("SCRIPTS", path=f"addons/{ADDON_PREFIX}", create=True))
|
||||||
|
|
||||||
MX_LIBS_FOLDER = "libraries"
|
MX_LIBS_FOLDER = "libraries"
|
||||||
MX_LIBS_DIR = ADDON_ROOT_DIR / "libraries"
|
MX_LIBS_DIR = ADDON_ROOT_DIR / MX_LIBS_FOLDER
|
||||||
|
|
||||||
|
NODE_CLASSES_FOLDER = "materialx_nodes"
|
||||||
|
NODE_CLASSES_DIR = ADDON_DATA_DIR / NODE_CLASSES_FOLDER
|
||||||
|
|
||||||
|
|
||||||
os.environ['MATERIALX_SEARCH_PATH'] = str(MX_LIBS_DIR)
|
os.environ['MATERIALX_SEARCH_PATH'] = str(MX_LIBS_DIR)
|
||||||
|
|
||||||
@ -26,13 +32,13 @@ def with_prefix(name, separator='.', upper=False):
|
|||||||
return f"{ADDON_PREFIX.upper() if upper else ADDON_PREFIX}{separator}{name}"
|
return f"{ADDON_PREFIX.upper() if upper else ADDON_PREFIX}{separator}{name}"
|
||||||
|
|
||||||
|
|
||||||
def title_str(str):
|
def title_str(val):
|
||||||
s = str.replace('_', ' ')
|
s = val.replace('_', ' ')
|
||||||
return s[:1].upper() + s[1:]
|
return s[:1].upper() + s[1:]
|
||||||
|
|
||||||
|
|
||||||
def code_str(str):
|
def code_str(val):
|
||||||
return str.replace(' ', '_').replace('.', '_')
|
return val.replace(' ', '_').replace('.', '_')
|
||||||
|
|
||||||
|
|
||||||
def set_param_value(mx_param, val, nd_type, nd_output=None):
|
def set_param_value(mx_param, val, nd_type, nd_output=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user