Material ID percentage by height (like Beiging watercube auditorium)

Hi
I need to generate randomly and continuosly changing seats pattern in the auditorium, based on two colors of the seat. Let's say from solid blue at the bottom, through mixed, to solid white at the top. Just like this watercube auditorium in Beiging. http://farm4.static.flickr.com/3079/2545312854_0150dde999_o.jpg

We have as a starting point a the auditorium made up of simple seats (each with pivot point at its centre) which should be replaced by the blue and white vrproxies in the fashion as per the image.

Up till now we've been doing a random coloured auditoriums by usin a little script without a problem. What I don't know how to do is to have the randomness (or ratio of the randomness) change with height.

Thank you for any help.

Marek

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Marco Brunetta's picture

Already replied by mail, but

Already replied by mail, but here's the latest version of the script with some extra options:

/*******************
by Marco Brunetta
[email protected]
********************/
 
(
	rollout heightColorizer "Height Colorizer"
	(
		materialButton mbtn_mat1 "EMPTY" width:100 pos:[10,10]
		colorPicker cpck_color1 color:white pos:(mbtn_mat1.pos+[100,0])
		materialButton mbtn_mat2 "EMPTY" width:100 pos:(mbtn_mat1.pos+[0,25])
		colorPicker cpck_color2 color:blue pos:(mbtn_mat2.pos+[100,0])
 
		groupBox gbox_settings "Settings" width:140 height:170
		spinner spn_variation "Variation:" range:[0,100,50] type:#integer fieldWidth:40 pos:(gbox_settings.pos+[25,25]) 
		spinner spn_bias "Bias:" range:[-100,100,0] type:#integer fieldWidth:40 pos:(spn_variation.pos+[-63,20]) 
 
		spinner spn_offset "Offset:" range:[-50,50,0] type:#integer fieldWidth:40 pos:(spn_bias.pos+[-71,30]) 
		spinner spn_minLimit "Low Limit:" range:[0,100,0] type:#integer fieldWidth:40 pos:(spn_offset.pos+[-87,20])
		spinner spn_maxLimit "High Limit:" range:[0,100,100] type:#integer fieldWidth:40 pos:(spn_minLimit.pos+[-89,20])
		checkBox cbx_useGradient "Use Gradient" pos:(spn_maxLimit.pos+[-75,30])
 
		button btn_clearMats "Remove Materials" width:140 height:18 pos:(cbx_useGradient.pos+[-33,30])
		button btn_start "START!" width:140 height:30 pos:(btn_clearMats.pos+[0,22])
 
		fn assignColor target source =
		(
			IF source == "0" THEN
			(
				IF mbtn_mat1.material == undefined THEN target.wirecolor = cpck_color1.color ELSE target.material = mbtn_mat1.material
			)
			ELSE
			(
				IF mbtn_mat2.material == undefined THEN target.wirecolor = cpck_color2.color ELSE target.material = mbtn_mat2.material
			)
		)
 
		ON mbtn_mat1 PICKED arg DO
		(
			mbtn_mat1.text = IF arg != undefined THEN arg.name ELSE "EMPTY"
		)
 
		ON mbtn_mat2 PICKED arg DO
		(
			mbtn_mat2.text = IF arg != undefined THEN arg.name ELSE "EMPTY"
		)
 
		ON btn_clearMats PRESSED DO
		(
			selection.material = undefined
		)
 
		ON btn_start PRESSED DO
		(
			local theObjects = selection as array
			local deltaZ = selection.max.z-selection.min.z
			local minZ = selection.min.z
			local maxHeightLimit = (spn_maxLimit.value as float/100.0*deltaZ)+minZ as float
			local minHeightLimit = (spn_minLimit.value as float/100.0*deltaZ)+minZ as float
			FOR obj in theObjects WHERE (isProperty obj "wireColor") DO
			(
				local objValue = ((obj.pos.z-minZ)*100/deltaZ)+(random (-spn_variation.value+spn_bias.value) (spn_variation.value+spn_bias.value))
				IF cbx_useGradient.checked THEN
				(
					local minR
					local minG
					local minB
					local deltaR
					local deltaG
					local deltaB
					IF cpck_color1.color.r >= cpck_color2.color.r THEN 
					(
						minR = cpck_color2.color.r
						deltaR = cpck_color1.color.r-cpck_color2.color.r
					)
					ELSE
					(
						minR = cpck_color1.color.r
						deltaR = cpck_color2.color.r-cpck_color1.color.r
					)
					IF cpck_color1.color.g >= cpck_color2.color.g THEN 
					(
						minG = cpck_color2.color.g
						deltaG = cpck_color1.color.g-cpck_color2.color.g
					)
					ELSE
					(
						minG = cpck_color1.color.g
						deltaG = cpck_color2.color.g-cpck_color1.color.g
					)
					IF cpck_color1.color.b >= cpck_color2.color.b THEN 
					(
						minB = cpck_color2.color.b
						deltaB = cpck_color1.color.b-cpck_color2.color.b
					)
					ELSE
					(
						minB = cpck_color1.color.b
						deltaB = cpck_color2.color.b-cpck_color1.color.b
					)
 
					local colorR = (((objValue+spn_offset.value)/100*deltaR)+minR)
					local colorG = (((objValue+spn_offset.value)/100*deltaG)+minG)
					local colorB = (((objValue+spn_offset.value)/100*deltaB)+minB)
					IF colorR < 0 DO colorR = 0
					IF colorG < 0 DO colorG = 0
					IF colorB < 0 DO colorB = 0
					IF colorR > 255 DO colorR = 255
					IF colorG > 255 DO colorG = 255
					IF colorB > 255 DO colorB = 255
 
					IF obj.pos.z >= maxHeightLimit THEN obj.wireColor = cpck_color1.color ELSE
					(
						IF obj.pos.z <= minHeightLimit THEN obj.wireColor = cpck_color2.color ELSE
						(
							obj.wireColor = (color colorR colorG colorB)
						)
					)
				)
				ELSE
				(
					IF obj.pos.z >= maxHeightLimit THEN assignColor obj "0" ELSE
					(
						IF obj.pos.z <= minHeightLimit THEN assignColor obj "1" ELSE
						(
							IF objValue >= (50+spn_offset.value) THEN assignColor obj "0" ELSE assignColor obj "1"
						)
					)
				)
			)
		)
	)
	createDialog heightColorizer
)
br0t's picture

I just testet your Script

I just testet your Script Marco. It works really well and is pretty much self explaining, really fun to play around with! Whenever I need the beiging-color effect I now know where to look for it ;)

Never get low & slow & out of ideas

Marco Brunetta's picture

Hehe cool, thanks.

Hehe cool, thanks.

marek.kowalski's picture

Hi Marco and Anubis Thank you

Hi Marco and Anubis

Thank you for the incredible effort. Both of your scripts work, though, it is the Marco's script that we find more refined and siuted to the task. In fact your script Marco, is perfect - if not for one thing :(
Let me explain.
The property that your script changes is the wirecolor. The problem is that I want to use proper vray material rather just wirecolor for both types of seats. what's more the material for each of the types of seats would usually be multi/sub to allow for the plastic and metal parts of the seat. How difficult is it to rewrite the script with this in mind? Is it possible at all?

Thank you,

Marek

Marco Brunetta's picture

This seemed like a fun

This seemed like a fun experiment, so I started playing with it and I might have got a bit carried away, but here's my take on this:

Running the script will create a rollout with a few options:
COLOR 1: the first color
COLOR 2: the second color (DUH!)
VARIATION: this adds randomness to the pattern. Setting it to 0 will result in half the seats using COLOR 1 and the other half using COLOR 2, while using 100 will produce a totally random pattern. Using something around 40-50 should produce the result you are looking for
LOW LIMIT: this can be used to force seats to use COLOR 2. So if you set it to 20%, every seat below 20% of the total height of the selection will use the COLOR 2 regardless of the VARIATION setting.
HIGH LIMIT: similar to LOW LIMIT, forces seats above this value to use COLOR 1
USE GRADIENT: Checking this box will have the script color the seats with a gradient instead of using just the two color.

To run just select a bunch of objects and hit START!.

I didn't test it much, nor dos it have much error checking, so if you have any problems let me know. And feel fry to modify as needed.

/*******************
by Marco Brunetta
[email protected]
********************/
 
(
	rollout heightColorizer "Height Colorizer"
	(
		colorPicker cpck_color1 "Color 1:" color:white pos:[40,10] 
		colorPicker cpck_color2 "Color 2:"color:blue pos:(cpck_color1.pos+[-40,25])
		spinner spn_variation "Variation:" range:[0,100,50] type:#integer fieldWidth:40 pos:(cpck_color2.pos+[-46,25]) 
		spinner spn_minLimit "Low Limit:" range:[0,100,0] type:#integer fieldWidth:40 pos:(spn_variation.pos+[-87,30])
		spinner spn_maxLimit "High Limit:" range:[0,100,100] type:#integer fieldWidth:40 pos:(spn_minLimit.pos+[-88,20])
		checkBox cbx_useGradient "Use Gradient" pos:(spn_maxLimit.pos+[-75,30])
		button btn_start "START!" width:130 height:30 pos:(cbx_useGradient.pos+[-28,30])
 
		ON btn_start PRESSED DO
		(
			local theObjects = selection as array
			local deltaZ = selection.max.z-selection.min.z
			local minZ = selection.min.z
			local maxHeightLimit = (spn_maxLimit.value as float/100.0*deltaZ)+minZ as float
			local minHeightLimit = (spn_minLimit.value as float/100.0*deltaZ)+minZ as float
			FOR obj in theObjects DO
			(
				local objValue = ((obj.pos.z-minZ)*100/deltaZ)+(random -spn_variation.value spn_variation.value)
				IF cbx_useGradient.checked THEN
				(
					local minR
					local minG
					local minB
					local deltaR
					local deltaG
					local deltaB
					IF cpck_color1.color.r >= cpck_color2.color.r THEN 
					(
						minR = cpck_color2.color.r
						deltaR = cpck_color1.color.r-cpck_color2.color.r
					)
					ELSE
					(
						minR = cpck_color1.color.r
						deltaR = cpck_color2.color.r-cpck_color1.color.r
					)
					IF cpck_color1.color.g >= cpck_color2.color.g THEN 
					(
						minG = cpck_color2.color.g
						deltaG = cpck_color1.color.g-cpck_color2.color.g
					)
					ELSE
					(
						minG = cpck_color1.color.g
						deltaG = cpck_color2.color.g-cpck_color1.color.g
					)
					IF cpck_color1.color.b >= cpck_color2.color.b THEN 
					(
						minB = cpck_color2.color.b
						deltaB = cpck_color1.color.b-cpck_color2.color.b
					)
					ELSE
					(
						minB = cpck_color1.color.b
						deltaB = cpck_color2.color.b-cpck_color1.color.b
					)
 
					local colorR = ((objValue/100*deltaR)+minR)
					local colorG = ((objValue/100*deltaG)+minG)
					local colorB = ((objValue/100*deltaB)+minB)
					IF colorR < 0 DO colorR = 0
					IF colorG < 0 DO colorG = 0
					IF colorB < 0 DO colorB = 0
					IF colorR > 255 DO colorR = 255
					IF colorG > 255 DO colorG = 255
					IF colorB > 255 DO colorB = 255
 
					IF obj.pos.z >= maxHeightLimit THEN obj.wireColor = cpck_color1.color ELSE
					(
						IF obj.pos.z <= minHeightLimit THEN obj.wireColor = cpck_color2.color ELSE
						(
							obj.wireColor = (color colorR colorG colorB)
						)
					)
				)
				ELSE
				(
					IF obj.pos.z >= maxHeightLimit THEN obj.wireColor = cpck_color1.color ELSE
					(
						IF obj.pos.z <= minHeightLimit THEN obj.wireColor = cpck_color2.color ELSE
						(
							obj.wireColor = IF objValue >= 50 THEN cpck_color1.color ELSE cpck_color2.color
						)
					)
				)
			)
		)
	)
	createDialog heightColorizer
)
Anubis's picture

Quick draft code

Interesting question, there is something on-the-fly, maybe not perfect...

-- define colors
color1 = blue
color2 = (white + blue) / 2
color3 = white
-- define arrays
botArray = #(color1, color3, color2, color2, color2, color2)
midArray = #(color1, color2, color3)
topArray = #(color3, color3, color3, color3, color3, color2)
 
zVal = #(50, 100, 300) -- Z pos limits
sArray = selection as array -- select and collect all seats
 
for obj in sArray do (
	local zPos = obj.pos.z
	if (zPos <= zVal[1]) then
	(
		obj.wireColor = botArray[random 1 botArray.count]
	)
	else if (zPos > zVal[1] and zPos <= zVal[2]) then
	(
		obj.wireColor = midArray[random 1 midArray.count]
	)
	else
	(
		obj.wireColor = topArray[random 1 topArray.count]
	)
)

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.