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.
Contributor

Purpose

This PR continues implementation of https://archive.blender.org/developer/D16044
As part of Hydra Render engine we are providing MaterialX Blender addon.

Features

  • Adds new MaterialX nodes to the existing Shader editor. MaterialX nodes are generated from MaterialX XML spec.
  • Users can compose Shader nodegraph combining both: Blender nodes and MaterialX nodes.
  • Allows import of MaterialX XML files.
  • Allows export Shader nodegraph to MaterialX XML file. Currently support limited number of most used shading nodes.
  • Provides python API to export Shader nodegraph to MaterialX document. It is used in Hydra Render engine.

Notes

New addon is in TESTING status.

How it works

When addon starts, it generates python code with MaterialX nodes. Generated *.py files are lay in <user addons dir>/materialx_data/materialx_nodes.

Screenshots

List of new MaterialX nodes in Shader editor
Screenshot 2023-05-09 162457.png

Tools for Import/Export .mtlx file:
Screenshot 2023-05-09 162652.png

Exported .mtlx to Shader editor:
Screenshot 2023-05-09 163158.png

### Purpose This PR continues implementation of https://archive.blender.org/developer/D16044 As part of [Hydra Render engine](https://projects.blender.org/blender/blender/pulls/104712) we are providing MaterialX Blender addon. ### Features - Adds new MaterialX nodes to the existing Shader editor. MaterialX nodes are generated from MaterialX XML spec. - Users can compose Shader nodegraph combining both: Blender nodes and MaterialX nodes. - Allows import of MaterialX XML files. - Allows export Shader nodegraph to MaterialX XML file. Currently support limited number of most used shading nodes. - Provides python API to export Shader nodegraph to MaterialX document. It is used in [Hydra Render engine](https://projects.blender.org/blender/blender/pulls/104712). ### Notes New addon is in TESTING status. ### How it works When addon starts, it generates python code with MaterialX nodes. Generated `*.py` files are lay in `<user addons dir>/materialx_data/materialx_nodes`. ### Screenshots List of new MaterialX nodes in Shader editor ![Screenshot 2023-05-09 162457.png](/attachments/82583a61-ebb0-4613-9613-54f393dc026a) Tools for Import/Export `.mtlx` file: ![Screenshot 2023-05-09 162652.png](/attachments/a076e1d0-70e3-4b90-a9d5-eb6165dcbfb7) Exported `.mtlx` to Shader editor: ![Screenshot 2023-05-09 163158.png](/attachments/5727ffff-be54-4dc9-9d77-7d77ba3fa8b2)
Bogdan Nagirniak added 27 commits 2023-05-09 15:35:15 +02:00
- Created basic structure of MaterialX addon
- Added MxNode related classes, generate_node_classes.py, categories.py.
- Added preferences.py, node_tree.py
- Added basic UI for MX node tree
- Added materialx libraries
Added constant variables ADDON_DATA_DIR, NODE_CLASSES_FOLDER, MX_LIBS_DIR.
Added generate_init_code function to create __init__.py for node_classes.
Small fixes.
Added mathlib module, with ui.py and manager.py.
Added properties module.
Added class MaterialXProperties to be used as a parent for addon PropertyGroups. It sets "materialx" property as parent for addon properties (bpy.context.window_manager.materialx. ...) Added constant variables MATLIB_FOLDER, MATLIB_DIR, currently, it is set to save matlib to addon appdata folder.
Renamed ADDON_PREFIX to ADDON_ALIAS, made it to use in properties. Made code improvements.
Added drawing MaterialX Node Tree inside Material panel.

Co-authored-by: Bogdan Nagirniak <bnagirniak@luxoft.com>
Implemented AddonPreferences with log_level and dev_tools options.
Changed appdata folder name: materialx -> materiax_data
* BLEN-219: Export blender nodes to MX nodes.
Added bl_node module.
Added bl_node.nodes module:
- color.py
- converter.py
- input.py
- output.py
- shader.py
- texture.py
- vector.py

Moved manager.URL to utils.MATLIB_URL.
Remove redundant code from material.ui.
Code cleanup.
Made UI improvements: removed unused panels, fixed text, etc.
Made code cleanups and improvements, removed unused code.
Refactoring: moved NodeParser node classes to bl_nodes folder.
Fixed some TODOs.
* BLEN-222: Mike node link invalid if connects different types.
Registered timer for update_links.

Co-authored-by: Bogdan Nagirniak <bnagirniak@luxoft.com>
More fixes and cleanups.
Implemented showing MxNodeTree node editor when mx_node_tree is changed.
Fixed loading materialx from matlib.
Removed default libraries files.
Fixed export Material editor and MaterialX editor to file.
Added get_materialx_data method.
All MaterialX nodes moved to Blender shader node tree.
MaterialX nodes and Blender nodes now work between each other.
It is possible to have MaterialX surfacematerial node or Blender Material Output node for material (both works).
Moved functions import, export, print to console to Blender shader node tree.
Removed: online MatX library, unused code, MatX properties
Moved materialx/ui.py -> ui.py. deleted folder "material". small improvements

Co-authored-by: markyandex@gmail.com <markyandex@gmail.com>
Added caching of MaterialX Document
Changes:
    getOutput -> getActiveOutput
    getOutputs-> getActiveOutputs
    getInput -> getActiveInput
    getInputs-> getActiveInputs

Co-authored-by: markyandex@gmail.com <markyandex@gmail.com>
Changed description of addon and moved preference's register/unregister functions to preferences.py

Co-authored-by: markyandex@gmail.com <markyandex@gmail.com>
BLEN-321: Fix export to mtlx with dependencies
Fixed code in utils.export_to_file() (renamed from export_mx_to_file()).
Made code cleanups/improvements.
* Fixed generation of MaterialX nodes
* Fixed nodes `add` and `mix`
* Adjust code for other nodes to fit new requirements

**NOTE FOR REVIEWERS**
You need to regenerate MaterialX nodes for this PR

Pull Request #3
**TECHNICAL STEPS**
Added check for input types and warnings if input has inappropriate type. This check added for `Mix` and `Add` nodes for now.

Pull Request BogdanNagirniak/blender-addons#4
### Purpose
Folder `materialx` with mtlx files moved to blender.shared in Windows.

### Technical steps
Make FILE_PATH in generated node classes to be local for MX_LIBS_DIR and MX_ADDON_LIBS_DIR.
Added blender.shared to BL_DATA_DIR for Windows.

Pull Request BogdanNagirniak/blender-addons#7
### Purpose
Extend list of supported formats due to enable OIIO for USD.

### Techical steps
Extend SUPPORTED_FORMATS with `".exr", ".open_exr", ".tif", ".tiff", ".zfile", ".tx"`

Pull Request BogdanNagirniak/blender-addons#8
Bogdan Nagirniak requested review from Brecht Van Lommel 2023-05-09 15:36:05 +02:00
Bogdan Nagirniak requested review from Brian Savery (AMD) 2023-05-09 15:36:05 +02:00

The design of this is different than we agreed on, so I'm confused about what the plan is here? Is this really meant as the implementation we ship with Blender?

For reference: in conversation at the Blender Conference we agreed that the nodes should be implemented natively in C/C++ as shader nodes, and that we should add new native socket types where needed, rather than having a completely separate node system for MaterialX.
blender/blender#100894 (comment)

The design of this is different than we agreed on, so I'm confused about what the plan is here? Is this really meant as the implementation we ship with Blender? > For reference: in conversation at the Blender Conference we agreed that the nodes should be implemented natively **in C/C++** as shader nodes, and that we should add **new native socket types** where needed, rather than having a completely separate node system for MaterialX. https://projects.blender.org/blender/blender/issues/100894#issuecomment-106110
Brian Savery (AMD) reviewed 2023-05-10 00:48:43 +02:00
Brian Savery (AMD) left a comment
Member

I guess my main comment is on the mechanism of generating the .py files for materialx nodes. Why are they generated on the user side and not something done once.

I guess my main comment is on the mechanism of generating the .py files for materialx nodes. Why are they generated on the user side and not something done once.
@ -0,0 +1,93 @@
<?xml version="1.0"?>

Why are these node defs being included?

Why are these node defs being included?
Bogdan Nagirniak added 1 commit 2023-05-10 18:14:18 +02:00
### Purpose
`alglib` .mtlx files are not needed, it can be removed.

### Technical steps
- Removed `libraries` folder
- Removed `alglib_defs.mtlx` from node code generation.

Pull Request BogdanNagirniak/blender-addons#9
Bogdan Nagirniak added 1 commit 2023-06-13 18:51:43 +02:00
### Purpose
Fix infinite loop in preview render when generated image cached.

### Technical steps
Caching images moved from python to C++ part so caching no more triggers Depsgraph updates;

Co-authored-by: Bogdan Nagirniak <bodyan@gmail.com>
Pull Request BogdanNagirniak/blender-addons#15
Bogdan Nagirniak added 1 commit 2023-08-28 14:58:54 +02:00
Bogdan Nagirniak added 1 commit 2023-09-13 12:52:54 +02:00
First-time contributor

I've been attempting to try out this addon but have been running into errors registering the nodes: ValueError: register_class(...): already registered as a subclass 'MxNode_STD_convert'. Perhaps there's a mismatch between the materialx version I'm using and what this addon supports? What version are you testing it with?

I've been attempting to try out this addon but have been running into errors registering the nodes: `ValueError: register_class(...): already registered as a subclass 'MxNode_STD_convert'`. Perhaps there's a mismatch between the materialx version I'm using and what this addon supports? What version are you testing it with?
Author
Contributor

Sorry, this PR has to be closed. MaterialX is going to be supported natively by Blender. Here is PR blender/blender#111765 which converts Blender material nodes to MaterialX, which is going to be merged.

Sorry, this PR has to be closed. MaterialX is going to be supported natively by Blender. Here is PR https://projects.blender.org/blender/blender/pulls/111765 which converts Blender material nodes to MaterialX, which is going to be merged.
Bogdan Nagirniak closed this pull request 2023-09-24 20:04:45 +02:00

Pull request closed

Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#104594
No description provided.