Mapping gradient colors to several .obj

Hi there. I am trying to map an animated gradient to various .obj geometries, my goal is to create a smooth color gradient by changing the color the .objs, The .objs must have only one color value, I dont want a gradient in the object, i want several single color objects to form a “lofi” representation of the gradient animation. I am new to TD so I am struggling with this.
I am comming from a Grasshopper3d environment and trying to complement my workflow with TD, finally I want to use the color values to then send them to an Arduino connected to LEDs to bring allt his to life.

I am attaching a picture of what I am looking for, ive already done it GH but is not very efficient thats why I am trying to do it in TD. I hope someone can guide me here. Thanks!!

If you want to move the geometry out of GH into TD as a single obj, then taking each element here, collapsing it’s UVs to a point and then distributing them visually in this layout would be the quickest way I can think of.

edit: if you feel comfortable posting the geo, I’d be happy to work up a demo.

Thanks that would be great!
I tried importing it as one .obj, but couldn´t figure out how to split it into separate geometries in the orden i need them to. They need to follow an exact order in which the LEDs are connected in series.

I exported from GH the geometry already separated from index 0 to 76. I am uploading the .obj.

/file/d/18cTxgSnfpOsuyL3RXXrByaMo3UjOeXEf/view?usp=sharing
(for some reason I cant post full links here and the file is to big, just add
image
before the url above)

Here’s a project demoing the workflow I recommended:
https://www.dropbox.com/t/FkAXz9xPsv5KgjuH

I pulled your OBJs into blender and merged them into a single object. Then merged by distance to unify the individual elements into discrete UV islands. UV projected from top view and collapsed the islands into points based on centers.

Even quickly optimized, your geometry is kind of heavy for this type of work. It ran fine on my MacBook but might struggle on some systems. As a very general rule if you have more faces packed into a piece of geometry than you’re likely to render pixels of, you should simplify the geometry further.

I assume you’re running Grasshopper in Rhino. I haven’t used Rhino in decades, but you might want to consider extending your procedural workflow a bit and doing this with USD instead of OBJ and custom attributes if Rhino does USD.

Wow thanks!
That worked really well!
Yeah the meshes are very heavy since its what I am using for 3D Printing.
I don`t know if rhino has blender capabilities for mesh optimization since is nurbs based but I i will try to figure it out.

Do you know how can I extract the RGB value for each point to send it to Arduino?
You already help me a lot so dont worry if you dont know.

Thanks again!

Yep,

It’s worth noting that we’re probably doing this the hard way. If Grasshopper is anything like Houdini, you’re scattering some points as the origin of each element. This is a nice short list of all the places where we need to sample a color. Assigning this to an attribute bound to each element would be a more efficient way to also do your visualizer, but I digress.

:rotating_light: NERD ALERT :rotating_light:

The mesh has over 3 million vertices in it. Each of them has a UV coordinate, but there are only 78 unique coordinates corresponding to each LED element. We want to get just those.

Python has a really useful data structure called set that is beloved by computer scientists and quixotic nerds. What’s awesome about set is that it only allows you to define one instance of an entry. So if you’re trying to reduce a large list of entries to only the unique ones, a handy trick is to just add everything into a set and let Python take care of discarding duplicates.

First we use a SOPtoDAT to extract the data from the sop with your model in it. When building large DAT tables, it’s a good idea to turn off the Viewer flag (circle in the upper left) of the OP, since TD will otherwise helpfully try to draw you a table with 3 million rows and your performance will drop into the single digits.

As shown in the screenshot here, we want to extract the ‘uv’ attribute from the geometry’s Vertices.

Next we want to use a scriptDAT to process all the rows and extract unique UV entries. Here’s the code:

def onCook(scriptOp):
	# clear the scriptDAT if it has any data in it and 
	# define some vars for our input and our set of UVs
	scriptOp.clear()
	input = scriptOp.inputs[0]
	uvSet = set()
	
	# iterate through the entire input table and 
	# add a tuple for each coordinate to the set
	# duplicate entries are automatically discarded
	for row in range(input.numRows):
		uvSet.add( ( input[row,'uv(0)'].val, input[row,'uv(1)'].val ) )
	
	# make a header for our table
	scriptOp.appendRow( ['x', 'y'] )
	
	# iterate through the set and add a row for each entry
	for i in uvSet:
		scriptOp.appendRow( i )

	return

we can take the result of the scriptDAT and send it into a DATtoCHOP to make a CHOP with two channels corresponding to our coordinates. To get the raw values for pixels we use a TOPtoCHOP. This OP has a convenient input for the lookup coordinates to which we can attach our chop with the coordinate channels.

I haven’t worked with an Arduino in a while, but if I were wanting to send RGB lighting data I’d use DMX. The linked file has a shuffleCHOP added to interleave the three channels into a single channel suitable for feeding a DMXoutCHOP.

Link to updated file

Good Luck! :slight_smile:

1 Like

Hello again @leonfeza ,

I realized this morning that an issue with the approach outlined before is that it doesn’t properly account for the addressing order of your LED elements. So I went back and did another version of this that keeps the objects as separate sops and then queries each sop in order to extract the UV data.

While I was at it, I went ahead and reduced the complexity of the display geo.

I QC’d the addressing order by running the output of our DATtoCHOP into a CHOPtoSOP. The spiral pattern seems to properly match the numbering order of your objects.

Here’s a ZIP with the project, blender file and individual OBJs

1 Like

Man! You really did the job! Thanks for that!
I haven´t try this final solution just yet, but I´m sure it will work for what I want to achieve.

I thought about exporting just the points as you mentioned, since those are the ones that really matter and its a far simpler geometry. But I in orden to take decisions I needed the whole geoemtry to see how it will look with the colors and everything.

Honestly I have like a week experience in TD (and it shows hahaha), but so far I think I´m starting to understand how in works, the logic its similar to GH (the I´ve been using for 10yrs now) but the interface and params its whats killing me. I will keep learning.

Thanks again! I´ll send you some pictures of the whole thing lighten up once its finished and if you are on IG or something let me know I´ll drop some credits.

Happy to help :slight_smile:

I hope I didn’t cheat you out of some learning opportunities. I’ve been cooped up and this stuff is like crossword puzzles for me. It looks like a cool project and it will be nice to see it go live.