Reduce texture sizes easily with this script.

EsemwyEsemwy Posts: 578
edited December 2016 in Freebies

It's been noted that Iray is getting more memory hungry in the latest beta. That, coupled with the tendency of PAs to include 4K maps (a good thing normally), even minor scene elements can consume significant texture memory. With this script, each texture of the selected scene element is reduced by half in each dimension (one-fourth resolution). The new textures are saved into the Studio temporary directory by default, so they'll disappear when the application exits. That means you should save your scene before running the script, not after. If, however, you press CONTROL (COMMAND on OS X) while running the script, the newly scaled images will be saved along side the original textures with the resolution appended to the basename (i.e. xxxx_2048x2048.jpg). Just place the script in one of your content folders. Enjoy.

Edit: added icon
Edit: added Connect compatibility
Edit: Fixed for props / primitives

Reduce Texture.png
91 x 91 - 8K
dsa
dsa
Reduce Texture.dsa
3K
Post edited by Esemwy on
«134567

Comments

  • Oso3DOso3D Posts: 15,009

    ... Wow, very nice, thanks!

    I often run into this problem with Skydome stuff, where I want to make sure the skydome is at max resolution but other figures and stuff don't need to be.

     

  • EsemwyEsemwy Posts: 578

    ... Wow, very nice, thanks!

    I often run into this problem with Skydome stuff, where I want to make sure the skydome is at max resolution but other figures and stuff don't need to be.

     

    You're quite welcome.

  • DigiDotzDigiDotz Posts: 515

    Works like a charm -thanks!

  • hphoenixhphoenix Posts: 1,335
    Esemwy said:

    It's been noted that Iray is getting more memory hungry in the latest beta. That, coupled with the tendency of PAs to include 4K maps (a good thing normally), even minor scene elements can consume significant texture memory. With this script, each texture of the selected scene element is reduced by half in each dimension (one-fourth resolution). The new textures are saved into the Studio temporary directory by default, so they'll disappear when the application exits. That means you should save your scene before running the script, not after. If, however, you press CONTROL (COMMAND on OS X) while running the script, the newly scaled images will be saved along side the original textures with the resolution appended to the basename (i.e. xxxx_2048x2048.jpg). Just place the script in one of your content folders. Enjoy.

    Edit: added icon

    @Esemwy You beat me to the punch.  But using the Qt Image class to do the resizing was brilliant.....I missed that somehow.  Would you mind if I put out my scripts using that technique?  Most of my slowdown was getting all the install instructions made up since it used an external program to do the resizing?

     

  • EsemwyEsemwy Posts: 578
    hphoenix said:
    Esemwy said:

    It's been noted that Iray is getting more memory hungry in the latest beta. That, coupled with the tendency of PAs to include 4K maps (a good thing normally), even minor scene elements can consume significant texture memory. With this script, each texture of the selected scene element is reduced by half in each dimension (one-fourth resolution). The new textures are saved into the Studio temporary directory by default, so they'll disappear when the application exits. That means you should save your scene before running the script, not after. If, however, you press CONTROL (COMMAND on OS X) while running the script, the newly scaled images will be saved along side the original textures with the resolution appended to the basename (i.e. xxxx_2048x2048.jpg). Just place the script in one of your content folders. Enjoy.

    Edit: added icon

    @Esemwy You beat me to the punch.  But using the Qt Image class to do the resizing was brilliant.....I missed that somehow.  Would you mind if I put out my scripts using that technique?  Most of my slowdown was getting all the install instructions made up since it used an external program to do the resizing?

     

    Have at it. I discovered the technique a while back when I needed to build icons from textures. 

  • hphoenixhphoenix Posts: 1,335
    Esemwy said:
    hphoenix said:
    Esemwy said:

    It's been noted that Iray is getting more memory hungry in the latest beta. That, coupled with the tendency of PAs to include 4K maps (a good thing normally), even minor scene elements can consume significant texture memory. With this script, each texture of the selected scene element is reduced by half in each dimension (one-fourth resolution). The new textures are saved into the Studio temporary directory by default, so they'll disappear when the application exits. That means you should save your scene before running the script, not after. If, however, you press CONTROL (COMMAND on OS X) while running the script, the newly scaled images will be saved along side the original textures with the resolution appended to the basename (i.e. xxxx_2048x2048.jpg). Just place the script in one of your content folders. Enjoy.

    Edit: added icon

    @Esemwy You beat me to the punch.  But using the Qt Image class to do the resizing was brilliant.....I missed that somehow.  Would you mind if I put out my scripts using that technique?  Most of my slowdown was getting all the install instructions made up since it used an external program to do the resizing?

     

    Have at it. I discovered the technique a while back when I needed to build icons from textures. 

    It hadn't occured to me to look into the Qt Image class.  Though I do have a question....why are you using scale instead of smoothscale?  Just for speed?  The bilinear filtering does take a little longer, but normally does help.....though, since we're doing powers of 2 reductions (1/2 and 1/4th) I suppose it won't help much.....

     

  • EsemwyEsemwy Posts: 578
    hphoenix said:
    Esemwy said:
    hphoenix said:
    Esemwy said:

    It's been noted that Iray is getting more memory hungry in the latest beta. That, coupled with the tendency of PAs to include 4K maps (a good thing normally), even minor scene elements can consume significant texture memory. With this script, each texture of the selected scene element is reduced by half in each dimension (one-fourth resolution). The new textures are saved into the Studio temporary directory by default, so they'll disappear when the application exits. That means you should save your scene before running the script, not after. If, however, you press CONTROL (COMMAND on OS X) while running the script, the newly scaled images will be saved along side the original textures with the resolution appended to the basename (i.e. xxxx_2048x2048.jpg). Just place the script in one of your content folders. Enjoy.

    Edit: added icon

    @Esemwy You beat me to the punch.  But using the Qt Image class to do the resizing was brilliant.....I missed that somehow.  Would you mind if I put out my scripts using that technique?  Most of my slowdown was getting all the install instructions made up since it used an external program to do the resizing?

     

    Have at it. I discovered the technique a while back when I needed to build icons from textures. 

    It hadn't occured to me to look into the Qt Image class.  Though I do have a question....why are you using scale instead of smoothscale?  Just for speed?  The bilinear filtering does take a little longer, but normally does help.....though, since we're doing powers of 2 reductions (1/2 and 1/4th) I suppose it won't help much.....

     

    Exactly so. In scaling by one-half, I felt smooth-scaling was unnecessary. 

  • barbultbarbult Posts: 24,244

    Do you know if this will work on Content installed with Daz Connect? I'm concerned about the ability to save the scaled textures in the folder with original textures. Daz Studio does not allow adding files to the Daz Connect folders usually.

  • EsemwyEsemwy Posts: 578
    barbult said:

    Do you know if this will work on Content installed with Daz Connect? I'm concerned about the ability to save the scaled textures in the folder with original textures. Daz Studio does not allow adding files to the Daz Connect folders usually.

    Hmmm... Good point. I don't use Connect. I'll see what I can do about that. 

  • hphoenixhphoenix Posts: 1,335
    edited December 2016

    It should.  It simply pulls the list of images from the list of selected skeletons in the scene.  Those images have their own paths, and it saves (depending on if CTRL is pressed or not) to the Temp directory, or the directory they came from....regardless of if it was downloaded via connect or via DIM or even browsed to.  Mine does that too, though a little differently.  End result is that the images are loaded/saved based on where they were originally loaded from.

    And I thought DAZ Connect directories weren't locked.  But that is a possible concern if you tried to save to a Connect directory and Qt couldn't save to it.  Saving to the Temp directory should still work.

    (I don't use Connect either....so haven't tested this.)

     

    Post edited by hphoenix on
  • barbultbarbult Posts: 24,244

    Well, I have 95% of my content installed with Connect. I'll try it and report back with what happens.

  • EsemwyEsemwy Posts: 578
    hphoenix said:

    It should.  It simply pulls the list of images from the list of selected skeletons in the scene.  Those images have their own paths, and it saves (depending on if CTRL is pressed or not) to the Temp directory, or the directory they came from....regardless of if it was downloaded via connect or via DIM or even browsed to.  Mine does that too, though a little differently.  End result is that the images are loaded/saved based on where they were originally loaded from.

    And I thought DAZ Connect directories weren't locked.  But that is a possible concern if you tried to save to a Connect directory and Qt couldn't save to it.  Saving to the Temp directory should still work.

     

    Does connect put textures in 'My Daz Connect Library' or in one of your other content libraries? I'm working on a solution now that should redirect connect paths to the regular content folder.

  • barbultbarbult Posts: 24,244
    edited December 2016
    Esemwy said:
    hphoenix said:

    It should.  It simply pulls the list of images from the list of selected skeletons in the scene.  Those images have their own paths, and it saves (depending on if CTRL is pressed or not) to the Temp directory, or the directory they came from....regardless of if it was downloaded via connect or via DIM or even browsed to.  Mine does that too, though a little differently.  End result is that the images are loaded/saved based on where they were originally loaded from.

    And I thought DAZ Connect directories weren't locked.  But that is a possible concern if you tried to save to a Connect directory and Qt couldn't save to it.  Saving to the Temp directory should still work.

     

    Does connect put textures in 'My Daz Connect Library' or in one of your other content libraries? I'm working on a solution now that should redirect connect paths to the regular content folder.

    Everything installed by Daz Connect goes into the "My Daz Connect Library" (I actually named mine Daz Connect Data and put it on drive D.) An example file structure for me is D:\DAZ 3D\Studio\Daz Connect Data\data\cloud\1_23585\runtime\textures\sarsa\peasantmale.

    Post edited by barbult on
  • DaWaterRatDaWaterRat Posts: 2,885

    I haven't tried saving (I also use Daz connect) but I will say - Thank you!!! you are a gentleperson and a scholar!

    Just tested it on a scene that more or less froze my system when I tried to render it in Iray originally.  Now, no problem at all.

    I may actually go back to playing with Iray now. :)

     

  • EsemwyEsemwy Posts: 578

    I haven't tried saving (I also use Daz connect) but I will say - Thank you!!! you are a gentleperson and a scholar!

    Just tested it on a scene that more or less froze my system when I tried to render it in Iray originally.  Now, no problem at all.

    I may actually go back to playing with Iray now. :)

    Glad to hear it! 

  • barbultbarbult Posts: 24,244
    edited December 2016

    Well, I tried it (CTRL click on script) with items installed with Daz Connect. I seemed to work with no error messages. Then I saved the scene with a new name, closed Daz Studio 4.9.3.166 and reopened it. When I loaded the saved scene, it couldn't find any of the texture files that the script had created. I will investigate further...

    Screenshot 2016-12-29 16.22.51.png
    599 x 791 - 43K
    Post edited by barbult on
  • barbultbarbult Posts: 24,244

    When I go back and look in the Daz Connect folder where those reduced fies were created, they are still there. I will need to open a scene file and see if I can figure out why the saved scene file doesn't find them.

  • EsemwyEsemwy Posts: 578
    edited December 2016

    @barbult (or anybody else using Connect) try this version. If it works, I'll replace it in the main post.

     

    Post edited by Esemwy on
  • barbultbarbult Posts: 24,244
    edited December 2016
    barbult said:

    When I go back and look in the Daz Connect folder where those reduced files were created, they are still there. I will need to open a scene file and see if I can figure out why the saved scene file doesn't find them.

    Edit: I see nothing wrong in the Scene file. But, if I open the original scene and try to substitute one of the save reduced files for the original file by browsing in the Surfaces pane, I get an error pop up. Daz Studio/Daz Connect will not allow me to retrieve the reduce file that way. angrysadno

    Screenshot 2016-12-29 16.33.29.png
    506 x 101 - 9K
    Post edited by barbult on
  • EsemwyEsemwy Posts: 578
    barbult said:
    barbult said:

    When I go back and look in the Daz Connect folder where those reduced files were created, they are still there. I will need to open a scene file and see if I can figure out why the saved scene file doesn't find them.

    Edit: I see nothing wrong in the Scene file. But, if I open the original scene and try to substitute one of the save reduced files for the original file by browsing in the Surfaces pane, I get an error pop up. Daz Studio/Daz Connect will not allow me to retrieve the reduce file that way. angrysadno

    Good to know. The above version will use your 2nd (contolled by the constant at the top of the script) Content directory if it detects that the texture is in the Connect directory.

  • barbultbarbult Posts: 24,244
    edited December 2016

    This is the same huge issue I have with saving any material preset  or morph I make for any Daz Connect installed items. I cannot save it with the original files in the Daz Connect folder. I have to create (manually) a parallel folder in another content library and save it there.

    Post edited by barbult on
  • barbultbarbult Posts: 24,244

    Oops just saw your new version. The comments above refer to my attempts with the original version.

  • barbultbarbult Posts: 24,244

    I tried the new script. When I hold CTRL and double click the script, an error pops up telling me to look in the log. This is what I see:

    2016-12-29 16:46:51.176 Loading script: D:/DAZ 3D/Studio/My DIM Library/scripts/esemwy/reduce textures.dsa
    2016-12-29 16:46:54.236 WARNING: Script Error: Line 11
    2016-12-29 16:46:54.236 WARNING: SyntaxError: too few arguments in call to getRelativePath(); candidates are
        getRelativePath(QString,bool)
        getRelativePath(DirectoryTypes,QString)
    2016-12-29 16:46:54.236 WARNING: Stack Trace:
        <anonymous>()@D:/DAZ 3D/Studio/My DIM Library/scripts/esemwy/reduce textures.dsa:11
    2016-12-29 16:46:54.298 Error in script execution: D:/DAZ 3D/Studio/My DIM Library/scripts/esemwy/reduce textures.dsa

     

  • EsemwyEsemwy Posts: 578

    Second attempt at Connect compatibility.

     

    dsa
    dsa
    Reduce Texture.dsa
    3K
  • barbultbarbult Posts: 24,244

    smileyyesheart It Works! This is fantastic! Thank you for the script, and THANK YOU for the extra effort to make it Daz Connect compatible!!!!!!!!!

  • EsemwyEsemwy Posts: 578
    barbult said:

    smileyyesheart It Works! This is fantastic! Thank you for the script, and THANK YOU for the extra effort to make it Daz Connect compatible!!!!!!!!!

    Awesome! You're welcome!

  • SimonJMSimonJM Posts: 5,982
    barbult said:

    When I go back and look in the Daz Connect folder where those reduced fies were created, they are still there. I will need to open a scene file and see if I can figure out why the saved scene file doesn't find them.

    I note it works for you now, but to address your original issue about not finding the textures - using Ctrl made the script save the resized texttures in the DAZ temp diretcory which, when you shut DS down, is cleared out.  So, naturally, when you restart DS they are, indeed, gone!

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

    When I go back and look in the Daz Connect folder where those reduced fies were created, they are still there. I will need to open a scene file and see if I can figure out why the saved scene file doesn't find them.

    I note it works for you now, but to address your original issue about not finding the textures - using Ctrl made the script save the resized texttures in the DAZ temp diretcory which, when you shut DS down, is cleared out.  So, naturally, when you restart DS they are, indeed, gone!

    No, you misunderstood. CTRL stores the images with the originals. When they are stored in Daz Connect directories, DS refuses to reload them. They were not deleted,. They were not in the temp directory.

  • barbultbarbult Posts: 24,244

    I'm getting a bunch of warnings in the log file, even when the script seems to be working. Do I need to be concerned about them?

    2016-12-29 22:55:03.743 WARNING: general\dzcontentmgr.cpp(4341): Content directory index out of range in DzContentMgr::getContentDirectory()

  • EsemwyEsemwy Posts: 578
    barbult said:

    I'm getting a bunch of warnings in the log file, even when the script seems to be working. Do I need to be concerned about them?

    2016-12-29 22:55:03.743 WARNING: general\dzcontentmgr.cpp(4341): Content directory index out of range in DzContentMgr::getContentDirectory()

    Change g_CONTENT_PATH_NUM at the top of the script from 1 to 0. 

Sign In or Register to comment.