Announcement

Collapse
No announcement yet.

Maxscript: Condense materials with same name

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

  • Maxscript: Condense materials with same name

    Hey guys,
    I have a problem here that is bugging me for years. When we get CAD data, we often have multiple materials sharing the same name in the scene. These are exactly the same material, but assigned to different objects. Is there a way to condense these materials into one material in a fast (one-click) way? Something like this must be very easy in MaxScript, but I don't know how to use it.
    https://www.behance.net/Oliver_Kossatz

  • #2
    I can help, likely.
    Would you be so kind as to send me a sample scene for this? Small is fine, i just need to test the logic.
    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


    • #3
      Ok, i made the test file myself.
      Attached, the test scene and the script.

      Running it will get stuff doodled, and eventually done.
      It will print minimal info in the listener, and it will print out if anything (hopefully graciously) failed.
      It's built with heavy scenes in mind, so it will set up max in the quickest possible condition before running, and return it to normal as the process has concluded successfully or not (meaning it'll turn on expert mode, deactivate UI bits, disable VP redraw, and so on.).
      It will NOT save your scene.
      It will recognise different shaders based on their first level properties only (for speed. traversing and hashing complex shaders would take a long time, potentially).
      Run it on the provided scene first to see what the behaviour is, and please report anything which doesn't behave as you would like it to.

      sample result:
      "Parsing and hashing 491 materials."
      "Parsing and Hashing 2274 geometry nodes."
      "all done."
      18.868 seconds
      EDIT: New version here.
      Last edited by ^Lele^; 27-01-2019, 06:07 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.

      Comment


      • #4
        I am personally pouring a virtual drink for LeLe...cheers!
        I have come across this kind of shit in the past and it is definitively a massive ball-ache. So whilst I don't have anything of the sort right now, thanks LeLe, great work!
        https://www.behance.net/bartgelin

        Comment


        • #5
          Originally posted by ^Lele^ View Post
          Ok, i made the test file myself.
          Attached, the test scene and the script.

          Running it will get stuff doodled, and eventually done.
          It will print minimal info in the listener, and it will print out if anything (hopefully graciously) failed.
          It's built with heavy scenes in mind, so it will set up max in the quickest possible condition before running, and return it to normal as the process has concluded successfully or not (meaning it'll turn on expert mode, deactivate UI bits, disable VP redraw, and so on.).
          It will NOT save your scene.
          It will recognise different shaders based on their first level properties only (for speed. traversing and hashing complex shaders would take a long time, potentially).
          Run it on the provided scene first to see what the behaviour is, and please report anything which doesn't behave as you would like it to.

          sample result:
          !! gotta try that on monday! Thanks!
          Last edited by Ihno; 25-01-2019, 04:07 PM.
          German guy, sorry for my English.

          Comment


          • #6
            Originally posted by ^Lele^ View Post
            Ok, i made the test file myself.
            Attached, the test scene and the script.
            Jesus, you're quick! I just tested it on a heavy production scene, and it actually works as expected! It just reduced the amount of materials from 113 to 21.
            Great, thank you so much!
            I owe you some beer. You still like that, right?
            Last edited by kosso_olli; 25-01-2019, 03:36 PM.
            https://www.behance.net/Oliver_Kossatz

            Comment


            • #7
              I'm horrible at holding beer, these days.
              But i'm half a farmer, so i'll happily get a few seeds!
              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
                Made a new version (right-mouse click and download as...), which you can grab directly from my gitHub (i *strongly* discourage you from poking around and downloading stuff. it's not meant for widespread usage, and it's likely broken to bits anyway. You've been warned. ).

                The version now creates a macroscript under the VRay category, called Duplicate Material Condenser.
                You can then assign it a shortcut key, drag it on bars and whatever else.

                It's got an UI which simply allows to choose the undo state (turn off should the scene be ginormous, and ram very scarce. makes no difference to speed that i could see, if ram is aplenty.), and has three progress bars, one per script phase.
                It will also pop a neat dialog box as it completes, showing statistics of what was done to the scene.

                There has been no substantial change in the code, if it's been cleaned up and reorganised a bit.
                Last edited by ^Lele^; 27-01-2019, 06:06 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.

                Comment


                • #9
                  Great can't wait for a crappy Revit Scene to try this on. Does this also work with materials that are part of multiple multisubs?
                  A.

                  ---------------------
                  www.digitaltwins.be

                  Comment


                  • #10
                    Originally posted by Vizioen View Post
                    Does this also work with materials that are part of multiple multisubs?
                    In principle, yes: it operates on the scenematerials library, and those materials are present there as individual ones too.
                    It does not condense a multimaterial in fewer IDs, that's not what the goal is, as that's covered by the tools in the material editor, but it should get rid of more identical materials which aren't instances.
                    But please verify it does what it should.
                    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


                    • #11
                      Originally posted by Vizioen View Post
                      Great can't wait for a crappy Revit Scene to try this on. Does this also work with materials that are part of multiple multisubs?
                      I second that! Thanks Lele!
                      Neal Biggs

                      3D Generalist | Freelance | Founder | Big5 Studio
                      http://big5studio.com/

                      3ds Max 2022 - V-Ray5 Update 2.2

                      Comment


                      • #12
                        Sounds like a cool tool - just tested and it doesn't seem to work as i expected. If i have 5 cubes and 5 materials all with the same diffuse colour should the script make all 5 cubes just have the one material ?

                        Comment


                        • #13
                          Originally posted by leehumphries View Post
                          If i have 5 cubes and 5 materials all with the same diffuse colour should the script make all 5 cubes just have the one material ?
                          No. The script is intended to work if the 5 cubes have 5 different materials, but all with exactly the same name. This can never happen in Max, because Max always needs a unique name for materials when assigning them to objects, but stuff like this easily happens by importing objects from unknown sources.

                          https://www.behance.net/Oliver_Kossatz

                          Comment


                          • #14
                            Now i understand. Works perfectly. Will help massively with SK model imports

                            Comment


                            • #15
                              Oh Lele, thank you so much! I had to spend days in the past for this!

                              Click image for larger version

Name:	material_condense.PNG
Views:	703
Size:	3.5 KB
ID:	1057285
                              Attached Files
                              https://www.behance.net/Oliver_Kossatz

                              Comment

                              Working...
                              X