Comments (8)
This is a good question, @MatthieuBEAUD, and I'm CC'ing @kwokcb who has done some initial work on adding NodeDef publication methods to the MaterialX API.
One related pull request may be found here:
#1403
from materialx.
Hi @MatthieuBEAUD ,
This line is a bit "strange" in approach
node_def.copyContentFrom(doc_in)
as you're trying to copy the entire document into a single element.
It will embed the document inside but it's has a source reference (adds a sourceURI
reference). Thus when writing it's only including the reference as an "xinclude" by default. In this case ou can set the following XmlWriteOptions
to expand the include.
/// If true, elements with source file markings will be written as
/// XIncludes rather than explicit data. Defaults to true.
bool writeXIncludeEnable;
BTW< It's an interesting way to populate a definition from an external whole document source which from what I see should not have any side-effects but is not a well tested scenario.
I'm not sure if this fits your workflow but perhaps taking a "libraries" approach is useful ? For example loadLibrary()
loads in a external definition references in using importLibrary()
. The "dummy" nodedef
it seems is just a placeholder which isn't really needed if you just intend to import an entire document.
Hope this helps, and is an workflow that would interesting to get more clarification on.
from materialx.
Hi @kwokcb,
Thank you for the explainations.
So it is expected that doing:
node_def.copyContentFrom(doc_in)
would remove the nodeDef from the materialX and replace it with the <xinclude>
(instead of adding the <xinclude>
inside the NodeDef) since we're trying to copy the content from a document into a single element, so it would default to copying the content into the parent document of the node_def, right ?
I'll try with the libraries. But would it need to import a NodeDef or I could import any materialX graph ?
The workflow would be for the creation of an eye shader with MaterialX. It would be as follows:
- Create a MaterialX through the GraphEditor. (and could be edited later if necessary).
- We then would need to use this MaterialX in different DCCs (maya, houdini...). It would not only be an simple import/reference but we'd also need to expose some of the shader parameters for animation (for example, in an eye shader, we would need to animate/keyframe the size of the pupil, so some inputs of the materialX would need to be exposed one way or another. We wouldn't want to export one materialX per keyframe).
- In Houdini, it is possible to create a HDA (Houdini Digital Asset: a custom node that can be used in the houdini graphs) from a MaterialX using one of their python script
mtlx2hda.py
. This would allow to have this Materialx as a custom node with some exposed parameters within Houdini and keyframe those. But this script can only convert a MaterialX NodeDef to a HDA. So I need a way to convert a MaterialX without NodeDef to one with a NodeDef. And I was looking for ways to do it through the MaterialX API, instead of manipulating the XML directly (which is dirty and dangerous). - For maya, I was planning on using the MaterialX ShaderGen, to get the glsl code, and then wrap it manually into the maya format .ogsfx to expose some of the Uniforms of the glsl in the maya UI.
So basically, my main concern was to make a materialX graph into a nodeDef.
I don't know if there are any plans for MaterialX to have exposable / dynamic parameters (like the inputs of a shader) ?
Thank you again for your time !
from materialx.
Hi @MatthieuBEAUD ,
It's great to have this context information.
In a nutshell this sounds like dynamic nodedef
creation.
- If you assume the premise that a document can contain N nodegraphs then there is an API to create a nodedef on the fly from a nodegraph. It basically copies the nodegraph and modifies it to be an implementation graph ("functional graph"), creates a
nodedef
and then sets up the implementation relationship. I have some fixes for it which I should really finish off the PR for :(.
It's not hard to do this with just Python API as well as I wrote up a utility here which will patch the current API call as needed and also has some logic for content copying. Since the code is not checked in yet. you need to assume use_1_38_8
is false.
- If you assume your whole document is a definition, then you'd need top level inputs and output nodes as needed. From that you can create a nodegraph and place these elements as children of the nodegraph. Then as before create the definition.
For Maya I'm not sure from your comments if you know there OGSFX shader generator which will produce ogsfx for the viewport rendering. Thus I don't think you have to go this route. I haven't checked the current state of the MaterialX Stack
support but custom definitions should be supported. I'm unsure if they can dynamically reload at runtime. Best to ping folks directly there.
Anyways the key elements are:
- Load 1 or more nodegraphs from a document, or wrap a document in a nodegraph
- Copy the graphs to create the implementation graphs.
- Create a nodedef per graph. Using the inputs and outputs from that graph to expose the definition interfaces.
- Update any dependent definition libraries such as the USD SDR if you need that ( I guess that's what's being done with
mtlx2hda
.
For dynamic parameter exposure, on a nodegraph it's already there by adding input nodes to a graph. For a definition they could be possible but definitions are meant to be statically created once for a definition. In your case you can dynamically change the inputs to expose and rebuild the definition as needed.
from materialx.
BTW, I wrote a tutorial for definition creation (from graphs or source) here. Maybe overkill but has all the "gory" details (especially for the latter) :).
from materialx.
Thank you so much for all the documentation and help @kwokcb ! It'll help a lot !
from materialx.
No problem. If you need something more interactive and not on them, the ASWF Slack channels have a lot of great folks.
from materialx.
Thanks for these great notes, @kwokcb, and I'll close out this question as resolved.
from materialx.
Related Issues (20)
- Crash when loading / viewing an existing nodegraph into graph editor - related to swizzle node upgrade process HOT 8
- libMaterialXFormat exports pugixml symbols HOT 8
- Add reference thumbnail images for the spec docs
- isTransparentSurface() does not work for OpenPBR HOT 6
- MDL shader uniform block reflection inconsistency
- Instructions for running MaterialXGraphEditor on Mac HOT 4
- Proposal: Migrate comment documentation to nodedef doc attributes for std libraries HOT 2
- MaterialXGraphViewer: `time_float` and `frame_float` do not have any effect HOT 3
- GLSL ShaderGen: `time_float` and `frame_float` do not have any effect HOT 6
- Proposal: MaterialX Hair BSDF
- Angle units handling
- Input node resolution failure when same-named nodes exist inside and outside a nodegraph HOT 3
- Smoothstep breaks GLSL compilation when multiple type signature nodes are used HOT 13
- generateshader cannot validate shaders with lighting
- Equivalence operator fails to handle vector string differences HOT 12
- Multiple type signature possible problem
- Graph Editor: Mouse UI action orbits camera in render view HOT 2
- Suggestion: Add command line commands for Python package
- Proposal : Provide a Functionally equivalent operator HOT 8
- Proposal: Add a simple way to strip out library content on XML write
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from materialx.