Tool to update old material libraries to v6 standards

​As V-Ray introduces new features and defaults with each iteration, old material (pun intended) may be left behind.
For example, the new energy conservation for GTR/GGX is turned on only for new materials, and it has no UI control to toggle it.
This is a problem if one has old material libraries, for example, they take materials from to add to new scenes.
The attached script aims to process .mat and .max files so to toggle such options (see the screenshot).

Usage:
a) Pick a Path to scan (it will recurse through sub-paths.) for .mat and .max files, or choose “work on the open scene” instead.
b) Toggle off the options you don’t want
c) Press “Go!” and wait (a few seconds for matlibs, more for Max files.).

Warnings:
a) The script is given as-is, without any guarantee of support or improvements.
b) The script by default appends the max version to the saved files. The behaviour can however be toggled off, thereby enabling file overwriting. This is very risky (see point c) ) and shouldn’t be used on the original files. To be clearer: make a copy of the files before processing them.
c) The process will set the version of matlibs/max files to the version of Max used to process them.
In other words, matlibs or max files saved with max 2023 will not open again in max 2022.
Particularly for older stuff: make a copy!
d) Max files can be opened either as matlibs (processing is super quick this way) and will then create a matlib as a result (maxfilename.mat) saved side-by-side, the original max files are left untouched, or as Max files proper (processing of these can be several times longer, depending on scene complexity.), and then by default a new version of the original max file will be created.
e) The switch of BRDF to GGX is naively done, there is currently no attempt at matching glossiness amounts. Looks *will* change (as it’s the goal of the whole task.).
f) The legacy (typically mentalRay) custom attributes are detected and cleaned using Max’s own scene converter. If it creates issues for you, turn it off.

Script version is 0.02 adds processing of just the open scene.
It also allows to add the Max version as token to the saved matlib (so old ones stay the same, and it future-proofs trying to open them.) as well as a custom string instead.

Script version 0.03 adds the processing and saving of max files as max or mat files, thereby creating (or overwriting. change defaults at your peril!) new max files or new mat files as the user chooses.

Script version 0.05 strenghtens the holding/fetching of max files, and adds conversion of bitmap loaders to vrayBitmap ones using the tried and tested functions that come with V-Ray.

Script version 0.07 adds the resetting of map coordinates’ blur to 1.0 (only works on Max files treated as scenes. Won’t touch matlibs.), and also turns on the new anisotropy model along with Energy conservation (the highlights will not turn into anisotropic, however.).
There is also a fix for a potential corner-case bug (that was not reported, though.).

Script v 0.08 does away with turning on the new GTR anisotropy as it’s the default since v7.0.
The previous version stays for V 6.x users.

Script and screenshots have been updated.

​​
matlibProcessor_007.zip (4.55 KB)
matlibProcessor_008.rar (4.98 KB)

Thanks for sharing !
would it be easy to add an option to do these changes to the current scene materials directly too ?
I usually use VMC script to do this process manually to each property one by one, but a one click solution will be great too.
Thank you .

Ah nice, we started updating our inhouse library so can use this aswell! Thanks.

I have something else that processed open scenes (it’s substantially simpler compared to matlibs).
Not sure i should just add the “work only on open scene” option to this one.
Would it work this way?

Thanks for the suggestion, Max, i updated the first post with the new script and screenshots.

Wow that was fast! Thank you so much!
I will test it later and report back if I find any issue/suggestions.

Script version 0.03 adds the processing and saving of max files as max or mat files, thereby creating (or overwriting. change defaults at your peril!) new max files or new mat files as the user chooses.
Script and screenshots have been updated in the first post.

Does this also take care of mismatchin reflection and specular glossiness (which was possible many versions ago).
I know it is ignored these days, but V-Ray still prints a warning about this in the log.

It doesn’t, no, because the materials are anyway ignored non-destructively by V-Ray itself.
For the script to make the error disappear, it’d have to wipe the contents of the specular section, thereby potentially dropping textures.

Hi Lele,
I just finished moving our library into the V-ray Material Library Browser using the V-ray companion tool. Using your script I managed to generate a new .mat library file with all materials updated to the current standards. There is only one thing I can’t wrap my head around do to my almost zero maxscript knowledge. We have a lot of old materials that still use the legacy Max Bitmap and I wanted to convert them to V-ray Bitmaps. What would be the easiest way of doing this? I tried to search for a script that would import all the materials from the .mat file inside Max so that I could use the V-ray converter but could not find anything usable.
Thanks in advance!

You’re right, and in the right place.
That’s the planned upgrade for the script above.

Script version 0.05 strenghtens the holding/fetching of max files, and adds conversion of bitmap loaders to vrayBitmap ones using the tried and tested functions that come with V-Ray.
Script and screenshots have been updated in the original post.

Awesome, thanks Lele!

You’re welcome, most of the work was already done by others. :slight_smile:
Please report any issue you may have!

Thank you LeLe 8)

What is the reason that the resulting .mat file is much smaller after running the script? (3.6mb vs. 2.4mb)

I don’t quite know.
The methods i use are Max’s own (i.e. saveMaterialLibrary).
If the materials are all there, then it’s possibly because of versioning the file up (assuming the format got more efficient.).
If they aren’t, then perhaps there is some error in my code, and i’d love to have said matlib (no textures needed).

Is there a quick way to get the number of materials inside a mat file?

Run the attached script.
matlib_coount_comparer.zip (379 Bytes)

The script says they’re matching. So indeed the matlib files seem to have been modified to be smaller in size.

Regards and thanks again for both of the scripts.

Olvier