WIP: MaterialX addon #104594

Closed
Bogdan Nagirniak wants to merge 34 commits from BogdanNagirniak/blender-addons:materialx-addon into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 30 additions and 15 deletions
Showing only changes of commit e50fcd0df3 - Show all commits

View File

@ -2,18 +2,20 @@
# Copyright 2022, AMD
import importlib
from pathlib import Path
import bpy
import nodeitems_utils
import sys
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()
gen_modules = [importlib.import_module(f"materialx.nodes.{f.name[:-len(f.suffix)]}")
for f in Path(__file__).parent.glob("gen_*.py")]
gen_modules = [importlib.import_module(f"{utils.NODE_CLASSES_FOLDER}.{f.name[:-len(f.suffix)]}")
for f in utils.NODE_CLASSES_DIR.glob("gen_*.py")]
mx_node_classes = []
for mod in gen_modules:
@ -44,11 +46,11 @@ def register():
register_ui()
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():
nodeitems_utils.unregister_node_categories(with_prefix("MX_NODES"))
nodeitems_utils.unregister_node_categories(utils.with_prefix("MX_NODES"))
unregister_nodes()
unregister_ui()

View File

@ -7,7 +7,7 @@ from collections import defaultdict
import MaterialX as mx
from .. import utils
from ..utils import NODE_CLASSES_DIR
from .. import logging
log = logging.Log("nodes.generate_node_classes")
@ -273,10 +273,10 @@ from bpy.props import (
PointerProperty,
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()
@ -311,7 +311,8 @@ mx_node_classes = [{', '.join(mx_node_class_names)}]
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 = [
('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}")
module_code = generate_classes_code(file_path, prefix, category)
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.
""")

View File

@ -16,8 +16,14 @@ log = logging.Log('utils')
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_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)
@ -26,13 +32,13 @@ def with_prefix(name, separator='.', upper=False):
return f"{ADDON_PREFIX.upper() if upper else ADDON_PREFIX}{separator}{name}"
def title_str(str):
s = str.replace('_', ' ')
def title_str(val):
s = val.replace('_', ' ')
return s[:1].upper() + s[1:]
def code_str(str):
return str.replace(' ', '_').replace('.', '_')
def code_str(val):
return val.replace(' ', '_').replace('.', '_')
def set_param_value(mx_param, val, nd_type, nd_output=None):