Copying/Modifying Surface Color Values

Hi,

I wonder if anyone can help me. I'm working on a script based of Casual's mcjSpreadTex - https://sites.google.com/site/mcasualsdazscripts5/mcjspreadtex

I've modified it so it copies color values, which then can be applied to other channels. However, I want to some operations to it ie. clamp color to a minimal value of 32 rather than 0 and retarget colors above values (say, 255,192,128 to 160,120,80). I'm thinking retargeting is done by converting the values from RGB to HSV and then changes/clamps the colors to a value of 67. Is that possible? Or do I have to work with the original RGB values.

Thanks.

Comments

  • djigneodjigneo Posts: 283

    Once you have a Color object, you can get the HSV code from the rgb property.

    var oColor = new Color(r, g, b);var nHsvCode = oColor.rgb;

    Then you could make adjustments to that value, then set it back:

    oColor.setRgb(nHsvCode);

    I hope this puts you on the right track.

  • wowiewowie Posts: 2,029

    Thanks.

    Will try it out.

  • mCasualmCasual Posts: 4,607
    edited November 2015
    wowie said:

    Thanks.

    Will try it out.

    here's the list of properties a Color has

     

    Number 	blueNumber 	greenNumber 	hueString 	nameNumber 	redNumber 	rgbNumber 	saturationNumber 	value

     

    if we're lucky, all those can be written to

    i know r,g,b are numbers between 0 and 255

    now lets see what 'value' is for full-intensity white

     

    node = Scene.getPrimarySelection()obj = node.getObject()shp = obj.getCurrentShape();mat = shp.getMaterial( 0 )co = mat.getDiffuseColor();debug( co.value )

     

    the answer is 255

    now lets see if it can be written to

     

    node = Scene.getPrimarySelection()obj = node.getObject()shp = obj.getCurrentShape();mat = shp.getMaterial( 0 )co = mat.getDiffuseColor();debug( co.value )if( co.value > ( 0.67 * 255 ) ){    co.value = Math.round( co.value * 0.67 )}mat.setDiffuseColor( co );

     

    yes, it workks perfectly !

    Post edited by mCasual on
  • wowiewowie Posts: 2,029
    edited November 2015

    Yeah. I thought that's the way to go. Glad it worked and a lot less to write compared to doing it with RGB values. I'll try putting that into the script you've made.

    OK just tried it and it works. I've also found 0.67 was too high. Had to be set to 0.6275 so max value of any color is 160.

    Thanks Jacques!

    Post edited by wowie on
  • wowiewowie Posts: 2,029
    edited November 2015

    Here's the edits I've made.

    var node = Scene.getPrimarySelection();if( node ){	var obj = node.getObject();	if( obj )	{		var shape = obj.getCurrentShape();		var mats = shape.getAllSelectedMaterials();		var n = mats.length;		for( var i = 0; i < n; i++ )		{			transferColor( mats[i] );		}	}}function transferColor( mat ){	var prop1 = mat.findProperty( "Diffuse Color" );	if( !prop1 )	{		return;	}	var col = prop1.getColorValue();	if( !col )	{		return;	}	if( col.value > ( 0.6275 * 255 ) )	{	    col.value = Math.round( col.value * 0.6275 )	}	if( col.red < 32 ) col.red = 32	if( col.green < 32 ) col.green = 32	if( col.blue < 32 ) col.blue = 32	mat.setDiffuseColor( col );	var prop4 = mat.findProperty( "Translucency Color" );	if( prop4 )	{		prop4.setColorValue( col );	}	var prop5 = mat.findProperty( "Diffuse2 Color" );	if( prop5 )	{		prop5.setColorValue( col );	}}

     

    Just need to input the texture operations. Right now, it only works on colors.

    Post edited by wowie on
  • wowiewowie Posts: 2,029
    edited January 2016

    Made some changes. Now instead of multiplying color values, it is now clamped so the max values are always 160 of the highest color value.

    So, from this:

    	if( col.value > ( 0.6275 * 255 ) )	{	    col.value = Math.round( col.value * 0.6275 )	}

    To this:

    	if( col.value > ( 0.6275 * 255 ) )	{	    col.value = Math.max( 255 * 0.6275 )	}

     

    Post edited by wowie on
Sign In or Register to comment.