<?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 Assign random vertex color per element in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127413#M12566</link>
    <description>&lt;P&gt;Hi, im using substance painter a lot and i have to assign to my objects random vertex colors to each element to make selections. Is there any script to do this automatically? ty&lt;BR /&gt;&lt;BR /&gt;ps. if there is someone using substance too and knows other way of passing selections into substance im all ears &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 03 Jun 2017 22:35:08 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-06-03T22:35:08Z</dc:date>
    <item>
      <title>Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127413#M12566</link>
      <description>&lt;P&gt;Hi, im using substance painter a lot and i have to assign to my objects random vertex colors to each element to make selections. Is there any script to do this automatically? ty&lt;BR /&gt;&lt;BR /&gt;ps. if there is someone using substance too and knows other way of passing selections into substance im all ears &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jun 2017 22:35:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127413#M12566</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-03T22:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127569#M12567</link>
      <description>&lt;P&gt;If random vertex color per element is enough (which may or may not result in duplicates, changing seed might help sometimes), you can use dataChannel modifier for that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dataChannelVC.gif" style="width: 658px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/363289i4E929DC86B062572/image-size/large?v=v2&amp;amp;px=999" role="button" title="dataChannelVC.gif" alt="dataChannelVC.gif" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2017 06:05:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127569#M12567</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2017-06-04T06:05:16Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127596#M12568</link>
      <description>&lt;P&gt;And as a script that ensures unique colors:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;fn shuffle arr =
    for counter = arr.count to 1 by -1 collect
    (
        local swapIndex = random 1 counter
        swap arr[random 1 counter] arr[counter]
    )

fn incrementCounters &amp;amp;r &amp;amp;g &amp;amp;b step =
    if (b += step) &amp;gt; 256 do
    (
        b = 1
        if (g += step) &amp;gt; 256 do
        (
            g = 1
            if (r += step) &amp;gt; 256 do r = 1
        )
    )

fn getElements mesh =
(
    local vertCount = mesh.numVerts
    local faces = mesh.faces as bitArray
    local facesByVert = for v = 1 to vertCount collect #()

    for face in faces do
    (
        local faceVerts = getFace mesh face
        append facesByVert[faceVerts[1]] face
        append facesByVert[faceVerts[2]] face
        append facesByVert[faceVerts[3]] face
    )

    for face in faces collect
    (
        local i = 0, element = #(face), elementVerts = #()

        while (local f = element[i += 1]) != undefined do if faces[f] do
        (
            faces[f] = false
            local faceVerts = getFace mesh f

            for v = 1 to 3 do facesByVert[faceVerts[v]] = 
                for vertFace in facesByVert[faceVerts[v]] where faces[vertFace] collect
                (
                    append element vertFace
                    append elementVerts (int faceVerts[v])
                    dontCollect
                )
        )
        elementVerts as bitarray
    )
)

fn assignUniqueElementColor obj op shuffleElements:off =
(
    local elements = getElements (snapshotAsMesh obj)
    local stepCount = elements.count^(double 1/3) + 1
    local step = 255./stepCount
    local redArr = shuffle (#(0) + #{1..255})
    local greenArr = shuffle (#(0) + #{1..255})
    local blueArr = shuffle (#(0) + #{1..255})
    local r = 1, g = 1, b = 1
    
    if shuffleElements do
      elements = shuffle elements

    for element in elements do
    (
        op.setVertColor obj 0 element [redArr[int r], greenArr[int g], blueArr[int b]]
        incrementCounters &amp;amp;r &amp;amp;g &amp;amp;b step
    )
)

if isKindOf $ Editable_Mesh then assignUniqueElementColor $ meshop shuffleElements:on
else if isKindOf $ Editable_Poly do assignUniqueElementColor $ polyop shuffleElements:on&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you instead want to bind it to a shortcut, you can save it as a .ms file and use the &lt;A href="http://www.scriptspot.com/3ds-max/scripts/macroscript-creator" target="_self"&gt;macroscript creator&lt;/A&gt; to make a macro for it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2017 07:00:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127596#M12568</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2017-06-04T07:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127632#M12569</link>
      <description>&lt;P&gt;Thanks again, exactly what i needed &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2017 08:55:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127632#M12569</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-04T08:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127760#M12570</link>
      <description>&lt;P&gt;One more q: this script is independent to data channel modifier and cant be used in previous max versions? thanks again&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2017 12:48:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127760#M12570</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-06-04T12:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127998#M12571</link>
      <description>&lt;P&gt;Yes, it works with any editable mesh / editable poly that's currently selected and should work across most of the old max version, more than a decade back at the very least.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2017 19:53:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/7127998#M12571</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2017-06-04T19:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9530890#M12572</link>
      <description>&lt;P&gt;Hey, this is super cool.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to do the same but apply to all objects instead of just elements?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, I have 9 objects that will be textured in Substance Painter and I want a random vertex color for each object (to use as an ID mask).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 May 2020 03:14:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9530890#M12572</guid>
      <dc:creator>Jixal</dc:creator>
      <dc:date>2020-05-21T03:14:42Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9533474#M12573</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7802619"&gt;@Jixal&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have 9 objects that will be textured in Substance Painter and I want a random vertex color for each object (to use as an ID mask).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Something like&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;fn smootherStep x = 
    x * x * x * (x * (x * 6 - 15) + 10)

fn shuffle arr =
    for counter = arr.count to 1 by -1 collect
    (
        local swapIndex = random 1 counter
        swap arr[random 1 counter] arr[counter]
    )

fn assignUniqueVertexColor objs shuffleItems:off seed:0 =
(
    local maxVal = 256^3 - 1d0
    local maxCount = objs.count
    local counter = 0d0

    if shuffleItems and ::seed seed == OK do
        objs = shuffle objs

    for obj in objs do
    (
        local clr = smootherStep (counter / maxCount) * maxVal
        if isKindOf obj Editable_Poly do polyOp.setVertColor obj 0 #all [bit.shift (bit.and clr 0xff0000) -16, bit.shift (bit.and clr 0x00ff00) -8, bit.and clr 0x0000ff]
        counter += 1
    )
)

assignUniqueVertexColor (getCurrentSelection())&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 07:18:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9533474#M12573</guid>
      <dc:creator>Swordslayer</dc:creator>
      <dc:date>2020-05-22T07:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9533506#M12574</link>
      <description>&lt;LI-CODE lang="general"&gt; ::seed seed&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I like it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 May 2020 07:40:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9533506#M12574</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2020-05-22T07:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9553674#M12575</link>
      <description>&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 00:03:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9553674#M12575</guid>
      <dc:creator>Jixal</dc:creator>
      <dc:date>2020-06-02T00:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9647055#M12576</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I tried to use data channel for vertex color element, but it seems that it kills uv map channel...&lt;/P&gt;&lt;P&gt;Your script run fine. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 15:36:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9647055#M12576</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-07-21T15:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9648020#M12577</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Joker Martini just released a really nice script that does everything that we want for vertex colouring objects and elements-&amp;nbsp;&lt;A href="https://jokermartini.com/product/vertex-color-editor/" target="_blank"&gt;https://jokermartini.com/product/vertex-color-editor/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lightweight, simple and slick. Love it.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 23:30:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/9648020#M12577</guid>
      <dc:creator>Jixal</dc:creator>
      <dc:date>2020-07-21T23:30:30Z</dc:date>
    </item>
    <item>
      <title>Re: Assign random vertex color per element</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/11811747#M12578</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;This is very useful. thanks for the effort!&lt;BR /&gt;could it be easy to convert wirecolor to vertex color for all objects or selected objects?&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2023 05:21:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/assign-random-vertex-color-per-element/m-p/11811747#M12578</guid>
      <dc:creator>alnoman.7cgi</dc:creator>
      <dc:date>2023-03-10T05:21:25Z</dc:date>
    </item>
  </channel>
</rss>

