macroScript Autoload_Materials category: "RacoonScripts" ( local version = 1.1 try(destroyDialog ::RA_materialAutoload)catch() -- defaults local bitmapBlurVal = 1.0 local loadheightmapsChk = false local reflIor = 1.5 -- naming convention, case insensitive (like: "Rough_bricks_Basecolor.png", "Rough_bricks_Normal.png", ...) local naming_Albedo = #("basecolor", "albedo", "color", "diffuse", "diff") local naming_Normal = #("normal", "directx", "nrm") local naming_Roughness = #("roughness") local naming_Glossiness = #("glossiness") local naming_Reflection = #("reflection", "specular") local naming_Height = #("height", "displacement") local naming_Metallic = #("metallic") local naming_Ior = #("ior") local mapfiles fn queryTypeTex types =( local out = undefined for tex in mapfiles while out == undefined do( local filteredName = filterstring (getFilenameFile tex) "_" for type in types while out == undefined do( if (toLower filteredName[filteredName.count]) == (toLower type) do( out = tex ) ) ) out ) fn createBitmap filepath gamma bmblur:unsupplied worldspaceSize:unsupplied =( if filepath != undefined then( local bm = bitmaptexture() bm.bitmap = openBitmap filepath gamma:gamma if bmblur != unsupplied then bm.coords.blur = bmblur if worldspaceSize != unsupplied and worldspaceSize != undefined then( bm.coords.realWorldScale = true bm.coords.realWorldWidth = worldspaceSize bm.coords.realWorldHeight = worldspaceSize ) bm )else(undefined) ) fn loadAndCreateMaterial bitmapblur loadheightmap flipGreen ws_size =( local theDialog = dotNetObject "System.Windows.Forms.OpenFileDialog" theDialog.title = "Select One Or More Files" theDialog.Multiselect = true local result = theDialog.showDialog() mapfiles = theDialog.fileNames local renderEngine = substring (renderers.current as string) 1 5 if mapfiles != undefined AND mapfiles.count != 0 then( local genMtl = undefined local tmpfltr = filterstring (getFilenameFile mapfiles[1]) "_" local sugg_name = "" for i = 1 to tmpfltr.count - 1 do( sugg_name += tmpfltr[i] if i < tmpfltr.count - 1 do sugg_name += "_" ) if renderEngine == "V_Ray" then ( genMtl = VrayMtl() genMtl.name = sugg_name genMtl.Reflection = color 255 255 255 genMtl.reflection_lockIOR = false genMtl.reflection_ior = reflIor genMtl.texmap_bump_multiplier = 100.0 genMtl.brdf_type = 4 metalnessMap = createBitmap (queryTypeTex naming_Metallic ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size genMtl.texmap_diffuse = createBitmap (queryTypeTex naming_Albedo ) 2.2 bmblur:bitmapblur worldspaceSize:ws_size genMtl.texmap_bump = VRayNormalMap flip_green:flipGreen normal_map:(createBitmap (queryTypeTex naming_Normal ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size) genMtl.texmap_reflectionGlossiness = createBitmap (queryTypeTex naming_Roughness ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size if genMtl.texmap_reflectionGlossiness != undefined then( genMtl.texmap_reflectionGlossiness.output.invert = true genMtl.texmap_reflectionGlossiness.output.clamp = true )else( genMtl.texmap_reflectionGlossiness = createBitmap (queryTypeTex naming_Glossiness ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size ) if metalnessMap != undefined then ( -- metalness workflow local iorMixMap = mix name:"IorMapping" iorMixMap.mask = metalnessMap local clrIor = ((1.0/reflIor)*255) as integer iorMixMap.color1 = color clrIor clrIor clrIor iorMixMap.color2 = color 0 0 0 genMtl.texmap_reflectionIOR = iorMixMap local baseColorMult = VRayCompTex name:"BaseColorMult" operator:3 local outputMapInvert = Output map1:metalnessMap outputMapInvert.output.invert = true baseColorMult.sourceA = outputMapInvert baseColorMult.sourceB = genMtl.texmap_diffuse local baseColorToReflMult = VRayCompTex name:"BaseColorToReflMult" operator:3 baseColorToReflMult.sourceA = metalnessMap baseColorToReflMult.sourceB = genMtl.texmap_diffuse genMtl.texmap_diffuse = baseColorMult genMtl.texmap_reflection = baseColorToReflMult )else( -- spec/ior reflection workflow genMtl.texmap_reflectionIOR = createBitmap (queryTypeTex naming_Ior ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size genMtl.texmap_reflection = createBitmap (queryTypeTex naming_Reflection ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size ) if loadheightmap then genMtl.texmap_displacement = createBitmap (queryTypeTex naming_Height ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size if genMtl.texmap_displacement != undefined then genMtl.texmap_displacement_on = false meditmaterials[activeMeditSlot] = genMtl ) if renderEngine == "Coron" then ( genMtl = CoronaMtl() genMtl.name = sugg_name genMtl.levelReflect = 1.0 genMtl.colorReflect = color 255 255 255 genMtl.fresnelIor = reflIor genMtl.mapamountBump = 1.0 metalnessMap = createBitmap (queryTypeTex naming_Metallic ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size genMtl.texmapDiffuse = createBitmap (queryTypeTex naming_Albedo ) 2.2 bmblur:bitmapblur worldspaceSize:ws_size genMtl.texmapBump = CoronaNormal flipGreen:flipGreen normalMap:(createBitmap (queryTypeTex naming_Normal ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size) genMtl.texmapReflectGlossiness = createBitmap (queryTypeTex naming_Roughness ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size if genMtl.texmapReflectGlossiness != undefined then( genMtl.texmapReflectGlossiness.output.invert = true genMtl.texmapReflectGlossiness.output.clamp = true )else( genMtl.texmapReflectGlossiness = createBitmap (queryTypeTex naming_Glossiness ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size ) if metalnessMap != undefined then ( -- metalness workflow local iorMixMap = mix name:"IorMapping" iorMixMap.mask = metalnessMap local clrIor = ((1.0/reflIor)*255) as integer iorMixMap.color1 = color clrIor clrIor clrIor iorMixMap.color2 = color 0 0 0 genMtl.texmapFresnelIor = iorMixMap local baseColorMult = CoronaMix name:"BaseColorMult" mixOperation:2 mixAmount:1.0 mixInSRgb:false local outputMapInvert = Output map1:metalnessMap outputMapInvert.output.invert = true baseColorMult.texmapTop = outputMapInvert baseColorMult.texmapBottom = genMtl.texmapDiffuse local baseColorToReflMult = CoronaMix name:"BaseColorToReflMult" mixOperation:2 mixAmount:1.0 mixInSRgb:false baseColorToReflMult.texmapTop = metalnessMap baseColorToReflMult.texmapBottom = genMtl.texmapDiffuse genMtl.texmapDiffuse = baseColorMult genMtl.texmapReflect = baseColorToReflMult )else( -- spec/ior reflection workflow genMtl.texmapFresnelIor = createBitmap (queryTypeTex naming_Ior ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size genMtl.texmapReflect = createBitmap (queryTypeTex naming_Reflection ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size ) if loadheightmap then genMtl.texmapDisplace = createBitmap (queryTypeTex naming_Height ) 1.0 bmblur:bitmapblur worldspaceSize:ws_size if genMtl.texmapDisplace != undefined then genMtl.texmapOnDisplacement = false meditmaterials[activeMeditSlot] = genMtl ) ) ) rollout RA_materialAutoload "Autoload Materials" width:220 ( label lblBtmpBlur "Bitmap Blur" across:2 align:#left spinner spnBitmapBlur "" range:[0.01, 1.0, bitmapBlurVal] fieldwidth:60 checkbox chkUseWS "Use worldspace size" checked:false across:2 spinner spnWSsize "" fieldwidth:60 type:#worldunits range:[0.0, 1000000.0, 500.0] enabled:false checkbox chkLoadHeight "Load heightmap" checked:loadheightmapsChk radiobuttons rdoNrmType "Normal map type:" labels:#("DirectX", "OpenGL (flipped Green channel)") offset:[-9,0] button btnLoadMaps "Load maps, create material" width:194 height:26 on chkUseWS changed state do spnWSsize.enabled = state on btnLoadMaps pressed do( loadAndCreateMaterial spnBitmapBlur.value chkLoadHeight.checked (if rdoNrmType.state == 2 then true else false) (if chkUseWS.checked then spnWSsize.value else undefined) ) ) createDialog RA_materialAutoload )