/* UV Pipe by Robert Fletcher Mod by hamLT & TexeL This is untested, free, beta software. use/edit at your own risk. CHANGE LOG: ---------------------------------------------------------------- 19th April 2010 *Material Support Added *New UVs not showing on second Export fixed. ----------------------------------------------------------------- 17th April 2010 *Released ----------------------------------------------------------------- 11th May 2010 *UVChannel Choicer *Error Checker */ macroscript rt_uvpipe category:"_UV Layout Tools (by hamLT)" tooltip: "Headus Uvlayout bridge" Icon:#("uvpipe",1) ( rollout r_uvPipe "UVPipe" width:106 height:190 ( pickbutton pb_send "Pick" pos:[6,48] width:40 height:40 message:"" toolTip:"Select object to start to launch UV layout" spinner spn2 "" pos:[6,115] width:40 height:16 enabled:true range:[-100,100,10] type:#integer checkbutton ckb1 "Checker" pos:[6,137] width:40 height:40 toolTip:"Assign Cheker To Selection" radiobuttons rb_meshMode "Mode:" pos:[55,1] width:50 height:46 labels:#("Poly", "SubD") default:1 columns:1 radiobuttons rb_uvMode "UV Mode:" pos:[55,49] width:45 height:46 labels:#("New", "Edit") default:2 columns:1 label lbl1 "Create by" pos:[57,100] width:47 height:16 enabled:false dropdownList ddl1 "UV Ch." pos:[6,3] width:40 height:40 items:#("3", "2", "1") Timer tmr_checkForUvs "wait" pos:[145,113] width:24 height:24 interval:500 active:false progressBar pb2 "ProgressBar" pos:[0,95] width:169 height:2 enabled:true value:100 color:(color 210 209 8) label lbl12 "Tilling:" pos:[10,96] width:34 height:15 progressBar pb5 "ProgressBar" pos:[50,-7] width:2 height:195 enabled:true value:100 color:(color 34 225 34) orient:#vertical local turnToPoly local uvLayoutBin local uvLayoutLaunchOptions = " -plugin" local uvLayoutTemp = "c:\\" local uvLayoutNode local uvLayoutDummyNode local uvLayoutMeshMode ="Poly" local uvLayoutUVMode = "Edit" local statusLine local objMaterial fn importObjUvs nNode fileName = ( local mapChan = ddl1.selected as integer local mapVerts = #() local mapfaces = #() local file =openfile fileName if file !=undefined then ( while (not (eof file)) do ( cl = readline file tokens = filterstring cl " " case tokens[1] of ( "vt": ( -- format "tvert: %, %\n" tokens[2] tokens[3] append mapVerts [tokens[2] as float,tokens[3] as float,0] ) "f": ( tokens = deleteItem tokens 1 --format "face: %\n" tokens local mapFace = #() for i = 1 to tokens.count do ( subToken = filterString tokens[i] "/" append mapFace (subToken[2] as integer) ) --print mapFace append mapFaces mapFace ) ) ) close file if (classof nNode == editable_poly) then ( numFaces = polyop.getNumFaces nNode polyop.setMapSupport nNode mapChan true polyop.setNumMapVerts nNode mapChan mapVerts.count polyop.setNumMapFaces nNode mapChan mapFaces.count numVerts = mapVerts.count for i = 1 to numVerts do ( -- polyOp.setMapVert nNode mapChan i mapVerts[i] polyOp.setMapVert nNode mapChan i mapVerts[i] print mapVerts[i] ) for i = 1 to numFaces do ( -- polyOp.setMapFace nNode mapChan i mapFaces[i] polyOp.setMapFace nNode mapChan i mapFaces[i] ) ) ) ) fn exportObj nNode fileName = ( local mapChan = (ddl1.selected as integer) local numFaces = polyop.getNumFaces nNode local numVerts = polyop.getNumVerts nNode --print ddl1.selected local numTVerts = polyop.getNumMapVerts nNode mapChan local matLib = #() local materialList =#() local numMaterials = 1 local filenameStub = filterString filename "." local mtlFileName = filenameStub[1] + ".mtl" local currentMtl = "" fn getMaterialByID nNode ID = ( mat = nNode.Material if classof mat ==multiMaterial then ( if ID > mat.materialList.count then ( newIdx = mod ID mat.materialList.count return mat.materialList[newIdx] ) else ( return mat.materialList[ID] ) ) else ( if mat == undefined then ( mat = standardmaterial() mat.name = nNode.name + "_mat" ) return mat ) ) fn safeMatName matName = ( filteredMatName = filterString matName " -" matName = "" for element in filteredMatName do ( matName = MatName + element ) matName ) local file = createfile fileName if file != undefined then ( format "# RT_OBJ Exporter\n" to:file format "# % Verts\n" numVerts to:file format "# % T Verts\n" numTVerts to:file format "# % Faces\n" numFaces to:file format "mtlLib %.mtl\n" (getFilenameFile mtlFileName) to:file get_vert = polyop.getVert get_tVert = polyOp.getMapVert get_face_verts = polyOp.getFaceVerts get_map_face = polyOp.getMapFace get_face_ID = polyOp.getFaceMatID local pf = 100/(numVerts + numTVerts + numFaces) for i = 1 to numVerts do ( vert = get_vert nNode i format "v % % %\n" vert[1] vert[2] vert[3] to:file ) for i = 1 to numTVerts do ( tVert = get_tVert nNode mapChan i format "vt % % %\n" tVert[1] tVert[2] tVert[3] to:file ) format "g %\n" nNode.name to:file for i = 1 to numFaces do ( faceVerts = get_face_verts nNode i faceMapVerts = get_map_face nNode mapChan i faceVertCount = faceVerts.count faceMatID = get_face_ID nNode i faceMat = getMaterialByID nNode faceMatID if faceMat != currentMtl then ( matName = safeMatName faceMat.name format "usemtl %\n" matName to:file appendifUnique matLib matName currentMtl = faceMat ) format "f" to:file for j = 1 to faceVertCount do ( -- f v/vt/vn format " %/%" faceVerts[j] faceMapVerts[j] to:file ) format "\n" to:file ) close file ) --export the .mtl file file = createFile mtlFileName for mat in matlib do ( format "newmtl %\n" mat to:file format "kd 1.0 1.0 1.0\n\n" to:file ) close file ) fn UvLayoutSend nNode = ( local fileName = (uvLayoutTemp + nNode.name +".obj") local uv_mod = unwrap_uvw() convertTo nNode Editable_Poly polyop.setMapSupport nNode 1 true polyop.setMapSupport nNode 2 true polyop.setMapSupport nNode 3 true addModifier nNode uv_mod uvLayoutDummyNode =copy nNode uvLayoutDummyNode = convertto uvLayoutDummyNode editable_poly deleteModifier nNode uv_mod exportObj uvLayoutDummyNode fileName uvLayoutLaunchOptions = " -plugin," + uvLayoutMeshMode + "," + uvLayoutUVMode shelllaunch uvLayoutBin (uvLayoutLaunchOptions +" " +filename) ) fn uvLayoutKill = ( print "sending kill signal" file = createFile (uvLayoutTemp + uvLayoutNode.name + ".cmd") format "exit" to:file close file ) fn uvLayoutRecieve nNode = ( --import the uvs into the dummy node importObjUvs uvLayoutDummyNode (uvLayoutTemp + uvLayoutNode.name + ".out") --copy the imported uvs from the dummy to the stack of the working node. channelInfo.copyChannel uvLayoutDummyNode 3 (ddl1.selected as integer) channelInfo.pasteChannel nNode 3 (ddl1.selected as integer) uvLayoutNode.modifiers[1].name = "UVLayout UV's" uvLayoutKill() --deselect and reselect the working node. this will cause the stack display to refresh. select uvLayoutDummyNode select nNode delete uvLayoutDummyNode ) fn uvPipeInit = ( local scriptsDir = getDir #Scripts uvLayoutTemp = sysInfo.tempdir + "\\" if (doesFileExist (scriptsDir +"\\"+"uvpipe\\uvpipe.ini")) then ( uvLayoutBin = getINISetting (scriptsDir +"\\"+"uvpipe\\uvpipe.ini") "Settings" "bin" print uvLayoutBin ) else ( uvLayoutBin = getOpenFileName caption:"uvlayout binary" filename:"uvlayout.exe" types:"Executable(*.exe)|*.exe" makeDir (scriptsDir +"\\"+"uvpipe") setINISetting (scriptsDir +"\\"+"uvpipe\\uvpipe.ini") "Settings" "bin" uvLayoutBin ) ) label lbl5 "R.Fletcher" pos:[55,119] width:52 height:16 enabled:true label lbl10 "Mod by" pos:[67,143] width:39 height:16 enabled:false label lbl11 "hamLT " pos:[56,159] width:45 height:16 enabled:true progressBar pb6 "ProgressBar" pos:[50,138] width:61 height:2 enabled:true value:100 color:(color 210 209 8) label lbl6 "TexeL" pos:[56,173] width:45 height:16 enabled:true on r_uvPipe open do ( spn2.enabled = false uvPipeInit() ) on pb_send picked nNode do ( uvLayoutNode = nNode UvLayoutSend uvLayoutNode tmr_checkForUvs.active = true ) on spn2 changed val do ( if (classof $.material.diffuseMap) == Checker then ( $.material.diffuseMap.coords.U_Tiling = val $.material.diffuseMap.coords.V_Tiling = val ) ) on ckb1 changed state do ( if state == on then ( if ((superClassOf $) != GeometryClass) or (selection.count != 1) or ($.material == undefined) then ( ckb1.state = false messageBox "Hooop hl@, Select Same Object First (No Material) !" return false ) objMaterial = $.material $.material = Standard() $.material= standard diffuseMap:(checker()) showInViewport:true $.material.diffuseMap.coords.U_Tiling = spn2.value $.material.diffuseMap.coords.V_Tiling = spn2.value spn2.enabled = true $.material.diffuseMap.coords.MapChannel = ddl1.selected as integer ) else ( if ((superClassOf $) != GeometryClass) or (selection.count != 1) or ($.material == undefined) then ( ckb1.state = true messageBox "Hooop hl@, Select Same Object First !" return false ) $.material = objMaterial spn2.enabled = false ) ) on rb_meshMode changed mode do ( mm = #("Poly","SUBD") uvLayoutMeshMode = mm[mode] ) on rb_uvMode changed mode do ( um = #("New","Edit") uvLayoutUVMode = um[mode] ) on tmr_checkForUvs tick do ( if doesFileExist(uvLayoutTemp +uvLayoutNode.name+".out" ) then ( tmr_checkForUvs.active = false uvLayoutRecieve uvLayoutNode ) ) ) on execute do ( createDialog r_uvPipe ) )