<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Changing Object Diffuse Colour Based On Distance Between Objects in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262942#M17956</link>
    <description>seven years ago the script controller probably didn't have some features which it has today.&lt;BR /&gt;so we can see several problems in the tutorial:&lt;BR /&gt;&lt;BR /&gt;#1 it's a bad practice now to use a PathName values to define max objects used in the expression. &lt;BR /&gt;because any object renaming or deleting will cause the script failure.&lt;BR /&gt;&lt;BR /&gt;#2 it's not a good idea to add any unnecessary nodes to the scene.&lt;BR /&gt;in the tutorial it's a test sphere. &lt;BR /&gt;&lt;BR /&gt;#3 it's not a good practice to add a script to one controller to change the another.  &lt;BR /&gt;in the tutorial the script applied to the scale controller to change the material's difffuse.&lt;BR /&gt;&lt;BR /&gt;here is how the same idea has to look today:&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;fn setupDistanceColorController mat source target maxdistance:100 = &lt;BR /&gt;( &lt;BR /&gt; c = mat.diffuse.controller = point3_script()&lt;BR /&gt; c.AddConstant "maxdistance" maxdistance&lt;BR /&gt; c.AddObject "source" (NodeTransformMonitor node:source)&lt;BR /&gt; c.AddObject "target" (NodeTransformMonitor node:target)&lt;BR /&gt; &lt;BR /&gt; str =  "if isvalidnode source and isvalidnode target then\n"&lt;BR /&gt; str += "(\n"&lt;BR /&gt; str += " c = amin 1.0 ((distance source target)/maxdistance)\n"&lt;BR /&gt; str += " \n"&lt;BR /&gt; str += ")\n"&lt;BR /&gt; str += "else "&lt;BR /&gt; &lt;BR /&gt; c.SetExpression str&lt;BR /&gt; c&lt;BR /&gt;)&lt;BR /&gt;/*&lt;BR /&gt;(&lt;BR /&gt; delete objects&lt;BR /&gt; mat = standard name:"Distance Meter Material"&lt;BR /&gt; source = box name:"source" isselected:on material:mat&lt;BR /&gt; target = box name:"target" wirecolor:green&lt;BR /&gt; setupDistanceColorController mat source target&lt;BR /&gt;)&lt;BR /&gt;*/&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;execute the function and run the commented part of the script to make a test scene.&lt;BR /&gt;move source or target nodes to see the color change.&lt;BR /&gt;&lt;BR /&gt;the maxdistance parameter is used to map distance value (0+) to color (0-1)&lt;BR /&gt;&lt;BR /&gt;PS. i forgot to say about another problem in the tutorial:&lt;BR /&gt;#4 in animate mode ON the script adds key to the diffuse controller every transform change. &lt;BR /&gt;which is definitely wrong.</description>
    <pubDate>Fri, 07 Sep 2012 16:42:36 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2012-09-07T16:42:36Z</dc:date>
    <item>
      <title>Changing Object Diffuse Colour Based On Distance Between Objects</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262938#M17952</link>
      <description>I followed this tutorial on CG-Academy: &lt;A href="http://www.cg-academy.net/pages/free_tutorials/tut_scripted_color_to_length/tut_scripted_color.php" target="_blank"&gt;http://www.cg-academy.net/pages/free_tutorials/tut_scripted_color_to_length/tut_scripted_color.php&lt;/A&gt; to try to get an object's diffuse colour to change when the distance between two points (in this example) is made shorter or larger.  The problem is that it doesn't work, even when I download the final file at the end and loaded it, it doesn't work.  Does anyone know I can achieve the same effect in the more up to date versions of Max?&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;-Harry</description>
      <pubDate>Thu, 06 Sep 2012 23:16:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262938#M17952</guid>
      <dc:creator>hazmondo</dc:creator>
      <dc:date>2012-09-06T23:16:29Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Object Diffuse Colour Based On Distance Between Objects</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262939#M17953</link>
      <description>First thing is that "DependsOn" is deprecated (shouldn't be used in new scripts) and has been since Max 8.&lt;BR /&gt;&lt;BR /&gt;Create 2 variables, select each one, click Assign Node and select the appropriate object.&lt;BR /&gt;Change the provided script to use those variables instead of the $object names and it should work.&lt;BR /&gt;&lt;BR /&gt;Note. Because of the hard-coded values in the rag.hue= line you will find that the distance over which the script works is quite limited - you may need to play with those valuse to suit your scene.</description>
      <pubDate>Fri, 07 Sep 2012 09:51:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262939#M17953</guid>
      <dc:creator>Steve_Curley</dc:creator>
      <dc:date>2012-09-07T09:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Object Diffuse Colour Based On Distance Between Objects</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262940#M17954</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;I followed this tutorial on CG-Academy: &lt;A href="http://www.cg-academy.net/pages/free_tutorials/tut_scripted_color_to_length/tut_scripted_color.php" target="_blank"&gt;http://www.cg-academy.net/pages/free_tutorials/tut_scripted_color_to_length/tut_scripted_color.php&lt;/A&gt; to try to get an object's diffuse colour to change when the distance between two points (in this example) is made shorter or larger.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;it's very old tutorial. it was not a good solution seven years ago but now it's an example how shouldn't do a scripted controller. &lt;BR /&gt;do you want to see the right way?</description>
      <pubDate>Fri, 07 Sep 2012 12:58:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262940#M17954</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-09-07T12:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Object Diffuse Colour Based On Distance Between Objects</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262941#M17955</link>
      <description>Feel free Denis - the general situation of "alter  based on a distance" comes up often enough that a properly written generic solution would be quite useful.</description>
      <pubDate>Fri, 07 Sep 2012 13:12:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262941#M17955</guid>
      <dc:creator>Steve_Curley</dc:creator>
      <dc:date>2012-09-07T13:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Object Diffuse Colour Based On Distance Between Objects</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262942#M17956</link>
      <description>seven years ago the script controller probably didn't have some features which it has today.&lt;BR /&gt;so we can see several problems in the tutorial:&lt;BR /&gt;&lt;BR /&gt;#1 it's a bad practice now to use a PathName values to define max objects used in the expression. &lt;BR /&gt;because any object renaming or deleting will cause the script failure.&lt;BR /&gt;&lt;BR /&gt;#2 it's not a good idea to add any unnecessary nodes to the scene.&lt;BR /&gt;in the tutorial it's a test sphere. &lt;BR /&gt;&lt;BR /&gt;#3 it's not a good practice to add a script to one controller to change the another.  &lt;BR /&gt;in the tutorial the script applied to the scale controller to change the material's difffuse.&lt;BR /&gt;&lt;BR /&gt;here is how the same idea has to look today:&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;fn setupDistanceColorController mat source target maxdistance:100 = &lt;BR /&gt;( &lt;BR /&gt; c = mat.diffuse.controller = point3_script()&lt;BR /&gt; c.AddConstant "maxdistance" maxdistance&lt;BR /&gt; c.AddObject "source" (NodeTransformMonitor node:source)&lt;BR /&gt; c.AddObject "target" (NodeTransformMonitor node:target)&lt;BR /&gt; &lt;BR /&gt; str =  "if isvalidnode source and isvalidnode target then\n"&lt;BR /&gt; str += "(\n"&lt;BR /&gt; str += " c = amin 1.0 ((distance source target)/maxdistance)\n"&lt;BR /&gt; str += " \n"&lt;BR /&gt; str += ")\n"&lt;BR /&gt; str += "else "&lt;BR /&gt; &lt;BR /&gt; c.SetExpression str&lt;BR /&gt; c&lt;BR /&gt;)&lt;BR /&gt;/*&lt;BR /&gt;(&lt;BR /&gt; delete objects&lt;BR /&gt; mat = standard name:"Distance Meter Material"&lt;BR /&gt; source = box name:"source" isselected:on material:mat&lt;BR /&gt; target = box name:"target" wirecolor:green&lt;BR /&gt; setupDistanceColorController mat source target&lt;BR /&gt;)&lt;BR /&gt;*/&lt;BR /&gt;&lt;/PRE&gt;&lt;BR /&gt;execute the function and run the commented part of the script to make a test scene.&lt;BR /&gt;move source or target nodes to see the color change.&lt;BR /&gt;&lt;BR /&gt;the maxdistance parameter is used to map distance value (0+) to color (0-1)&lt;BR /&gt;&lt;BR /&gt;PS. i forgot to say about another problem in the tutorial:&lt;BR /&gt;#4 in animate mode ON the script adds key to the diffuse controller every transform change. &lt;BR /&gt;which is definitely wrong.</description>
      <pubDate>Fri, 07 Sep 2012 16:42:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262942#M17956</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-09-07T16:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Object Diffuse Colour Based On Distance Between Objects</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262943#M17957</link>
      <description>Wouldn't a distance-based Falloff map driving a Gradient Ramp in mapped mode eliminate the need for a script at all?</description>
      <pubDate>Mon, 10 Sep 2012 13:32:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262943#M17957</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-09-10T13:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: Changing Object Diffuse Colour Based On Distance Between Objects</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262944#M17958</link>
      <description>Thanks for the replies, I was able to get it working &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 18 Sep 2012 15:14:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/changing-object-diffuse-colour-based-on-distance-between-objects/m-p/4262944#M17958</guid>
      <dc:creator>hazmondo</dc:creator>
      <dc:date>2012-09-18T15:14:13Z</dc:date>
    </item>
  </channel>
</rss>

