----- About ----- /* Author: Michael Nicolayeff (SmallPoly) Email: SmallPolyArtist@gmail.com */ ----- Change Log ----- /* 2018-02-02 - v1.00 - Now a macroscript. Minor UI Tweaks. 2018-01-26 - v0.90 - Used felixherder's input to fix the material instancing problem. - Replacing alertbox based UI with actual rollout based UI - Adding greater map support and filtering based on material type 2016-12-19 - v0.80 - Bugfix: Keeping the name should now work for multimaterials as well. 2016-10-31 - v0.70 - Scipt now keeps the name of the original material 2012-08-08 - v0.622 - Added try/catch expression for convertToGeneric, since it's missing in Max 2011. The script now reports the material as unconvertable instead of crashing and recommends using Max 2012 or newer. 2012-07-26 - v0.621 - Fixed a bug related to Autodesk_Generic's default opacity configuration. - Redrawing of the scene while the script is running is now disabled to help with efficiency - The script now reports how long it took to convert everything, in milliseconds, starting from when the user confirms doing the conversion. 2012-07-26 - v0.62 - Added support for Specularity and Glossiness wherever possible. - The Index of Refraction (IOR) is now transferred wherever possible - Note: Given differences in material setup, reflectivity currently becomes specularity. - Therefore, Chrome-like reflective materials are not currently supported 2012-07-26 - v0.61 - Added support for Bump Maps - Added support for Opacity/Transparency (amount only. exporter does not support inverting map colors) - Cleaned up transfer method 2012-07-25 - v0.50 - First functional version - Copys diffuse properties only - Handles Arch */ macroScript sp_ArchToStandard category:"# SmallpolyScripts" buttonText: "ArchStd" toolTip:"Architecture Standard Converter" ( global AdskToStd global ArchDsnToStd global SArchToStd global navMulti global changeToStd global feedback = false -- Must be either true or false (no quotes). toggles script feedback print statements. global currentObjName = "null" -- Placeholder for the name of the current object. Used in error reporting. global titleText = "Architecture Standard Converter" rollout roll_Converter titleText ( group "Info:" ( label lbl_Info1 "Converts Architecture materials into Scanline" offset:[0,-8] label lbl_Info2 "Standard materials for VR Exporters" ) button btn_Convert "Convert Materials" width:200 height:40 offset:[0,5] local chkoffset = 0 group "Convert:" ( checkbox chk_Autodesk "Autodesk_Material" checked:true align:#left offset:[chkoffset,0] Tooltip:"The Autodesk Architectural material" across:3 checkbox chk_MRArch "MR Arch && Design" checked:true align:#left offset:[chkoffset,0] Tooltip:"The mental ray Architectural material" checkbox chk_ArchScanline "Architectural" checked:true align:#left offset:[chkoffset,0] Tooltip:"The scanline Architectural material" ) group "Notes:" ( label lbl_ins1 "• Save before using. Source materials will be replaced." align:#left label lbl_ins4 "• Invert transparency maps manually to convert them to opacity maps." align:#left label lbl_ins2 "• Materials that could not be converted will be listed in the console." align:#left label lbl_ins3 "• The console can be opened by pressing F11." align:#left ) hyperLink hyp_update "[ Check for Updates ]" offset:[0,4] color:[178, 178, 178] hoverColor:[255,255,0] visitedColor:[178, 178, 178] address:"http://www.scriptspot.com/3ds-max/scripts/architecture-to-standard-material-converter" align:#center label lbl_version "v1.0 - Jan 26, 2018" offset:[0,-4] on btn_Convert pressed do ( startStamp = timestamp() -- disableSceneRedraw() print "----- ----- ----- ----- ----- ----- ----- ----- ----- ----- Start ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- " for m in sceneMaterials do ( matMod = changeToStd m objarr = for o in objects where o.material == m collect o for obj in objarr do obj.mat = matMod )-- convert the material and assign it print "----- ----- ----- ----- ----- ----- ----- ----- ----- ----- End ---------- ----- ----- ----- ----- ----- ----- ----- ----- ----- " -- enableSceneRedraw() endStamp = timestamp() print ("Conversion completed in [" + (endStamp - startStamp) as string + "] ms for [" + sceneMaterials.count as string + "] materials") ) ) try (destroyDialog roll_Converter) catch() createDialog roll_Converter width:380 height:295 fn AdskToStd inMat = -- Convert Autodesk_Material to Standard (Revit's Arch material) ( matName = inMat.Name -- get the name of the material outMat = StandardMaterial() -- Creat output material --- --- Past here, inMat should be an Autodesk Generic material --- --- if inMat.DefinitionID != "Generic" do ( -- If it's not a generic, try to make it one try(inMat = inMat.ConvertToGeneric) catch (print ("Please manually convert the material named: [" + inmat.name + "]. Its class is: [" + classof inMat as string + "]. It was found on object: [" + currentObjName + "]. Use max 2012 or newer to allow automatic conversion of this kind of material.")) ) if inMat.DefinitionID == "Generic" then ( -- Converting Generic Autodesk Materials Part by Part. -- Diffuse outMat.Diffuse = inMat.Generic_Color -- transfer diffuse color swatch outMat.diffuseMap = inMat.Generic_Image -- transfer diffuse map outMat.diffuseMapAmount = inMat.Generic_Image_Fade -- blend with base color -- Gloss outMat.glossiness = inMat.Generic_Glossiness -- gloss slider outMat.glossinessMap = inMat.Generic_Glossiness_Map -- gloss texture -- Reflectivity -> Specular outMat.specularLevel = inMat.Reflectivity_Direct -- spec level outMat.Specular = color 230 230 230 -- color does not exist for autodesk generic outMat.specularMap = inMat.Reflectivity_Direct_Map outMat.specularMapEnable=inMat.Reflectivity_Enable -- set enabled last: adding a map automatically enables -- Transparency -> Opacity -- Translucency map is not used. if inMat.Transparency_Enable == true then outMat.opacity = (100 - inMat.Transparency_Amount) else outMat.opacity = 100 -- outMat.opacityMap = inMat.Transparency_Image --- inverted. not sure if this can be done with maps -- outMat.opacityMapEnable = inMat.Transparency_Enable -- set enabled last: adding a map automatically enables outMat.ior = inMat.Transparency_Refraction -- This material type allows for use of index of refraction. -- Cutouts -- Self Illumination -- Bump -- Bump Amount Map (macro) is not used outMat.bumpMap = inMat.Bump_Image outMat.bumpMapAmount = inMat.bump_amount outMat.bumpMapEnable = inMat.Bump_Enable -- set enabled last: adding a map automatically enables -- Ambient Occlusion -- Round Corners -- Performance -- Override Refreaction -- transfer bump map and amount -- transfer specular/reflectivity and gloss -- Set outmat name outMat.name = matName return outMat -- Return outMat ) else (return inMat) ) fn ArchDsnToStd inMat = -- Convert Arch___Design__mi Mateiral to Standard (Mental Ray's Arch Material) ( matName = inMat.Name outMat = StandardMaterial() -- Diffuse outMat.Diffuse = inMat.diff_color outMat.diffuseMap = inMat.diff_color_map -- Roughness outMat.glossiness = inMat.refl_gloss * 100 -- gloss level outMat.glossinessMap = inMat.refl_gloss_map -- gloss map outMat.glossinessMapEnable = inMat.refl_gloss_map_on -- set enabled last: adding a map automatically enables -- Specular outMat.specularLevel = inMat.refl_weight * 100 -- spec level outMat.Specular = inMat.refl_color -- spec color outMat.specularMap = inMat.refl_color_map -- reflectivity map outMat.specularMapEnable = inMat.refl_color_map_on -- set enabled last: adding a map automatically enables -- Transparency -- inverted: transparency -> opacity. In A&D, goes from 0 to 1. outMat.opacity = 100 - (inMat.refr_weight * 100) -- outMat.opacityMap = inMat.Transparency_Image --- inverted. not sure if this can be done with maps -- outMat.opacityMapEnable = inMat.Transparency_Enable -- set enabled last: adding a map automatically enables outMat.ior = inMat.refr_ior -- This material type allows for use of index of refraction. -- this material type also allows for BRDF -- Bump outMat.bumpMap = inMat.bump_map outMat.bumpMapAmount = inMat.bump_map_amt * 100 outMat.bumpMapEnable = inMat.bump_map_on -- set enabled last: adding a map automatically enables -- Displacement -- Cutout -- Environment -- Self Illumination outMat.selfillumMap = inMat.self_illum_map -- Set outmat name outMat.name = matName return outMat -- Return outMat ) fn SArchToStd inMat = -- Convert Architectural Mateiral to Standard (Max's Arch material) ( matName = inMat.Name outMat = StandardMaterial() -- transfer diffuse map and color outMat.Diffuse = inMat.Diffuse outMat.diffuseMap = inMat.diffuseMap -- transfer bump map and amount outMat.bumpMap = inMat.bumpMap outMat.bumpMapAmount = inMat.bumpMapAmount outMat.bumpMapEnable = inMat.bumpMapEnable -- set enabled last: adding a map automatically enables -- transfer transparency map and amount outMat.opacity = 100 - inMat.transparency --- inverted: transparency -> opacity -- outMat.opacityMap = inMat.Transparency_Image --- inverted. not sure if this can be done with maps -- outMat.opacityMapEnable = inMat.Transparency_Enable -- set enabled last: adding a map automatically enables -- transfer specular/reflectivity and gloss outMat.specularLevel = inMat.shininess -- spec level outMat.glossiness = inMat.shininess -- gloss level outMat.Specular = color 230 230 230 -- spec color -- spec color is not used in this mateiral type outMat.specularMap = inMat.shininessMap -- reflectivity map outMat.glossinessMap = inMat.shininessMap -- gloss map outMat.specularMapEnable = inMat.shininessMapEnable -- set enabled last: adding a map automatically enables outMat.glossinessMapEnable = inMat.shininessMapEnable -- set enabled last: adding a map automatically enables outMat.ior = inMat.ior -- This material type allows for use of index of refraction. -- Set outmat name outMat.name = matName return outMat -- Return outMat ) -- navigate multi mats fn navMulti subMat = ( for m=1 to subMat.count do ( subMat[m] = changeToStd subMat[m] ) return subMat ) ------ Meta Convert Functions ------ fn changeToStd inMat = -- Takes a in input material, returns a Standard, keeping diffuse color and texture -- Takes Autodesk_Material,Arch___Design__mi, and Architectural ( -- print ("Checking if Autodesk box is checked: " + roll_Converter.chk_Autodesk.checked as string) -- print ("Checking if MR Arch box is checked: " + roll_Converter.chk_MRArch.checked as string) -- print ("Checking if Scanline Arch box is checked: " + roll_Converter.chk_ArchScanline.checked as string) doAdsk = roll_Converter.chk_Autodesk.checked doMrArch = roll_Converter.chk_MRArch.checked doSLArch = roll_Converter.chk_ArchScanline.checked -- check invalid if classof inMat == UndefinedClass then ( print ("The object named [" + currentObjName + "] has no material or is a missing sub-material."); return inMat) else if classof inMat == StandardMaterial then (return inMat) else if classof inMat == MultiMaterial then (navMulti inMat) else if classof inMat == Autodesk_Material then (if doAdsk then (AdskToStd inMat) else return inMat) else if classof inMat == Arch___Design__mi then (if doMrArch then (ArchDsnToStd inMat) else return inMat) else if classof inMat == Architectural then (if doSLArch then (SArchToStd inMat) else return inMat) -- Give up else (print ("Please manually convert the material named: [" + inmat.name + "]. Its class is: [" + classof inMat as string + "]. It was found on object: [" + currentObjName + "]." ); return inMat) ) )