<?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: Tangent to Vertex Colour in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922585#M2650</link>
    <description>&lt;P&gt;when iterate faces,the &amp;lt;getVCFace&amp;gt; will collected #{1..numCPPverts},it is similar to houdini's&amp;nbsp;&amp;lt;linear vertex index&amp;gt;,I don't know any other way to get the vertex number of each face in max,per face must has unique vertex num to set color.&lt;/P&gt;&lt;P&gt;houdini's result export to unity is also correct,so ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;forgot about this ,may be max just can not&amp;nbsp; do this&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help. It has given me a lot of inspiration. Perhaps one day in the future, I can solve this problem and I will come back and post the code&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2023 08:54:55 GMT</pubDate>
    <dc:creator>547057474</dc:creator>
    <dc:date>2023-04-26T08:54:55Z</dc:date>
    <item>
      <title>Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11919657#M2640</link>
      <description>&lt;P&gt;a continuation of a thread on cgtalk which is neigh on impossible to post to these days&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this works for me btw&lt;/P&gt;&lt;LI-CODE lang="general"&gt;geo = $
convertToMesh geo 

meshop.defaultmapFaces geo 0; 
geo.showVertexColors = true

norMod = Edit_Normals()
addModifier geo norMod
tcols = #()

for i = 1 to getNumFaces geo do
( 
	local face = getFace geo i
	local tface = getTVFace geo i

	local v1 = getVert geo face[1]
	local v2 = getVert geo face[2]
	local v3 = getVert geo face[3]

	local w1 = getTVert geo tface[1]
	local w2 = getTVert geo tface[2]
	local w3 = getTVert geo tface[3]
 
	local e1 = v2-v1
	local e2 = v3-v1 

	local delta_u1 = w2.x - w1.x 
	local delta_u2 = w3.x - w1.x 
	local delta_v1 = w2.y - w1.y 
	local delta_v2 = w3.y - w1.y 

	local tangent = (delta_v1 * e2 - delta_v2 * e1) / (delta_v1 * delta_u2 - delta_v2 * delta_u1) 
	for j = 1 to 3 do 
	(
		local normalID = norMod.getNormalID i j
		local normal = normalize(norMod.GetNormal normalID )
		tangent = normalize(tangent - (dot tangent normal)*normal)           
		local bitangent = cross normal tangent 
		local TBN = Matrix3 tangent bitangent normal [0,0,0]
		TBN = inverse TBN

		smNor = [0,0,0] 
		norsID_bit = #{}
		norMod.ConvertVertexSelection #{face[j]} norsID_bit 
		for k in norsID_bit do smNor += norMod.getNormal k
		smNor = normalize smNor 

		tnor = normalize(smNor * TBN) 
		tnor = tnor *0.5 +0.5
		tcol = [tnor.x *255.0, tnor.y *255.0, tnor.z *255.0] as color              
		append tcols #(tcol, i, j)
	)
)

convertToMesh geo 
visited =#{};
for v = 1  to tcols.count do
(
	vcverts = getVCFace geo tcols[v][2];
	vci = vcverts[tcols[v][3]];

	if not visited[vci] then
	(
		visited[vci] = true;
		setVertColor geo vci tcols[v][1];
	)
)
update geo&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 07:47:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11919657#M2640</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2023-04-25T07:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11919958#M2641</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snipaste_2023-04-25_18-18-36.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1206412i57A2FAC2E276D85C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snipaste_2023-04-25_18-18-36.png" alt="Snipaste_2023-04-25_18-18-36.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; this is my result from you code,also weird,aren't you ?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 10:21:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11919958#M2641</guid>
      <dc:creator>547057474</dc:creator>
      <dc:date>2023-04-25T10:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11919975#M2642</link>
      <description>&lt;P&gt;ok Yoda&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;perhaps you want the "exploded" version you could try this...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;meshop.setmapsupport geo true;
setNumCPVVerts geo (3 * getNumFaces geo)
--defaultVCFaces geo; --this is wrong :/

vi = 1
for f = 1 to getNumFaces geo do 
(
	setVCFace geo f [vi, vi + 1, vi + 2];
	vi += 3;
)	

for v = 1  to tcols.count do
(
	vcverts = getVCFace geo tcols[v][2];
	vci = vcverts[tcols[v][3]];

	setVertColor geo vci tcols[v][1];
)
update geo&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 15:13:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11919975#M2642</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2023-04-25T15:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920041#M2643</link>
      <description>&lt;P&gt;for my case,this box has 108 tri faces,per face has 3 verteces, &amp;lt;tcols&amp;gt; collected 324 colors,and the num of cppvertes is also 324,so i dont think it will draw twice per vertex.&amp;nbsp;isn't it?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 11:13:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920041#M2643</guid>
      <dc:creator>547057474</dc:creator>
      <dc:date>2023-04-25T11:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920097#M2644</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="547057474_0-1682422707494.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1206432iAEC07B9BCA8A5D79/image-size/medium?v=v2&amp;amp;px=400" role="button" title="547057474_0-1682422707494.png" alt="547057474_0-1682422707494.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It's a bit strange&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 11:39:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920097#M2644</guid>
      <dc:creator>547057474</dc:creator>
      <dc:date>2023-04-25T11:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920099#M2645</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="547057474_0-1682422825698.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1206433i82CD9FD4DA0DC10D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="547057474_0-1682422825698.png" alt="547057474_0-1682422825698.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;i made in Houdini ,this is i wanted,but not work in max&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 11:42:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920099#M2645</guid>
      <dc:creator>547057474</dc:creator>
      <dc:date>2023-04-25T11:42:20Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920161#M2646</link>
      <description>&lt;P&gt;what result do you get from the original script&amp;nbsp;@ the top of the thread with a default box ?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 12:04:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920161#M2646</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2023-04-25T12:04:56Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920530#M2647</link>
      <description>&lt;P&gt;to "match" the uv's (hard edges at the uv seams) use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;note I've changed the exploded version above as it had an error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;meshop.setmapsupport geo true;
setNumCPVVerts geo (getNumTVerts geo);
for f = 1 to getNumFaces geo do  setVCFace geo f (getTVFace geo f)

visited =#{};
for v = 1  to tcols.count do
(
	vcverts = getVCFace geo tcols[v][2];
	vci = vcverts[tcols[v][3]];

	if not visited[vci] then
	(
		visited[vci] = true;
		setVertColor geo vci tcols[v][1];
	)
)
update geo&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 15:14:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11920530#M2647</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2023-04-25T15:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922002#M2648</link>
      <description>&lt;P&gt;you mean this one ?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snipaste_2023-04-24_15-22-00.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1206781i7885FE399419C04F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snipaste_2023-04-24_15-22-00.png" alt="Snipaste_2023-04-24_15-22-00.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;LI-CODE lang="general"&gt;geo = $
        convertToMesh geo 
        addModifier geo (vertexpaint())
        geo.showVertexColors = true

        addModifier geo (Edit_Normals()) 
        norMod = geo.Edit_Normals

        tcols = #()
        for i = 1 to getNumFaces geo do( 
            local face = getFace geo i
            local tface = getTVFace geo i

            local v1 = getVert geo face[1]
            local v2 = getVert geo face[2]
            local v3 = getVert geo face[3]
    
            local w1 = getTVert geo tface[1]
            local w2 = getTVert geo tface[2]
            local w3 = getTVert geo tface[3]
         
            local e1 = v2-v1
            local e2 = v3-v1 

            local delta_u1 = w2.x - w1.x 
            local delta_u2 = w3.x - w1.x 
            local delta_v1 = w2.y - w1.y 
            local delta_v2 = w3.y - w1.y 

            local tangent = (delta_v1 * e2 - delta_v2 * e1) / (delta_v1 * delta_u2 - delta_v2 * delta_u1) 
            for j = 1 to 3 do (
                local normalID = norMod.getNormalID i j
                local normal = normalize(norMod.GetNormal normalID )
                tangent = normalize(tangent - (dot tangent normal)*normal)           
                local bitangent = cross normal tangent 
                local TBN = Matrix3 tangent bitangent normal [0,0,0]
                TBN = inverse TBN
    
                smNor = [0,0,0] 
                norsID_bit = #{}
                norMod.ConvertVertexSelection #{face[j]} norsID_bit 
                for k in norsID_bit do smNor += norMod.getNormal k
                smNor = normalize smNor 
    
                tnor = normalize(smNor * TBN) 
                tnor = tnor *0.5 +0.5
                tcol = [tnor.x *255.0, tnor.y *255.0, tnor.z *255.0] as color              
                append tcols tcol
            )

        )

        convertToMesh geo   
        for i = 1 to meshop.getNumCPVVerts geo do setVertColor geo i tcols[i]
        update geo&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This result is the closest to houdini,most of them are correct, but the errors are concentrated in the corners&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 02:33:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922002#M2648</guid>
      <dc:creator>547057474</dc:creator>
      <dc:date>2023-04-26T02:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922437#M2649</link>
      <description>&lt;P&gt;slight variation of the above to illustrate whats going on&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;geo = $
convertToMesh geo 
addModifier geo (vertexpaint())
geo.showVertexColors = true
	
convertToMesh geo   	
tcols = #()
tcols.count = getNumCPVVerts geo;

addModifier geo (Edit_Normals()) 
norMod = geo.Edit_Normals

vci = 1;	
for i = 1 to getNumFaces geo do( 
	local face = getFace geo i
	local tface = getTVFace geo i

	local v1 = getVert geo face[1]
	local v2 = getVert geo face[2]
	local v3 = getVert geo face[3]

	local w1 = getTVert geo tface[1]
	local w2 = getTVert geo tface[2]
	local w3 = getTVert geo tface[3]
 
	local e1 = v2-v1
	local e2 = v3-v1 

	local delta_u1 = w2.x - w1.x 
	local delta_u2 = w3.x - w1.x 
	local delta_v1 = w2.y - w1.y 
	local delta_v2 = w3.y - w1.y 

	local tangent = (delta_v1 * e2 - delta_v2 * e1) / (delta_v1 * delta_u2 - delta_v2 * delta_u1) 
	for j = 1 to 3 do 
	(
		local normalID = norMod.getNormalID i j
		local normal = normalize(norMod.GetNormal normalID )
		tangent = normalize(tangent - (dot tangent normal)*normal)           
		local bitangent = cross normal tangent 
		local TBN = Matrix3 tangent bitangent normal [0,0,0]
		TBN = inverse TBN

		smNor = [0,0,0] 
		norsID_bit = #{}
		norMod.ConvertVertexSelection #{face[j]} norsID_bit 
		for k in norsID_bit do smNor += norMod.getNormal k
		smNor = normalize smNor 

		tnor = normalize(smNor * TBN) 
		tnor = tnor *0.5 +0.5
		tcol = [tnor.x *255.0, tnor.y *255.0, tnor.z *255.0] as color              
		tcols[vci] = tcol;
		vci += 1;
	)
)

convertToMesh geo   
for i = 1 to meshop.getNumCPVVerts geo do setVertColor geo i tcols[i]
update geo&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;adding the VertexPaint modifier "explodes" the vertex color channel ie a unique color vert for every face corner. The above duplicates the exploded order... so you may need to re-evaluate the Houdini result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as will this snippet...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;geo = $;
addModifier geo (vertexpaint());	
convertToMesh geo;	
	
for f = 1 to getNumFaces geo do  format "% %\n" (getVCFace geo f) (getFace geo f);	&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;geo = $
addModifier geo (vertexpaint());
geo.showVertexColors = true;
	
convertToMesh geo;	
	
setVertColor geo 5 red;
setvertselection geo 5;
subobjectLevel = 1;	
update geo;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 08:51:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922437#M2649</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2023-04-26T08:51:09Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922585#M2650</link>
      <description>&lt;P&gt;when iterate faces,the &amp;lt;getVCFace&amp;gt; will collected #{1..numCPPverts},it is similar to houdini's&amp;nbsp;&amp;lt;linear vertex index&amp;gt;,I don't know any other way to get the vertex number of each face in max,per face must has unique vertex num to set color.&lt;/P&gt;&lt;P&gt;houdini's result export to unity is also correct,so ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;forgot about this ,may be max just can not&amp;nbsp; do this&amp;nbsp;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your help. It has given me a lot of inspiration. Perhaps one day in the future, I can solve this problem and I will come back and post the code&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 08:54:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922585#M2650</guid>
      <dc:creator>547057474</dc:creator>
      <dc:date>2023-04-26T08:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922664#M2651</link>
      <description>&lt;P&gt;perhaps a handedness issue or a ccw/cw thing going on ?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 09:28:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11922664#M2651</guid>
      <dc:creator>klvnk</dc:creator>
      <dc:date>2023-04-26T09:28:45Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11924060#M2652</link>
      <description>&lt;P&gt;Where can I get the test geometry (box)?&lt;/P&gt;&lt;P&gt;could you post the file (v 2020) or code to make the box?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 19:01:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11924060#M2652</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2023-04-26T19:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11924858#M2653</link>
      <description>&lt;P&gt;this model made in blender ,because i am not&amp;nbsp;good at max modeling&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 02:48:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11924858#M2653</guid>
      <dc:creator>547057474</dc:creator>
      <dc:date>2023-04-27T02:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11924940#M2654</link>
      <description>&lt;P&gt;could you guys tell the whole story from the beginning?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what do you calculate?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 05:25:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11924940#M2654</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2023-04-27T05:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11925075#M2655</link>
      <description>&lt;P&gt;basicly i wanted to convert world space smooth vertex normal to tangent space ,then save the tangent normal to the vertex color.&lt;/P&gt;&lt;P&gt;after others help,i&amp;nbsp;achieved in houdini,it is correct because i export to unity,the shader is worked&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snipaste_2023-04-27_14-06-42.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1207354i650D3BFF10F190F6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snipaste_2023-04-27_14-06-42.png" alt="Snipaste_2023-04-27_14-06-42.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; but i need this in max,so i write a maxscript&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;geo = $
convertToMesh geo 
addModifier geo (vertexpaint())
geo.showVertexColors = true

addModifier geo (Edit_Normals()) 
norMod = geo.Edit_Normals

tcols = #()
for i = 1 to getNumFaces geo do( 
    local face = getFace geo i
    local tface = getTVFace geo i

    local v1 = getVert geo face[1]
    local v2 = getVert geo face[2]
    local v3 = getVert geo face[3]

    local w1 = getTVert geo tface[1]
    local w2 = getTVert geo tface[2]
    local w3 = getTVert geo tface[3]
    
    local e1 = v2-v1
    local e2 = v3-v1 

    local delta_u1 = w2.x - w1.x 
    local delta_u2 = w3.x - w1.x 
    local delta_v1 = w2.y - w1.y 
    local delta_v2 = w3.y - w1.y 

    local tangent = (delta_v1 * e2 - delta_v2 * e1) / (delta_v1 * delta_u2 - delta_v2 * delta_u1) 
    for j = 1 to 3 do (
        local normalID = norMod.getNormalID i j
        local normal = normalize(norMod.GetNormal normalID )
        tangent = normalize(tangent - (dot tangent normal)*normal)           
        local bitangent = cross normal tangent 
        local TBN = Matrix3 tangent bitangent normal [0,0,0]
        TBN = inverse TBN

        smNor = [0,0,0] 
        norsID_bit = #{}
        norMod.ConvertVertexSelection #{face[j]} norsID_bit 
        for k in norsID_bit do smNor += norMod.getNormal k
        smNor = normalize smNor 

        tnor = normalize(smNor * TBN) 
        tnor = tnor *0.5 +0.5
        tcol = [tnor.x *255.0, tnor.y *255.0, tnor.z *255.0] as color              
        append tcols tcol
    )

)

convertToMesh geo   
for i = 1 to meshop.getNumCPVVerts geo do setVertColor geo i tcols[i]
update geo&lt;/LI-CODE&gt;&lt;P&gt;and i got this , almost there ,but some corner is error,i dont know why cause this,and i have no idea to fix it&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="547057474_0-1682576034445.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1207356iEC83635464D3290A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="547057474_0-1682576034445.png" alt="547057474_0-1682576034445.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 06:19:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11925075#M2655</guid>
      <dc:creator>547057474</dc:creator>
      <dc:date>2023-04-27T06:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11926463#M2656</link>
      <description>&lt;P&gt;As I understand it, you are trying to "reverse engineer" the normal map where you bake the difference of the real vertex normal and render vertex normal as vertex color value.&amp;nbsp;After that, you want to use this data in the real-time shader as an offset to the real normal to visually smooth "hard edges".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Klvnk&lt;/STRONG&gt;'s code is right and works as expected:&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="denisTMaxDoctor_0-1682614643086.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1207606i5F64DA151B54D923/image-size/medium?v=v2&amp;amp;px=400" role="button" title="denisTMaxDoctor_0-1682614643086.png" alt="denisTMaxDoctor_0-1682614643086.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but the pipeline itself is wrong. We shouldn't do programmable normal averaging but have use apply correct (desired) smoothing groups to "edge" faces first. At least we have to specify "hard edges" which need to be smoothed.&lt;BR /&gt;&lt;BR /&gt;Moreover, I do not see the point of such a decision at all. If you have a custom shader why not bake desired (final) normals instead of normal offsets?&lt;BR /&gt;Well... I see some reason. It makes sense to use offsets if the mesh is deformable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 17:13:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11926463#M2656</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2023-04-27T17:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11927251#M2657</link>
      <description>&lt;P&gt;What about more basic thingy...&lt;/P&gt;&lt;P&gt;To transfer normals from high-res mesh to low-res through vertex color "low-res" mesh should have (at least)= vertices as high-res.&lt;/P&gt;&lt;P&gt;So, whats the point&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 00:31:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11927251#M2657</guid>
      <dc:creator>domo.spaji</dc:creator>
      <dc:date>2023-04-28T00:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11927271#M2658</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8285824"&gt;@domo.spaji&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;What about more basic thingy...&lt;/P&gt;&lt;P&gt;To transfer normals from high-res mesh to low-res through vertex color "low-res" mesh should have (at least)= vertices as high-res.&lt;/P&gt;&lt;P&gt;So, whats the point&lt;span class="lia-unicode-emoji" title=":thinking_face:"&gt;🤔&lt;/span&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Of course, baking (render) normals from high resolution geometry into a normal map is a common way to do this sort of thing. But it looks like there is a requirement caused by custom shader design.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 00:45:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11927271#M2658</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2023-04-28T00:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Tangent to Vertex Colour</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11927275#M2659</link>
      <description>&lt;P&gt;I think it should be something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;undo on
(
	node = $
	mesh = convertToMesh node 
	numf = getNumFaces node

	node.showVertexColors = true

	vcolors = #()
	for i = 1 to numf do
	( 
		face = getFace mesh i
		tface = getTVFace mesh i

		v1 = getVert mesh face[1]
		v2 = getVert mesh face[2]
		v3 = getVert mesh face[3]

		w1 = getTVert mesh tface[1]
		w2 = getTVert mesh tface[2]
		w3 = getTVert mesh tface[3]
		 
		e1 = v2 - v1
		e2 = v3 - v1 

		delta_u1 = w2.x - w1.x 
		delta_u2 = w3.x - w1.x 
		delta_v1 = w2.y - w1.y 
		delta_v2 = w3.y - w1.y 

		tangent = (delta_v1 * e2 - delta_v2 * e1) / (delta_v1 * delta_u2 - delta_v2 * delta_u1) 
	
		rnormals = meshop.getFaceRNormals mesh i
		normal = getfacenormal mesh i
		
		for k = 1 to 3 do 
		(
			tangent = normalize (tangent - (dot tangent normal) * normal)           
			binormal = cross normal tangent 
			tangent_tm = Matrix3 tangent binormal normal [0,0,0]

			tnormal = rnormals[k] * (inverse tangent_tm) 
			tnormal = (tnormal + 1)/2
			vcolor = (tnormal * 255) as color              
			append vcolors vcolor
		)
	)

	meshop.setMapSupport mesh 0 on
	setNumCPVVerts mesh (mesh.numfaces * 3) on
	for i = 1 to numf do setVCFace mesh i ([1,2,3] + 3*(i-1))
		
	for k = 1 to getNumCPVVerts mesh do setVertColor mesh k vcolors[k]
	update mesh
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As I said above, it makes sense to bake the difference between &lt;STRONG&gt;geometry&lt;/STRONG&gt; and &lt;STRONG&gt;render&lt;/STRONG&gt; normals.&lt;BR /&gt;All this doesn't make sense if the shader can use (as mostly all modern shaders) &lt;STRONG&gt;specified&lt;/STRONG&gt; normals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Apr 2023 21:52:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/tangent-to-vertex-colour/m-p/11927275#M2659</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2023-04-28T21:52:36Z</dc:date>
    </item>
  </channel>
</rss>

