Reduce texture sizes easily with this script.

13567

Comments

  • EsemwyEsemwy Posts: 578

    Oh nice! This works great! :D 

    No need for high res textures for things way in the background of the scene, so this is brilliant! :) Thank you!

    Glad everybody's (except @hphoenix sad) enjoying it.

    hphoenix, I feel your pain... There's nothing worse than finding the perfect API then discovering it doesn't quite work. 

  • AdreanAdrean Posts: 136

    Hi, may I ask a simple question: Does it also work with 3Delight?

  • mjc1016mjc1016 Posts: 15,001

    It should...

  • hphoenixhphoenix Posts: 1,335
    Adrean said:

    Hi, may I ask a simple question: Does it also work with 3Delight?

    Well, the script will resize the textures, but it isn't really needed for 3DL.  3Delight runs all textures for a render through TDLMAKE (a utility it runs when you go to render) that generates temporary MipMap images.  These have multiple levels of resolution inside, and allow 3Delight to automatically adjust for detail levels (like some game engines do.)  I believe the TDLMAKE processed images are stored in the DAZ temp directory during rendering.

     

     

  • mjc1016mjc1016 Posts: 15,001
    hphoenix said:
    Adrean said:

    Hi, may I ask a simple question: Does it also work with 3Delight?

    Well, the script will resize the textures, but it isn't really needed for 3DL.  3Delight runs all textures for a render through TDLMAKE (a utility it runs when you go to render) that generates temporary MipMap images.  These have multiple levels of resolution inside, and allow 3Delight to automatically adjust for detail levels (like some game engines do.)  I believe the TDLMAKE processed images are stored in the DAZ temp directory during rendering.

     

     

    That's where they are...and if you were to Render to RIB, with the 'Collect' option enabled, it will put them into that folder, too.

  • Wow! This script is fantastic!

    A scene that was taking forever to reach 5% can now (just barely) fit on my graphics card and renders in almost no time at all.

    Thank you, thank you smileyyes

  • BruganBrugan Posts: 365

    Hello all!

    I've been at this for a couple of weeks and really enjoying it. For us noobs, can someone reply with the correct folder locations to place these files, or maybe point me at a tutorial for manual installs?

    Thanks very much, hope to be sharing renders with you guys and gals soon :)

  • EsemwyEsemwy Posts: 578
    Brugan said:

    Hello all!

    I've been at this for a couple of weeks and really enjoying it. For us noobs, can someone reply with the correct folder locations to place these files, or maybe point me at a tutorial for manual installs?

    Thanks very much, hope to be sharing renders with you guys and gals soon :
     

    Both go in the same folder in your Content Library. Place the files somewhere in 'Scripts/' and you'll be good to go. You'll have to access them through Content Library as well, since there's no metadata to make it show up in Smart Content.

  • BruganBrugan Posts: 365

    Thank you! :)

    Experemented with it a bit, very handy, awesome script :)

  • outrider42outrider42 Posts: 3,679

    So if you run the script without pres ctrl and happen to save, what happens? Are the textures over written? Are the textures automatically applied when this script is ran? Can you save them as a preset or does the temp folder delete them when you close?

  • barbultbarbult Posts: 24,244

    So if you run the script without pres ctrl and happen to save, what happens? Are the textures over written? Are the textures automatically applied when this script is ran? Can you save them as a preset or does the temp folder delete them when you close?

    I accidently did this one time. The next time I opened DS and opened that scene, I got missing file errors. The files in the temp folder had been erased. I had to reapply the original material files and reduce again.

  • TooncesToonces Posts: 919

    I use DIM for most of my content. When I run the script, it chugs for a minute or so, and says successful in the log:

    2017-01-19 18:10:15.745 Loading script: D:/My DAZ 3D Library/Scripts/ReduceTextures/Reduce Texture.dsa
    2017-01-19 18:11:47.614 Script executed successfully: D:/My DAZ 3D Library/Scripts/ReduceTextures/Reduce Texture.dsa

    But it doesn't reduce the memory in GPUZ. I can't find the new files in temp or in my library (when using CTRL). Not sure why it's not working for me. Maybe because I store my content on the D drive instead of the C drive.

     

  • havsm said:

    I use DIM for most of my content. When I run the script, it chugs for a minute or so, and says successful in the log:

    2017-01-19 18:10:15.745 Loading script: D:/My DAZ 3D Library/Scripts/ReduceTextures/Reduce Texture.dsa
    2017-01-19 18:11:47.614 Script executed successfully: D:/My DAZ 3D Library/Scripts/ReduceTextures/Reduce Texture.dsa

    But it doesn't reduce the memory in GPUZ. I can't find the new files in temp or in my library (when using CTRL). Not sure why it's not working for me. Maybe because I store my content on the D drive instead of the C drive.

     

    same for me.

  • TooncesToonces Posts: 919

    I echoed out the directory:

    App.statusLine(oContentMgr.getContentDirectoryPath(1));

    And it is showing properly:

    D:/My DAZ 3D Library

    So internally it recognizes my D drive. Since I'm not getting any of the other status updates written to the log file, I'm guessing it doesn't get into the for loop. I need to get a better editor than notepad and will try to add some more logging to see where it's exiting early.

  • TooncesToonces Posts: 919

    Figured it out. Here are the takeaways:

    1. Do NOT do Select All or Select Children in your scene pane before running script. You'll get errors and the script will create a resolution for every size until 0x0. This is because if an object has bones, it will iterate over that object for every single bone (see attached).

    2. If you use Select All Objects (very handy feature) in scene pane, you must MANUALLY DESELECT THE GROUPS (the peace symbol thing - see attachment 2). This means expanding EVERY object to make sure you find all of the groups to deselect them. If even a SINGLE group remains selected, the script will complete 'successfully' but will not actually 'do' anything whatsoever. You want the boxy things ('objects') to be selected, not the groupy things (peace symbols).

    Do this, and it'll work like a charm.

    If Daz has an api to distguish between object/peace-symbol-thingy (group?), we could probably update the script to make it smarter so step #2 can be avoided.

    I ran the script on a scene I made yesterday (successfully) and it only knocked 200MB off of 5.5GB VRAM load. But that's something at least. And I could run it more than once, sacrificing quality. I imagine it has much greater impact on scenes with bunch of 4096 maps, so definitely a handy tool for the toolbelt!

    SelAll.PNG
    963 x 796 - 207K
    Group1.PNG
    287 x 122 - 6K
  • TooncesToonces Posts: 919

    Oh and one more thing: Wardrobe items are apparently not objects (or at least they don't get chosen with Select All Objects). So if you want to reduce them, you'll have to manually pick them (in addition to Select All Objects and manually deselecting the peace symbol things).

    Would be nice to have a 'select everything with maps'...but then again, wardrobe are often closer to your camera so you probably often do not want them reduced.

  • hphoenixhphoenix Posts: 1,335
    edited October 2018

    Okay.  It's done....I think.

    I've added a lot of options in the dialogs popped up....wiring it all up to work with the rest of the script took a while.

    It still has the issue with PNG w/Alpha resizing issues, as those are pretty much inherent in the internal resizer, and there are even problems with ImageMagick.  But it does what it can.

    Presenting:  TextureMapResizer and TextureMapSizeSwitcher!

     

    TextureMapResizer:  

    This script allows you to resize the image maps of the selected objects, the selected objects and ALL their child objects (recursively), or if you have NO objects selected, it prompts for if you wish to apply resizing to ALL objects in the scene.  If the object can have geometry (and thus materials, and as such, image maps) it will be handled.  It probably doesn't do the following:  lights (except emissive objects), cameras, nulls, or Render Settings elements (like the Iray HDRI environment map.)  Those items will be ignored.

    It allows you to select by checkboxes which levels of size reduction you want to generate.  Medium (1/2 resolution, 1/4 pixels), Small (1/4 resolution, 1/16 pixels), and Xtra-Small (1/8 resolution, 1/64 pixels).  You can generate all, some or just one of the selections (technically, you COULD select NONE of them, and you would generate no resized files.  (1/2 resolution means a 4096 x 4096 image becomes a 2048 x 2048, and so on.)

    You can use Internal Scaling, or External Scaling via ImageMagick (installed separately.)  If you don't use External, you don't need to install ImageMagick.

    The Alternate PNG w/Alpha scaling mechanism for internal scaling will effectively drop the alpha channel.  It re-enables it, but it's empty.  May work okay for some, may not for others.

    The DAZ Connect Content Path index is selectable via dropdown, so if you have issues with Connect-installed images not being resized successfully, you may need to change the 1 to a 0 in this dropdown.

    All resized images are saved into the same path the original file was in, and in the same format.

     

    TextureMapSizeSwitcher:

    This script allows you to switch which resolutions your selected objects (again, selectable to recursively find children, or prompt for all if no selected objects) to the original (Full) size images, or Medium/Small/XtraSmall sizes.  If it doesn't find the appropriately sized image, you'll get a list at the end of the operation with a list of which (and out of how many) it couldn't find.  So if you create only Medium and Small when you resize, then try to select XtraSmall in this script, it's probably not going to find them.

    This script makes swapping sizes around in the scene for various objects much easier!

     

    Both scripts were tested primarily in DAZ Studio 4.8, so I haven't tested the Connect functionality....and as I don't install stuff with Connect, I don't really have anything to test with.  @barbult if you could (and anyone else wants to) try them out to see if you find any issues with the Connect-installed content?  I'd appreciate it!

    These scripts should handle pretty much all fit/parenting/groups stuff....but please, test it out and see how it performs!  Any suggestions are welcome!

    (Due to upload issues, the two script .dsa files are now zipped into a single file)

    zip
    zip
    TextureMapResizerScripts.zip
    10K
    Post edited by hphoenix on
  • TooncesToonces Posts: 919

    Wow, sounds like you fixed both issues I mentioned and enhanced the crap out of this thing!

    Heck, with everything you describe, I'm surprised you're giving it away for free. I can imagine it would sell in the Daz store (similar to other reducing products like Decimator). Regardless, thanks for all your work on this!!

  • hphoenixhphoenix Posts: 1,335
    havsm said:

    Wow, sounds like you fixed both issues I mentioned and enhanced the crap out of this thing!

    Heck, with everything you describe, I'm surprised you're giving it away for free. I can imagine it would sell in the Daz store (similar to other reducing products like Decimator). Regardless, thanks for all your work on this!!

    Thanks!

    I started work on this over 6 months ago.....but when I ran into issues with the PNG/Alpha resizing with ImageMagick, I hoped I could find a way around it.  But it didn't really happen.....so it fell to the wayside.  I did do some more work on it over that time, but I needed to write the readme, and the installing of ImageMagick was a bit of a pain for the end-user.  So I never intended to release it commercially (since it depends on an external resizing program.  Then when @Esemwy posted about the internal resizing mechanism using the Image class, I adapted it (with his permission.)  Then I added a few more options to allow people to select which method to use, whether or not to create various sizes, and more.

    While the amount of time was definitely similar to a commercial product, I never would release something like this for pay......stuff like this should really be built-in to either DS or Iray itself.

    But I hope you like it, and that it helps!

     

  • hphoenixhphoenix Posts: 1,335

    Whoops.....realized I left the 'debug' flag in my code on the main resizing script (TextureMapResizer.dsa) set to 'true'....which disables the progress bar code (which can cause some issues when debugging.)  I've changed it to false and updated the files in my post with the files.  If you already downloaded it, you can either edit the line in the file (line 6, "var debug = true;" to "var debug = false;") or you can download the updated script.

     

  • barbultbarbult Posts: 24,244

    The new hphoenix scripts are not working properly on content installed with Daz Connect. The texture resizer script finds the textures in the Daz Connect content directory and creates the reduced textures in the non-Daz Connect content directory. However, the switcher script looks for the reduced textures in the Daz Connect directory and doesn't find any of the reduced textures. I used the default settings in the scripts.

    I also noticed that if I tried to create the reduced textures a second time (because the switcher said they couldn't be found), I got a message for each one that said it already existed and I was asked if I wanted to replace it. I had to click Yes about a thousand times (exaggeration), because it asked for each texture file. Luckily I could click Abort Script just once and that would kill it.

     

     

    Screenshot 2017-01-22 11.43.31.png
    356 x 354 - 14K
    Screenshot 2017-01-22 11.46.12.png
    518 x 1277 - 104K
    resizer replace.PNG
    359 x 357 - 21K
  • hphoenixhphoenix Posts: 1,335
    barbult said:

    The new hphoenix scripts are not working properly on content installed with Daz Connect. The texture resizer script finds the textures in the Daz Connect content directory and creates the reduced textures in the non-Daz Connect content directory. However, the switcher script looks for the reduced textures in the Daz Connect directory and doesn't find any of the reduced textures. I used the default settings in the scripts.

    I also noticed that if I tried to create the reduced textures a second time (because the switcher said they couldn't be found), I got a message for each one that said it already existed and I was asked if I wanted to replace it. I had to click Yes about a thousand times (exaggeration), because it asked for each texture file. Luckily I could click Abort Script just once and that would kill it.

     

     

    @barbult Did you try switching the "Connect ContentPath Num" option from 1 (the default) to 0?  This was the original issue you had with @Esemwy 's script, and you had to change the value to get it working right on connect files.....

    You can avoid the 'replace' popups by selecting the 'Automatically replace existing resized images' option in the resizer dialog, also.

    Let me double check and see what is being done about the sPath variable on the save....it should use what was found during loading, but I'll double check this evening.

     

  • barbultbarbult Posts: 24,244
    hphoenix said:
    barbult said:

    The new hphoenix scripts are not working properly on content installed with Daz Connect. The texture resizer script finds the textures in the Daz Connect content directory and creates the reduced textures in the non-Daz Connect content directory. However, the switcher script looks for the reduced textures in the Daz Connect directory and doesn't find any of the reduced textures. I used the default settings in the scripts.

    I also noticed that if I tried to create the reduced textures a second time (because the switcher said they couldn't be found), I got a message for each one that said it already existed and I was asked if I wanted to replace it. I had to click Yes about a thousand times (exaggeration), because it asked for each texture file. Luckily I could click Abort Script just once and that would kill it.

     

     

    @barbult Did you try switching the "Connect ContentPath Num" option from 1 (the default) to 0?  This was the original issue you had with @Esemwy 's script, and you had to change the value to get it working right on connect files.....

    You can avoid the 'replace' popups by selecting the 'Automatically replace existing resized images' option in the resizer dialog, also.

    Let me double check and see what is being done about the sPath variable on the save....it should use what was found during loading, but I'll double check this evening.

    I did try all three options you provided for "Connect ContentPath Num".

    When set to 0, it claims to have created the reduced images, but I cannot find them anywhere. If I try again, it says they already exist, but I don't know where and can't find them. The switcher script does not find them either.

    When set to 1 or 2, it creates the reduced images in my non-Daz-Connect directory. The switcher script does not find them.

    Do not try to save the reduced texture files in the Daz Connect directory structure. That does not work properly. That is why Esemwy changed the script save the reduced texture files in the non-Daz-Connect directory instead. I think the change in the Esemwy script to use 0 was only to get rid of a logged error message. His later version did not set it to 0, and it still created and loaded the reduced images for me just fine.

     

  • hphoenixhphoenix Posts: 1,335

    Okay.   Seems I misunderstood what his code was actually doing with the connect directories.  I'll have to re-work things a bit, but shouldn't take long.

     

  • EsemwyEsemwy Posts: 578

    Not sure why I haven't been getting notifications here. I'll take a look at fixing the skeleton vs bone problem and take a gander at @hphoenix new stuff.

  • hphoenixhphoenix Posts: 1,335

    Okay, I think I've wrapped my head around the issue, and made a solution.  I've got to test the new code changes to make sure I haven't broken anything.  I also added setting saving/reloading for the script for all the options, so they'll stay where you set them unless you change them.

    Just to make sure my thinking is correct.....

    IF the original full size image file is in the Connect-installed directory path (i.e., the one we get from App.getContentMgr().getCloudContentDirectoryPath())  then we need to save it into a NON-Connect content directory path (which we will need to create if it doesn't exist, and it likely won't.)  SO all the resized images WILL reside in a NON-Connect directory path.

    When switching resolutions via script, we need to check IF we are switching TO the FULL resolution image, and we don't find it in the same path as the resized ones, and it exists in the Connect-installed directory path, then we switch to that one.  If we are switching FROM the full resolution image, and it is in the Connect-installed directory path, we need to scan through the content paths available to see if it exists in any of them, and if we find it, we switch to THAT image.  If NONE of these work, then it's a "File Not Found" condition.

    Do I have that about correct?  That's what I've coded for....

     

  • hphoenixhphoenix Posts: 1,335

    Okay, I've got some fixes ready (I think) that should hopefully solve the Connect files issues.  But it's 1:45am here, and I have work tomorrow, so I'm off to bed.  I'll post the files tomorrow when I get home.

     

  • hphoenixhphoenix Posts: 1,335
    edited October 2018

    Okay, these files should have the fixes for connect-installed content.  Assuming I didn't miss anything.

    When resizing, if it finds that a given image file is in the Connect directory path, it will use the selected "Content directory for Connect Files" options path, and append the relative filename of the original (i.e., "/data/cloud/...../...../etc.") and append that to the path, and save the files there.

    When switching between resized files:

        If switching FROM the Full Resolution file, it will pull the relative file path from the Connect-Installed file, then loop through all non-connect content paths defined (which are what are in the option in the resizer) looking for any matches to the size we are switching to.  If it finds one, it uses it.  If it doesn't find it, then it's a missing file.

        If switching TO the Full resolution file, and it doesn't find it in the original content directory, it will pull the relative file path from it, prepend it with the Connect installed content path, and look for it there.  If it still doesn't find it, it's considered a missing file.

    That should fix the issue.  (note, until I get some feedback on these, I won't update the originals I uploaded.)

    (edit:  Had to re-up as a zip with both files in it, due to upload issues with the main dsa script file.)

     

     

    zip
    zip
    TextureMapResizerScripts.zip
    10K
    Post edited by hphoenix on
  • hphoenixhphoenix Posts: 1,335

    Um.... @barbult ?  @Esemwy ? @havsm ?  Anyone?  Bueler?  Bueler?  Bueler?

     

  • TooncesToonces Posts: 919

    Oh ya. Now we're cooking with propane. Loaded up a 4532 mb scene. Created mediums and switched to medium. GPUZ now shows 3593 mb. Chopped off a GB!

    Just to be clear, I ran the version from the post you made on Jan 21st...since I use DIM and avoid connect when possible.

    The only confusing part is how TextureMapResizer didn't update my textures automatically, like ReduceTextures did. But didn't take long for me to figure out I needed to run TextureMapSizeSwitcher...and now that I understand it, I kinda like them being separate.

    Thanks!

Sign In or Register to comment.