question

Ilyas DIZDAR avatar image
Ilyas DIZDAR asked ·

How can I use ai user data in operators ?

Is it possible to inject user data string for example in a operator ?

I want to assign shaders based on a user data string.

shadinguser_dataoperators
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Orn Gunnarsson avatar image
Orn Gunnarsson answered ·

You should be able to use user parameters to drive the shader assignment. Let me provide a couple of examples that might be of use.

Let's say you've exported some geo with some user data from Houdini to an .ass file (see standin.ass attached below as a trivial example).

Then depending on your preferred workflow, you can set things up in different ways to utilise the user data. I'll provide 2 examples below which uses the set_parameter operator and attached standin file (just 3 spheres with some arbitrary user data).

Example 1

Here, we assign a green shader to spheres that have particular string and velocity user properties

selection "sphere*.(my_string == 'make_me_green' and my_speed > 4.0)"
assignment "shader = 'green'"

sphere2 in standin.ass matches this criteria so it'll be assigned the green shader.


Example 2

You can also use the user data directly in the assignment. sphere1 and sphere3 have a my_shader_name user data with the values red and blue, respectively.

Here, the selection matches all spheres where the my_shader_name user data exists, and the assignment assigns the shader using the user data value as the shader name.

selection "sphere*.(my_shader_name)"
assignment "shader = my_shader_name"


The expected render and .ass files are attached and it should be easy to replicate in Maya using a standin. Hope this helps.

standin.ass

test.ass

test.png


test.png (26.4 KiB)
standin.ass (449 B)
test.ass (837 B)
Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Ilyas DIZDAR avatar image
Ilyas DIZDAR answered ·

Thanks Orn !

That is really good to know that Arnold can handle such things.

The problem now is that I d'ont have the same result as you in Maya.

I import you test.ass in Maya it render well but I get only the green sphere shaded, not the red and blue.

Seams to be it don't understand your assign_stuff operator.


Any idea to make it work in Maya ?

1 comment Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

How do you "set directly" ? You are using setAttr, not the Attribute Editor?

0 Likes 0 · ·
Ilyas DIZDAR avatar image
Ilyas DIZDAR answered ·

Thanks for your answer,

So if I understand well there is no way that user data can control or override shader assignation ?

I am exporting a forest from Houdini as ass file, But I am doing my rendering in Maya.

I know is possible to separate shaders and shapes in different ass files as long as shapes have the correct assignation.

I wanted to go that way but I failed to generate the assignations only based on attributes.

It doesn't work if Arnold can not find the shaders in Houdini ...


May be there is a trick to assign non existing shaders ?

1 comment Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

You can use the user data shaders to control an aiSwitch shader.

set_parameter operators can assign existing shaders.

0 Likes 0 · ·
Stephen Blair avatar image
Stephen Blair answered ·

EDIT: See Orn's answer. You can use user data values in assignment expressions.

I was thinking about control flow based on user data, sorry.


You want the operator to assign shaders based on user data that is already in the scene?

There's no way to do that.


A set_parameter operator can create user data on shapes. You add a custom assignment, where you specify the string type. Then in the shading tree you could get that user data and do different things based on the value.




Share
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.