I’ve created a script that takes an image, pixelates it, and assigns a corresponding color to a mesh cube. After that, I run a Python command to generate and apply a material with the color of each block.
The problem I’m facing is that this process creates around 7,000 materials, which makes it extremely slow to adjust properties like reflection or transparency, even when batch-editing (e.g., 300 at a time).
You’ll find that I am using RhinoCommon API directly. Also I made this for use with Python 3 in Rhino 8. It should be relatively simple to adjust for Python 2, but I haven’t tested. Just run _ScriptEditor, load the script and run it.
Steps the script takes:
find all mesh objects
build a list of RGB triplets from all mesh objects vertex colors (the first, as you did)
find the color clumps
create materials for each clump, picking the first color in the clump
assign materials to mesh objects based on
With distance 5 the script generates 268 colors. Since the script doesn’t remove the vertex colors I have a screenshot with Raytraced and Rendered modes side by side. It allows you to see the original colors against the new color set:
However, there is a trick with a hidden material that you can use if your goal is to render with Raytraced / Rhino Render in Rhino 7 or later. That will need only one material assigned to all objects, which then will render the vertex colors.
Run TestShowPrivateContent, the command-line history will tell you “Private content will be displayed”. Then in the materials panel add a new material, search for Cycles Vertex Color. Select all your objects that have vertex colors and assign this material. Then switch to Raytraced. It will look like this: