Grasshopper

algorithmic modeling for Rhino

Coloring objects according to their relative position in a bitmap

I wanted to do a quick thing for a friend wherein I'd have a grid of spheres in which each sphere would be colored according to a bitmap "overlayed" over the entire grid (I also raised the spheres but that's essentially independent of the coloring and not where the problem lies).

I thought at first that I'd use the image sampler to attach some sort of "user info" to each sphere and then reference that info in a brazil material but I couldn't find anything in Brazil that would reference the user info so I was scratching my head for a while until I thought that if I set all the UV coordinates in each sphere mesh according to it's relative position in the grid, then when I used the bitmap texture in Brazil with that bitmap, the entire sphere would map to the proper position in the bitmap texture and presto - each sphere would be colored correctly.

So I used a C# component to implement the following code:

-----

private void RunScript(object mesh, object U, object V, ref object A)
{
   Mesh meshIn = (Mesh) mesh;
   Mesh meshOut = new Mesh();
   double u = (double) U;
   double v = (double) V;

   meshOut.CopyFrom(meshIn);

   meshOut.TextureCoordinates.Clear();
   for (int i = 0; i < meshIn.TextureCoordinates.Count; i++)
   {
      meshOut.TextureCoordinates.Add(u, v);
   }
   A = meshOut;
}

-----

and then pipe in the UV values from the output of the Grid component (using the Paneling Tools plugin for GH).  So I tried this and in the Rhino display it looked great:

But when I actually tried to render, this is not what I saw at all:

Actually, when I did a closeup on the render it showed the moose bitmap being displayed on each sphere individually - as though no UV mapping had been applied by my C# component at all.  Here is the GH script:

and the material in the material for all the spheres simply had a bitmap texture with a colored version of the moose head.  Oh, the value of the number at the lower left is 10 which means that the grid is across a square from (-10,-10) to (10, 10).

Does anybody have any idea why this isn't working?  I could maybe get what I want by coloring the vertices in the sphere meshes and then using the VertexColor texture in Brazil but I haven't tried yet and I'd still be left wondering why I'm getting different values between the rhino display and the brazil render.  If I am correctly setting all the UV coordinates to the same value then it should be impossible to get anything but a solid color on each sphere.

I've included a zip of the gh file, bitmaps and Rhino file.  It would require Brazil and the Panel Tools GH plugin.  Sorry if this seems like a Brazil question more than a GH one - perhaps it is, and I apologize in advance if it turns out I've misidentified it.

Views: 939

Attachments:

Replies to This Discussion

Strangely, it renders just fine when I render it in v-ray, but as soon as I switch to Rhino Render, it reverts to the problem you describe. Is there a reason you're not just using a planar mapping across the entire set instead of doing per-vertex uv texture coordinates? This might be faster to set up and more compatible although you might not get a perfect 1-to-1 color-to-mesh translation. 

The other odd thing I noticed is that when I switch renderers, it seems to lose the custom texture mapping on the objects. If I bake the geometry with Rhino render as current, it actually handles it just fine. 

Ah - are you saying to join them into one object and then use a single mapping on that one object?  Not a bad solution, though individual spheres wouldn't be single colors but would have the texture cut "across" them, though it might be good enough.  Really, I think if I can't get this thing to work the next attempt would be the vertex colors since that would give each sphere it's own individual color and then this idea would be next.  At this point, I'm asking more for my curiosity/understanding than out of necessity.  In the end this doesn't seem like such a corner case that it would have any problem at all and so I'm curious why it doesn't.  I'll try baking the geometry with Rhino renderer as current.  Very odd.

Verified that this works fine with Rhino renderer as current when baked.  Says to me that Brazil permanently changes the UV coordinates for some reason in this case.  Tried adding a small fudge factor to each UV coordinate to see if it was because of strict equality and that didn't help anything.  I think this is definitely a Brazil problem so I'll take it up on their forum.

Thanks very much for the kind response!  Love your work I've seen!

Yeah, I was suggesting joining them into a single mesh - although I think you can apply a planar mapping to a group of objects as well, not sure. 

I wouldn't recommend going down the mesh vertex color alley - though some have had success with it, I have personally always found it to be near impossible to get working in a render engine. 

The only other approach that's workable would be to sample the colors, dynamically create render materials for the colors you're trying to represent, and then assign those to your objects at bake time (all of which will require a plug-in like human) (excuse the blatant self promotion). Here's an example of that workflow:

I messed around with your original definition a bit since I don't have paneling tools, but the same approach should apply. 

Attachments:

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service