-- Macro Scripts File -- Created: May 17 2008 -- Author: Alexander Nadein -- Macro Scripts for Spliting hard edges in editable polygon model for game engines -- Writed and test in 3dsmax 8 only --*********************************************************************************************** -- MODIFY THIS AT YOUR OWN RISK macroScript SplitHardEdges category:"shultz" tooltip:"Split Hard Edges" ButtonText:"Split H Edges" ( --Macroscript begin theEP = selection[1].baseobject --get the base object of the selected object ----------Define edge list of all non open edges in object edgeCount = polyOp.getNumEdges theEP --edges total openEdgesBitArray = polyOp.getOpenEdges theEP-- all open edges as bitArray edgeCount edgeSelArray = #() k = 1 for i = 1 to edgeCount do if openEdgesBitArray[i] == false then ( edgeSelArray[k] = i k = k + 1 ) HardEdgesArray = #() sg_bin_array = #{} sg_bin2_array = #{} --edgeSelArray --edgeSelArray.count -------- functions for converting decimal value to binary fn dec2bin1 deci = ( if deci != undefined then ( dec2bin = "" deciT = 0.0 s = "" ost = 0 do ( deciT = deci / 2 ost = deci - (deciT as integer * 2) deci = deciT as integer s = (ost as integer) as string + s ) while (deci as integer) != 0 dec2bin = s ) ) fn dec2bin2 deci = ( if deci != undefined then ( dec2bin = "" deciT = 0.0 s = "" ost = 0 do ( deciT = deci / 2 ost = deci - (deciT as integer * 2) deci = deciT as integer s = (ost as integer) as string + s ) while (deci as integer) != 0 dec2bin = s ) ) FOR J = 1 to edgeSelArray.count do --GLOBAL LOOP check around all edges for hardness ( polys = polyOp.getEdgeFaces theEP edgeSelArray[J] --get polys of selected edge --polys sg = polyOp.getFaceSmoothGroup theEP polys[1] --get smoothing groups from poly 1 as decimal sg_bin = dec2bin1 sg -- and convert to binary ---------adding to string neccesery 0`s sg_bin_str = sg_bin as string --convert binary smoothing groups to string while sg_bin_str.count <= 31 do sg_bin_str = "0" + sg_bin_str ---------2nd poly, the same opertaions sg2 = polyOp.getFaceSmoothGroup theEP polys[2] --get smoothing groups from poly 2 as decimal sg_bin2 = dec2bin2 sg2 -- and convert to binary ---------adding to string neccesery 0`s sg_bin2_str = sg_bin2 as string --convert binary smoothing groups to string while sg_bin2_str.count <= 31 do sg_bin2_str = "0" + sg_bin2_str --sg_bin_str --sg_bin2_str ---------making 2 bit arrays from strings for v = 1 to 32 do ( if sg_bin_str[v] == "1" then sg_bin_array[v] = true else sg_bin_array[v] = false if sg_bin2_str[v] == "1" then sg_bin2_array[v] = true else sg_bin2_array[v] = false ) --------comparison of 2 polys by having the same smoothing groups or not sg_bin_dif_array = #{} sg_bin_dif_array = sg_bin_array * sg_bin2_array hardness = false --exclude polys with the same normal meens it havn't hard edge visible nor1 = polyOp.getFaceNormal theEP polys[1] --find poly's normals nor2 = polyOp.getFaceNormal theEP polys[2] nor1.x = abs (nor1.x * 10000000) as integer nor1.y = abs (nor1.y * 10000000) as integer nor1.z = abs (nor1.z * 10000000) as integer nor2.x = abs (nor2.x * 10000000) as integer nor2.y = abs (nor2.y * 10000000) as integer nor2.z = abs (nor2.z * 10000000) as integer for n = 1 to sg_bin_dif_array.count do if sg_bin_dif_array[n] != true then hardness = true else ( hardness = false exit ) if hardness == true then if nor1 != nor2 then append HardEdgesArray edgeSelArray[J] --if hardness == true then append HardEdgesArray edgeSelArray[J] -- break() )-- GLOBAL LOOP END polyOp.setEdgeSelection theEp HardEdgesArray --Selecting all hard edges polyOp.SplitEdges theEP HardEdgesArray ) --Macroscipt End