Photoshop Maya 3DS Max Blender Bryce Corel DRAW Cult3D Flash Bodypaint 3D Cinema 4D LightWave 3D ZBrush Rhinoceros SoftImage XSI Vue d'Esprit x

Top: Autodesk Maya: Scripts : How to sample color at any given point in a ramp

From our website  www tjgalda com    Skill level  intermediate    How do you query the colour in a ramp at any given point     Frustratingly  this isnt quite as simple as it sounds  Even the technical documentation from Autodesk states     Currently the routines to get the value of a ramp structure  with interpolation  are not available through MEL  which limits the use of this control by end users     So  we have to work around it in this case  We are able to sample the ramp and get back i how many colour entries there are  ii where they are in the ramp and iii  what colour they are  From that data  we can approximate fairly well what the ramp looks like  Lets build the tool for our example to do so on a relatively simple scale  You can add complexity later  but to keep things simple  were going to sample a simple ramp with two colours and a linear interpolation between the two colours  A ramp such as this mel code will create     Note  you can view all the mel on the website  www tjgalda com      Create the gradient using a ramp   string  tempName    shadingNode  asShader ramp    string  tj rampNode    rename  tempName tj gradientColour    string  tj rampWin    window  t tj Ramp Viewer tj rampWin    columnLayout   rampColorPort  node  tj rampNode   showWindow  tj rampWin     setAttr   tj rampNode    colorEntryList 0  color   type double3 0 988 1 0 8    setAttr   tj rampNode    colorEntryList 1  color   type double3 0 0 0 235    setAttr   tj rampNode    colorEntryList 1  position  1 0   removeMultiInstance  break true   tj rampNode    colorEntryList 2     showWindow  tj rampWin         Now that we have the ramp  we can gather information about the ramp  We need to determine where are they and what colour  create an array to catch each position and match the entry in the list of the ramp  Finally we will create an array to catch colour  use a vector array to maintain match in the list of the ramp     Where are they and what colour  Create an array to catch each position and match entry in list   int  entries    getAttr  size   tj rampNode  colorEntryList     vector  entry colour     for   i   0   i    entries   i          entry pos  i     getAttr   tj rampNode  colorEntryList   i   position     float  entryList colours      getAttr   tj rampNode  colorEntryList   i   color      entry colour  i               and print back the results  print   n entry pos   is n                  n     print  entry pos   print   nn                  n entry colour   is n                  n    print  entry colour          entry pos   is                      0  1                       entry colour   is                      0 988 1 0 8  0 0 0 235    In our example now  we can see that we have the two colour entries at 0 and 1  with the associated colour mix  Now we can work with some basic calculations to deduce what the colours are between  After we know the colour information  we can then begin to deduce what the ramp is like  The first step is to find the difference or delta between the two colours on each channel  From there  we can divide up the colour on regular intervals and determine what the exact colour is at any specific point on the map     This is a sampling step  How many intervals should we break the ramp into   int  step   20         Find the delta difference for each channel  Use temp vectors to get data out of the array easily  For our example to keep it simple  we can make some assumptions about where each entry is and what colours they are  We will assume only two colours  and that the first colour is brighter  Of course  one should build in robustness to remove these assumptions with true data     vector  tempTopV    entry colour 0    vector  tempBotV    entry colour 1      Use absolute to ensure its not a negative value  float  differenceR    abs  tempTopV x    tempBotV x     float  differenceG    abs  tempTopV y    tempBotV y     float  differenceB    abs  tempTopV z    tempBotV z           Divide up the delta per step  This is the amount of change per step that each colour travels   float  deltaStepR    differenceR    step   float  deltaStepG    differenceG    step   float  deltaStepB    differenceB    step         Now  start number    delta per step   the number of steps    end number  in other words  we have broken down what the difference can be at each interval  Finalize by building the arrays   float  colourStepsR     colourStepsG     colourStepsB      colourStepsR 0     tempBotV x    colourStepsG 0     tempBotV y    colourStepsB 0     tempBotV z         Each new step is the old step   the delta for that colour   for   i   1   i

How to sample color at any given point in a ramp

From our website: www.tjgalda.com Skill level: intermediate How do you query the colour in a ramp at any given point? Frustratingly, this isnt quite as simple as it sounds. Even the technical documentation from Autodesk states: Currently the routines to get the value of a ramp structure (with interpolation) are not available through MEL, which limits the use of this control by end users. So, we have to work around it in this case. We are able to sample the ramp and get back i)how many colour entries there are, ii)where they are in the ramp and iii) what colour they are. From that data, we can approximate fairly well what the ramp looks like. Lets build the tool for our example to do so on a relatively simple scale. You can add complexity later, but to keep things simple, were going to sample a simple ramp with two colours and a linear interpolation between the two colours. A ramp such as this mel code will create: Note: you can view all the mel on the website. www.tjgalda.com Create the gradient using a ramp: string $tempName = `shadingNode -asShader ramp`; string $tj_rampNode = `rename $tempName tj_gradientColour`; string $tj_rampWin = `window -t tj Ramp Viewer tj_rampWin`; columnLayout; rampColorPort -node $tj_rampNode; showWindow $tj_rampWin; setAttr ($tj_rampNode + .colorEntryList[0].color) -type double3 0.988 1 0.8 ; setAttr ($tj_rampNode + .colorEntryList[1].color) -type double3 0 0 0.235 ; setAttr ($tj_rampNode + .colorEntryList[1].position) 1.0; removeMultiInstance -break true ($tj_rampNode + .colorEntryList[2]); showWindow $tj_rampWin; Now that we have the ramp, we can gather information about the ramp. We need to determine where are they and what colour, create an array to catch each position and match the entry in the list of the ramp. Finally we will create an array to catch colour, use a vector array to maintain match in the list of the ramp. Where are they and what colour? Create an array to catch each position and match entry in list. int $entries = `getAttr -size ($tj_rampNode+.colorEntryList)`; vector $entry_colour[]; for ($i = 0; $i < $entries; $i ++) { $entry_pos[$i] = `getAttr ($tj_rampNode+.colorEntryList[+$i+].position)`; float $entryList_colours[] = `getAttr ($tj_rampNode+.colorEntryList[+$i+].color)`; $entry_colour[$i] = >; } //and print back the results print ("n$entry_pos[] is n==================n"); print $entry_pos; print ("nn==================n$entry_colour[] is n==================n); print $entry_colour; $entry_pos[] is ================== 0 1 ================== $entry_colour[] is ================== 0.988 1 0.8 0 0 0.235 In our example now, we can see that we have the two colour entries at 0 and 1, with the associated colour mix. Now we can work with some basic calculations to deduce what the colours are between. After we know the colour information, we can then begin to deduce what the ramp is like. The first step is to find the difference or delta between the two colours on each channel. From there, we can divide up the colour on regular intervals and determine what the exact colour is at any specific point on the map. This is a sampling step. How many intervals should we break the ramp into? int $step = 20; Find the delta/difference for each channel. Use temp vectors to get data out of the array easily. For our example to keep it simple, we can make some assumptions about where each entry is and what colours they are. We will assume only two colours, and that the first colour is brighter. Of course, one should build in robustness to remove these assumptions with true data. vector $tempTopV = $entry_colour[0]; vector $tempBotV = $entry_colour[1]; Use absolute to ensure its not a negative value float $differenceR = `abs($tempTopV.x - $tempBotV.x)`; float $differenceG = `abs($tempTopV.y - $tempBotV.y)`; float $differenceB = `abs($tempTopV.z - $tempBotV.z)`; Divide up the delta per step. This is the amount of change per step that each colour travels. float $deltaStepR = $differenceR / $step; float $deltaStepG = $differenceG / $step; float $deltaStepB = $differenceB / $step; Now, start number + (delta per step * the number of steps) = end number, in other words, we have broken down what the difference can be at each interval. Finalize by building the arrays. float $colourStepsR[], $colourStepsG[], $colourStepsB[]; $colourStepsR[0] = $tempBotV.x; $colourStepsG[0] = $tempBotV.y; $colourStepsB[0] = $tempBotV.z; Each new step is the old step + the delta for that colour. for ($i = 1; $i

ADVERTISMENT

Looking for Job?

3DK.org is hiring 3ds max tutorial writers! If you're interested, please send your resume to info@NO-SPAMcgtutorials.com (remove NO-SPAM). Please include few examples of your previous tutorials and/or articles.

Comments

No comments at this moment

Highest Rated

Made most realistic water drop effect in Photoshop

Water drops on leaf - Made most realistic water drop effect in Photoshop....

Rated:**** with 488 hits

Draw Exploding planet earth in photoshop using tool and filters

Exploding planet earth in photoshop - Draw Exploding planet earth in photoshop using tool and filters....

Rated:**** with 2474 hits

Learn how to change color of objects in Flash  Choose which colors you  8217 ll use  and change colors in your Flash Movie

Changing color in Flash - Learn how to change color of objects in Flash. Choose which colors you̵...

Rated:**** with 151 hits

Corel Draw can do more then u expect    Check it

Draw 3D earth in Corel Draw. - Corel Draw can do more then u expect. Check it....

Rated:**** with 295 hits

Most Popular

I am going to show you that is quick and easy way to convert a picture in vector effect  Here we go

Vector Effect - I am going to show you that is quick and easy way to convert a picture in v...

Rated:*** with 425727 hits

In this tutorial  we present ten favorite creative and useful techniques

Ten Photoshop Tips and Tricks - In this tutorial, we present ten favorite creative and useful techniques....

Rated:*** with 411325 hits

I am going to show you a quick and easy variation on metallic text effect

Metallic Type Text Effect - I am going to show you a quick and easy variation on metallic text effect....

Rated:*** with 395899 hits

How to draw custom arrows in photoshop with the pen tool with a final 3 D embossing effect

How to draw custom arrows in photoshop with the pen tool with a final 3-D embossing effect. - How to draw custom arrows in photoshop with the pen tool with a final 3-D e...

Rated:*** with 354860 hits