Custom material properties?

Can I / What is the best way to add custom properties (text and numbers) that are associated with a material (or layer, but preferably material)? Basically I have multiple objects with a particular material, that I need to be able to configure some additional custom properties to, like spectral light properties and other things that are not normally part of Rhino. This plugin is used for research, not a polished commercial plugin.

Ideally, I would be able to add fields to the Material window:

I see, Notes… Can I just add comma delimited info there and parse it out? Kinda hacky, but would it work?

I found these posts, but not exactly applicable because I don’t care about doing this with the tree view:

Looks like I can parse it out of Notes:

Feels pretty hacky though…

Is there a better way to insert some extra properties in the Material or RenderMaterial objects? I see other seemingly relevant fields like RenderMaterial.Fields, Material.UserData, Material.UserDictionary, Material.HasUserData

If the Material window itself is not modifiable with custom properties, has anyone made a simple window / button / way to bind extra properties to a particular material? Where would be a good place in Rhino to put functionality like that?

Ok, I’ve implemented them as CSV fields in the Material.RenderingMaterial.Notes member… but ew. I feel it would be cleaner to store these custom material properties in some dictionary of key+value pairs.

If anyone has a better solution/suggestion, I’m curious.

I was going to say it might be an acceptable hack for an internal project, to add more entries to the RenderContent.Fields, but checking quickly, it appears that though what you add will be added (and visible by inspecting the xml) during the session, it will not survive file IO.

Given this (if it is correct), and since I do not believe it is currently possible to make a material show extra GUI components, I might tend to make a dialog where I manage some data stored in the document, which contains a mapping of render material IDs to, say, my data dumped to json.

It would not be too difficult to populate such a dialog when it comes up (and so could be done in python without needing a whole plugin), but you could extend it later to be a modeless dialog or panel, which is listening to document events, updating your data as necessary.

Joe

Sorry you haven’t had an answer to this - I’m on holiday at the moment.

There is actually a mechanism to attach user data to RenderContent, but only on the C++ side of the SDK. The method is CRhRdkContent::AttachCustomUserData. As of right now, this has not been implemented for RhinoCommon.

We would be happy to work with you to implement this in a future service release of Rhino 7 if you would find this valuable. I also understand you would like to be able to attach additional UI sections to content to edit and display this data. We can also implement support for that - it sounds like something that would be both very possible and very useful.

  • Andy
1 Like

https://mcneel.myjetbrains.com/youtrack/issue/RH-64870
https://mcneel.myjetbrains.com/youtrack/issue/RH-64871

@jdhill That’s what I was thinking as well, popping up some custom dialog via a command and saving it myself. We have a handful of commands and dialogs already for various settings we need, so one more for material properties couldn’t hurt… If I get time, this is exactly what I’ll do.

@andy Understood, thank you!! Because this is for proof of concept research that will be used in some renders and paper submitted in the next few months, I wouldn’t worry about it. I can live with the text parsing. We will not be commercializing this stuff. However, I do think it’s a good idea to allow developers to add custom information to materials and layers in a user friendly way (visually in Rhino). Some GUI button for dynamically adding some textfields or dropdowns that in turn stuff keys and values into a dictionary associated with the scene.