Getting Color of Canvas in Dynamic Painting via Python

I want to be able to determine the color of a vertex using Python on a canvas in a scene using Dynamic Painting. In my scene I want to have a number of objects acting as canvases and one object acting as the brush. When the brush object touches a canvas I want to know it’s color. How do I get the color of a painted vertex or face on a canvas object. Thanks for any pointers.

Welcome, cinetron!

This is a pretty specific request. Is there a motivated problem that you’re trying to solve? Some context? There may be a way to solve the problem that works around writing a big old python script.

I haven’t used dynamic paint much, so there may be easier ways to do this, but what I think you have to do is:

First, find where your meshes intersect using something like Object.closest_point_on_mesh

Then, if your Dynamic Paint targets vertex colors, look up the vertex in the vertex color data (see Mesh.vertex_colors, and LoopColors) in the active layer (MeshLoopColorLayer).

Or, if your Dynamic Paint is targeting an Image sequence:

  • look up the UV coordinate of the intersection point
  • read the target texture image into Python’s working memory
  • look up the nearest pixels and interpret the raw RGBA data as a color, potentially applying a resampling algorithm if aliasing will be a problem for your application

Thanks so much for the help. I worked out another way using BVHTree instead of Dynamic Paint. I wonder if under the hood Dynamic Paint uses BVHTree? I ended up using Animation Nodes. So far my solution doesn’t give me RGB values directly but indices to the material. From this I made a lookup table. I posted my solution here

1 Like

Awesome! Congratulations :smiley:

The vertex color does not have the dynamic painted values. It has only the vertex painted colors. Any way to find the dynamic paint colors