Community
Arnold for 3ds Max
Rendering with Arnold in 3ds Max using the MaxtoA plug-in.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Operators and namespaces

7 REPLIES 7
Reply
Message 1 of 8
110507
1390 Views, 7 Replies

Operators and namespaces

Hi,

Currently I'm trying to find a way to have dynamic shader assignment. For instance, during production the lookdev on an asset is created in one maya file. The artist uses operators to do the assignment of the shaders. The shaders and operators are published. In the lighting scene the asset and it's shaders are pulled in under a namespace. However, because of the namespace, the operators will not be able to resolve the reference to the shaders anymore.

For the selections I've found a way to fix this by referencing a collection with the namespace in the selection. However, it seems it's not possible to use collections in an assignment string. Therefore this still remains unsolved.

Does someone have any suggestions?

Thanks in advance

Tags (2)
Labels (2)
7 REPLIES 7
Message 2 of 8
Stephen.Blair
in reply to: 110507

Do you have a simple example of your setup?

I tried importing an mb file that had some shaders, and I was able to assign those shaders like this

shader = "my_test_scene:aiUtility1"


// Stephen Blair
// Arnold Renderer Support
Message 3 of 8
110507
in reply to: 110507

Hi Stephen,

Thanks for the answer.

Currently, the operators and shaders are created by a lookdev artist in a separate maya scene.

It this scene the operator might look like this:

selection: #namespace and *car_body*
assignment: shader = 'car_body_shader'

(#namespace is referring to a collection operator, containing a namespace selection)


Next, the shaders and operators are published. In the lighting scene these operators and shaders are pulled in under a namespace. However, due to the namespace, the name of the shader would now look something like: car_001:car_body_shader

Therefore, Arnold will not be able to resolve the reference to the shaders anymore.

I was wondering if there is a way to overcome this problem in a dynamic manner.

Thanks in advance

Message 4 of 8
Stephen.Blair
in reply to: 110507

No, I don't see a way to dynamically figure out the value for an assignment expression.



// Stephen Blair
// Arnold Renderer Support
Message 5 of 8
orn.gunnarsson
in reply to: 110507

Hi Arlon

As you probably know, the assignment expressions can use references and operators (e.g. +) to build dynamic expressions such as the following fictitious example

assignment "radius += geo_scale * (random_factor + 0.1)^2 - regulariser[1]"

Given the current workflow you have I have 3 suggestions for a workaround which I'm hoping could be workable for you, albeit only 1 is doable with the current version of Arnold, whereas the latter 2 would need a bug fix on our side (more on that below).

String-like types such as strings, enums and nodes such as shaders typically use string literal values, but the quotes are omitted then the value is interpreted as a reference. By default the reference is picked up from the selected (cooked) location, so if the shape 'car_001:car_body' conveniently had a custom string parameter ref_shader with the name of the shader, then you could have an assignment to dynamically pick that up, i.e.

assignment "shader = ref_shader"

Alternatively, the reference can come from another node (perhaps a dummy storage node) using the # in a similar way to how collections are referenced, e.g.

assignment "shader = #some_node.ref_shader"
assignment "shader = #some_node.ref_shaders[0]"
assignment "shader = #some_node.some_array[1].ref_shader"


1) The reason I mention this relates to the first suggestion, where if you are able to build it into the workflow to use references instead of literal assignments (perhaps on a dummy node), then the references in the lighting scene could differ and the assignment will dynamically pick up the namespaced name. Admittedly this might be a bit cumbersome unless you wrap it in a nice UI for the look-dev artists.

2) Perhaps an easier way would be use a references to a namespace in similar way to the selection expressions, where you'd have one assignment to build the full name and a second assignment to assign the shader to the concatenated name, e.g.

assignment 2 1 STRING 
 "string full_name = namespace + 'car_body_shader'" 
 "shader = full_name"

Here, the namespace in the look-dev scene would be empty, but the lighting shot build process would add the namespace on the shapes so the assignment would dynamically reference the correct namespace for each shape being selected and build the full name.

This brings me to the bug fix, as at the moment strings can't be concatenated in the same way other types can. This is a simple bug fix on our side though.

3) The final suggestion is along the same lines as the second one, but it's a bit cleaner as only one shader assignment expression is needed. However, it's a more involved change which may or may not be suitable in a bug fix release.

assignment "shader = namespace + 'car_body_shader'"


Appendix

On a side note, you may be interested in looking at MaterialX as we already have an operator that can assign look-dev by performing material/property/visibility assignments dynamically. At the moment we only support the consumption of MaterialX so you'd have to build the MaterialX documents from the Maya scene yourselves. We can discuss this further if that's of any interest.

Message 6 of 8
110507
in reply to: 110507

Hi Orn,

First of all thanks for the elaborate answer! My apologies for the late responds. I've been occupied with other tasks and didn't have time to get back to this one.

The latest solution I implemented to resolve the namespace is adding a special tag during lookdev publish and replacing this tag with the correct namespace when building the light scene.

For example:

assignment "shader = '@namespace@car_body_shader'"

Looking at the options you suggested. The second and third seem the most efficient to me. Adding a namespace to the shapes during the shot build process seems like a potential option. Additionally, the MaterialX option is something I'd like to explore.

However, I was wondering if it would be possible to implement referencing the collection name from an aiCollection node in the input? This already works in the selection of the aiSetParameter and thus I assume the input is already being evaluated by the node. This way we could achieve something like this:

collection {
 name aiCollection1
 selection "car1:*"
 collection "namespace"
 declare prefix constant STRING
 prefix "car1"
}
set_parameter {
 name aiSetParameter1
 inputs "aiCollection1"
 selection "#namespace and *car_body*"
 assignment 2 1 STRING
  "string full_name = #namespace.prefix + 'car_body_shader'"
  "shader = full_name"

Would this be at all possible. If yes, would this be suitable for a bug fix?

Thanks in advance

Message 7 of 8
110507
in reply to: 110507

@Orn Gunnarsson

In your previous post you mentioned MaterialX as an alternative. I've become extremely interested in going with MaterialX now and am currently looking into writing a exporter for native Maya (and later Houdini) shaders to MaterialX. Is your team already working on something similar? I would be grateful for tips or direction on this.

Thanks in advance

Message 8 of 8
orn.gunnarsson
in reply to: 110507

@Arlon Swaders

We have plans to provide means to turn native Arnold shading networks and assignments to a .mtlx file which would be used by all our plug-ins. The first implementation of this is in all likelihood going to be available in the very near future.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report