Change Material Assigned to DirectShape Based on Brightness Value

I have created a grid of DirectShapes and I am attempting to change their material based on the brightness values of the pixels of a black & white image. In other words, I am trying to recreate an image with different materials assigned to a grid of geometric shapes in Revit.

It is my understanding that the Color.Brightness node returns a (more-or-less) infinite number of values between 0 and 1. My ultimate goal is to assign each DirectShape with 1 of 3 different materials, so I am trying to create a logic that says, "Where a pixel’s Color.Brightness is less than .33, assign the corresponding DirectShape the “White Plastic” material. Values greater than .33 but less than .66 get assigned the “Pine” material, and lastly values greater than .66 get the “Plastic-Gen-Black” material. I have started this script, but have taken it as far as I can and am now a bit stuck.

I am fairly new to Dynamo… is this the simplest way to achieve my goal? Also, I am trying to do this without the use of Code Blocks so that I can force myself to learn the tools native to Dynamo first. Any help would be appreciated.

An embedded conditional statement is an easy solution here.
If the brightness is less than 0.33 return Material 1, if it’s not less than 0.33 but less than 0.66 return Material 2, otherwise return Material 3.

Brightness < 0.33 ? Mat1 : Brightness < 0.66 ? Mat2 : Mat3

I would also say that learning to use code blocks effectively is a very important part of learning Dynamo and can actually help you understand node functions better in some cases. Design Script is just the textual format for visual nodes anyway.

1 Like