Announcement

Collapse
No announcement yet.

V-Ray Material Library sample refresher script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • V-Ray Material Library sample refresher script

    EDIT: As of Hotfix 2, this post is outdated, and the script are removed.
    The functionalities are integrated in the Library itself, under the "Add to Library" button.
    Refer to the docs for usage scenarios and limitations.



    The attached script will at some point be better integrated with the library itself.
    For now, we'd like for the most adventurous of users to try this out and provide us with actionable feedback.

    Click image for larger version  Name:	UI.png Views:	13 Size:	21.0 KB ID:	1102264

    Installation:
    The attached archive (very bottom) contains two files: the script and a max file.
    *)The max file needs to be placed in the v-ray install folder, "assets" subfolder.
    For example, in
    Code:
    C:\Program Files\Chaos Group\V-Ray\3ds Max 2021\assets\
    You may need elevated privileges to write in there.
    *)The script can instead be opened and run from the maxscript editor, or from the maxscript/scripting menu.
    Its location isn't important.

    Limitations:
    The script will try to detect the material library installation folder.
    Currently, the script expects this library to exist and be valid.
    Should this not be the case, the script will warn and close.

    The script expects the Swatch max file to live inside the correct assets folder in the v-ray install.
    Should it not find it, it will warn and close.

    So, for now, no custom locations for new material libraries, nor the chance to choose custom location for the assets.
    This may or may not change in the future.

    Operation:

    The script has two main modes of operation:
    a1) Select (or -recursively- scan for) a material library, then process it as per the chosen options: copy and repath the textures to the assets' folder in the library, render the previews, and copy/refresh the material library file in the V-Ray Library folder.
    a2) Select (or -recursively- scan for) a Max file, then process it as per the chosen options: copy and repath the textures to the assets' folder in the library, render the previews, and create/refresh a material library file in the V-Ray Library folder.

    Both buttons can be used, and the script will process the .mat files first, and the .max files afterwards.

    The script offers options:
    The defaults can be overridden for both resolution and quality (more on this further down.): from 64 to 4096px can be rendered in final or preview quality.
    The default is 512px, which is mostly fine.
    For those wanting bigger samples (to be clear, those are the images shown when the samples are double-clicked and open in a new window), the option is there.
    Be mindful of higher resolutions: the 2048 one will take 16 times the default one to render.
    Because the script can scan folder trees, using the preview quality and the small resolutions will allow for a very quick pre-pass to create matlibs from any number of max files, as quickly as possible.
    As a second stage, the ones worthy of being kept can be rendered at higher quality and resolution.

    Below the render options, there are choices for copying the textures to the asset folder in the library, and to convert to .TX (currently not working. Will arrive for the final, integrated version.).

    To handle duplicates, the script now offers choices: "Always", "Never", or "Ask" are available for textures, preivews and material library files.

    Lastly, options can be saved and reset to defaults easily.
    Resetting options to defaults will still remember the last path used for either of the browse buttons.

    Usage:
    Simply run the script, click (or CTRL+Click, or ALT+Click. See tooltip.) on either of the two buttons, and once the "Process" button is active, click it to let the script do its job.
    At factory defaults, the script will produce results identical to those the Library ships with.

    Keeping the ESC key pressed (with focus on the script UI, not the VFB) will quit the process.

    It's provided with tooltips, so there should be no need to get back to this post for instructions.
    If anything is terribly wrong, the script should warn the user, and then close.

    Thank you in advance for all the feedback, and the reporting of any bugs.



    EDIT: The version is now v 0.05, it simply adds the "Skip existing" checkbox.
    This will skip existing previews, regardless of their size (the check is on the file name alone.).
    While checking sizes is entirely doable, it'll also get quite slow (the script would need to open each sample picture, and once in RAM check its size. then close it and garbage collect. Checking for file size alone could work too, but it'd be risky due to jpg compression), so i'd rather the user did the manual work of cleaning up offending images from their library previews.
    Should it prove hard or a long slog, i'll reconsider this.
    EDIT #2: The version is now v 0.06. Added the automatic Asset Browser refresh to the operations, and a little "R" button to manually refresh it.
    EDIT #3: The 007 version implements custom .mat file usage (i.e. pick any .mat file.), process quitting on ESC key hold-down, and graceful exit if terminal errors are found (no max file for sample rendering, no material library is found.).
    There are still a couple of things to get done (rationalisation of texture assets copying, VFB history suspecnsion from saving during sample rendering.), but usability should be about fine.
    EDIT #4: V 008 has now an option to copy texture files over to the material library assets path. Defaults to off, so it won't repath and copy textures when a new material library is created from an open max file.
    EDIT #5: V 103 is a complete rewrite, to finalise the script and prepare it for integration into the library. The post has been updated to describe the features.
    EDIT #6: V 104 fixes two issues; the first has to do with matlibs containing corrupt entries. The script now detects those and fixes the matlibs transparently. The second was with the asset copying for matlibs (only. max files were good.). It didn't quite work as intended, and didn't copy and repath the textures at all. Now it does.
    EDIT #7: V 106 fixes an issue which didn't allow for recursive search, and makes a few minor QoL changes to he UI elements and tooltips.
    EDIT #8: V 106b only fixes an inconsistency which lead to a bug.
    EDIT #9: V 107 fixes a silly, terminal bug.
    EDIT #10: V 108 adds a cleaning of custom attributes and bad class IDs, via the Autodesk's own scene converter methods present in either Max files or matlibs.
    The original files will *not* be changed in any way, however, only the created matlibs will be cleaned.
    It also shuts max up completely (that's the hope, at least) on file load, so batch operations should flow to their rightful end now.
    EDIT #11: V 111 holds and fetches the currently open max scene. Fetching should happen in any case, also if the user holds the ESC key, at any stage of the process.
    The behaviour of the pick buttons for when the user wants folders scanned (CTRL or ALT modifiers) has changed, and now will display a folder picking dialog, instead of a file one. Tolltips have been updated to reflect the change.

    This is now actively going through QA, and is considered feature-complete for this stage. It will be integrated into the material library with the next public hotfix.

    Please upgrade from previous versions.
    Last edited by ^Lele^; 21-04-2021, 10:35 PM.
    Lele
    Trouble Stirrer in RnD @ Chaos
    ----------------------
    emanuele.lecchi@chaos.com

    Disclaimer:
    The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

  • #2
    This is great! thanks for sharing !

    I've tested it and all worked well expect it can't generate render preview
    I received these 2 messages "Can't find the material sample max file" and "Can't find the material sample"
    I fixed it by changing the name for the max file to "Swatch2016.max" instead of "Swatch_2016.max" as per the name in the script .

    Another issue is that, if you have multi-sub material it will render only the first one -probably intended- . I would like to have an option to render the "nested" materials too and separate them .
    Also I had to close max and open it again in order to refresh VRay assets browser and see the new added library. I think Refresh button is needed here for the assets browser.
    Thank you!

    -------------------------------------------------------------
    Simply, I love to put pixels together! Sounds easy right : ))
    Sketchbook-1 /Sketchbook-2 / Behance / Facebook

    Comment


    • #3
      Nasty bug, that of the filename, very very sorry, it's fixed now.
      Find the script in the first post.

      There is a new, much more nuanced version coming which ought to take care of your requests regarding multisub (at least, it'll render them all.).
      The library's features aren't mine to touch (that's why it works, likely, eh.), but you're being read by the right people.
      Last edited by ^Lele^; 27-07-2020, 02:41 AM.
      Lele
      Trouble Stirrer in RnD @ Chaos
      ----------------------
      emanuele.lecchi@chaos.com

      Disclaimer:
      The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

      Comment


      • #4
        I think this is also ready for some feedback.
        I expanded on the script functionalities, and it can now render a variety of lighting setups, and geometric shapes, at different quality levels.
        I have also tried to move completely away from an Ortho camera (Max's traditional material samples rendering setup) to allow for prettier lighting.
        The max file is a wee bit bigger (~60MB to download), currently, but it can possibly be made smaller for the final release (via decimation, or some change in models.).
        Everything stays the same (max file in assets folder, run script.).
        The UI is below.

        Notice that because of the number of possible permutations, i can't quite guarantee all the options will work with all the shaders.
        Also, take cues from the script UI: if it turns off shelling when selecting the statue, trust it, and don't turn it back on.
        Some things will eventually be forced to avoid issues.

        EDIT: VERY IMPORTANT! Do *not* open the scene which comes with the script, and then run the script on it.
        All sorts of things would happen, and none of them pretty. The scene simply sits -untouched and forgotten- into the assets folder.
        The script is run on current scenes (if you're dumping their materials to the library) or on an empty one to do library update work.

        Suggestions and feedback are very welcome, there's plenty of scope to be explored still.

        Click image for larger version  Name:	UI_render.png Views:	21 Size:	17.9 KB ID:	1076319Click image for larger version  Name:	UI_Lighting.png Views:	19 Size:	19.0 KB ID:	1076320Click image for larger version  Name:	UI_Geo.png Views:	19 Size:	18.0 KB ID:	1076321
        Last edited by ^Lele^; 29-06-2020, 03:19 AM.
        Lele
        Trouble Stirrer in RnD @ Chaos
        ----------------------
        emanuele.lecchi@chaos.com

        Disclaimer:
        The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

        Comment


        • #5
          Very nice update!
          it is really handy and it is something I wanted to have for ages .so thanks for the hard work you put on this!.
          I will need to test it more but for now I have few suggestions:
          1- to make multi-sub rendering as a checkbox, something like "render multi-sub materials sample" in that way if the scene/material library have some materials that's using multi-sub material the user will get a render for them using the sample that's you are using now while the other will use the default sample or whatever selected under the sample type
          2- I still prefer to have one render per material for those sub materials ..maybe another option like " separate multi-sub materials" but then I'm not sure how the material itself would be saved or used later .
          3-Adding materials to an existing library isn't unusual or updating it . so an option to "skip existing materials " would be great .

          Thank you again.
          -------------------------------------------------------------
          Simply, I love to put pixels together! Sounds easy right : ))
          Sketchbook-1 /Sketchbook-2 / Behance / Facebook

          Comment


          • #6
            Very good ideas, thanks a lot!
            Will see what can be done.
            Lele
            Trouble Stirrer in RnD @ Chaos
            ----------------------
            emanuele.lecchi@chaos.com

            Disclaimer:
            The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

            Comment


            • #7
              Here's the latest version of script and scene (the scene hasn't changed, however.)

              I have added the "skip existing" checkbox, OFF by default.
              Notice it will only be able to skip the existing images, regardless of their content (there is no provision to store the rendering options anywhere in the file, be it in the name or metadata).
              Meaning that if it's run on a library which has just been downloaded, it will render no sample at all.

              For Multi-Sub materials, it's not good to split them (max itself doesn't with its libraries on which we depend.), while having the script react to the material class (not just multi-sub) is theoretically possible, but it can lead to a set of incongruences.
              Will think more about that, but don't hold your breath.
              You're better off prepping the scene whose library you're dumping to ensure you have it written as you like.

              Lele
              Trouble Stirrer in RnD @ Chaos
              ----------------------
              emanuele.lecchi@chaos.com

              Disclaimer:
              The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

              Comment


              • #8
                I've tried the latest version and noticed that I have to restart 3ds Max to be able to see the updated material library in the asset browser. A way to refresh it without restarting 3ds Max would be nice. Other than that I think that when this is further implemented it would be good to have some "convenience" options. Like for instance dragging the materials to the browser / adding it through the material editor so that it's easier to select which materials to transfer. Right now I find it easier to create a new scene and add the few materials that need converting.

                Comment


                • #9
                  I cannot influence the material library's behaviour, myself, but you're being read by the right people.
                  Some of the things you mentioned seem to be doable, others may prove tricky.
                  Thanks for the suggestions, though, duly noted!
                  Lele
                  Trouble Stirrer in RnD @ Chaos
                  ----------------------
                  emanuele.lecchi@chaos.com

                  Disclaimer:
                  The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

                  Comment


                  • #10
                    Hey, there actually is a way to refresh the browser - vrayDestroyAssetBrowser() and vrayShowAssetBrowser() in maxscript destroy/create the asset browser.

                    Comment


                    • #11
                      Super, thank you! Implementing!
                      Lele
                      Trouble Stirrer in RnD @ Chaos
                      ----------------------
                      emanuele.lecchi@chaos.com

                      Disclaimer:
                      The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

                      Comment


                      • #12
                        The first post has been updated to include auto and manual refresh of the Asset browser.
                        Lele
                        Trouble Stirrer in RnD @ Chaos
                        ----------------------
                        emanuele.lecchi@chaos.com

                        Disclaimer:
                        The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

                        Comment


                        • #13
                          I just installed Vray 5 to test out on the latest build of max 2021 and this was the first thing I started looking into; the material editor and asset library. This topic seems to be heading in a progressive direction and I couldn't find much discussion elsewhere. Here's some initial thoughts:

                          - The default material preview in max seems to have a pretty harsh hotspot on the ball and with the gray/almost white background it can be hard to discern similar materials in a populated editor. Having the ability to change between preview scenes in the editor would be extremely beneficial (like the geometry sample types you have listed in ver 005 of the script)
                          - Changing the sample type in the max material editor between sphere, cylinder, cube, doesn't affect the preview - would be nice to change this on the fly in the editor rather than batch render a whole library
                          - I found a thread were someone asked where to change the preview scene and that was strongly discouraged
                          - I tried to manually install a mat library into the vray material library directory, but that didn't work - saving a library from scene via this script works great, but not every scene is perfect and redundant/duplicate materials get rendered. This can be manually cleaned up within max in a roundabout way which then shows up in the vray asset browser, but in the future it seems this should work within the asset browser itself (ability to move/rename/copy)
                          - I can put a material from the max editor to library and it will show up in the the browser, but without a preview even when vray material library is configured in project paths.
                          Click image for larger version

Name:	2020-09-22_16-19-47.png
Views:	7571
Size:	67.4 KB
ID:	1085062
                          In order to have preview, the whole library has to batch render again through script version 005 then must be manually refreshed using script version 006
                          Click image for larger version

Name:	2020-09-22_16-27-43.png
Views:	7382
Size:	52.5 KB
ID:	1085063

                          - I also get a lot of missing dll dialogues pop up throughout this process (mental ray from old scenes) is there any way to suppress these?


                          Comment


                          • #14
                            Originally posted by rusteberg View Post
                            In order to have preview, the whole library has to batch render again through script version 005 then must be manually refreshed using script version 006
                            My bad, i will remove v005, it's only confusing to people (and to me, clearly), and i got pretty much zero feedback (sure sign no one is actively doing a thing with it.).
                            Only use v006 for now, at some point that will be integrated.

                            - I also get a lot of missing dll dialogues pop up throughout this process (mental ray from old scenes) is there any way to suppress these?
                            Autodesk Scene Converter removes those, optionally automatically on scene open.


                            Lele
                            Trouble Stirrer in RnD @ Chaos
                            ----------------------
                            emanuele.lecchi@chaos.com

                            Disclaimer:
                            The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

                            Comment


                            • #15
                              The scipt has been rewritten, and is about to be integrated and released with update 1.
                              Please have a try (first post.) and let me know if anything's broken, or could be done better.
                              Lele
                              Trouble Stirrer in RnD @ Chaos
                              ----------------------
                              emanuele.lecchi@chaos.com

                              Disclaimer:
                              The views and opinions expressed here are my own and do not represent those of Chaos Group, unless otherwise stated.

                              Comment

                              Working...
                              X