Hi,
I’m just writing a shadernode ‘ObjectIndexer’ that provides a ‘Fac’ computed from the number of an object name among others object sharing the same prefix name.
Eg :
Cube.012 => give object number 12
The factor is then computed from the total objects sharing the same prefix (eg ‘Cube’).
Because it is not currently possible to compute a ‘true’ shader with the Python ShaderNode API (ie a shader that really acts at rendering time for every object sharing the same material), the tool comes in 2 parts :
- shaderNodeObjectIndexer.py : compute value from the scene (Total number of objects)
- node_objectindexer.osl : really compute our Factor (and other values)
For those that have used the ‘ObjectInfo’ node, they perhaps know about its ‘Object Index’ output : it is computed from the ‘pass_index’ property of an object.
This means that you must set the pass_index property, then you can use it as a ShaderNode parameter.
My tool doesn’t set pass_index, it computes the object index from its name.
Next release will use an external spacial reference (other object that will modify the object precedence in the group) : Reference/Influence Inputs + RefLoc/InfLoc outputs.
Currently, they doesn’t work at all. Don’t use them.
How to use it :
- On your scene, you have duplicated an object and have a scene with many copies (Cube,Cube.001,Cube.002, …)
- on your scene, these objects share the same material (eg: Object > Make Links > Material)
On the Node editor - select one of these object.
- add a Script node, link it to node_objectindexer.osl, refresh.
- link its Fac output to the Fac input of a ColorRamp for example.
- load shaderNodeObjectIndexer.py on the “Text Editor”, then “Run Script” (alt+p)
- add ‘Object Indexer’ node (from Input Shader category), link its Total output to the Total input of the osl.
- from ‘Object Indexer’, apply ‘Auto Update’
That’s all.
The ‘AutoUpdate’ option can be used for those that prefer to set the Total manually (ie. huge number of objects …)
Let me know if you encounter some troubles.
Hope it helps …
Thanks,
Valery
EDIT :
A very small demo video here on what could be done:
Attachments
objectindexer.zip (117 KB)