Changing the compression format of multiple textures - unity3d

I'm using the following method to compress a bunch of textures:
public void OnPostprocessTexture (Texture2D t) {
EditorUtility.CompressTexture(t, TextureFormat.DXT5, 2);
}
The idea is to try to compress the texture when importing it. I have a project with many textures which are not using an optimal format.
The problem is that these changes are not saved anywhere, if you check the editor you'll see that the format remains the same. I can leave the script there and reimport everything in the build server, but I'd like a way to save these changes.
The only way I can think of this is to create another texture using the format I want and copying/replace the texture. Is there a better way to do this?
Edit
Doing some more tests, I noticed something strange: EditorUtility.CompressTexture is somehow compressing NPOT textures. This is before running the script:
And this is after running EditorUtility.CompressTexture:
How does this work?
While Sergey's answer helps me change the format, it won't compress NPOT textures and I really need to save these bytes.

You have 2 problems here.
Problem 1
You are trying to do it inside OnPostprocessTexture method, which is too late. You need to do it inside OnPreprocessTexture method instead.
Problem 2
EditorUtility.CompressTexture compresses a texture object itself (an object that resides in RAM), not a corresponding asset (an object that resides on disk).
The correct way of doing what you want to do is using TextureImporter.textureFormat.
Solution
Here is a working example:
public void OnPreprocessTexture()
{
TextureImporter textureImporter = assetImporter as TextureImporter;
textureImporter.textureFormat = TextureImporterFormat.DXT5;
}
Answer to comment
Another detail: I don't agree that CompressTexture creates an object in RAM instead of the disk, I think it creates a file inside the Library folder (that at some point is loaded into the RAM).
No, it doesn't create anything inside Library folder. It's quite easy to check:
Start with minimal Unity3D project: only one texture and only one editor script (a descendant of AssetPostprocessor with your OnPostprocessTexture method.
Open Library folder and write down number of files and their size.
Reimport the texture from Unity editor (it will result in execution of your OnPostprocessTexture method).
Open Library folder and see that no files were added and total size of files remains the same (at least this is how it works on my machine).
Answer to edited question
Doing some more tests, I noticed something strange: EditorUtility.CompressTexture is somehow compressing NPOT textures.
If I try to reproduce it, Unity outputs an error line to console: "!hasError".
Despite that Unity editor says that the texture is compressed with DXT5 after such a manipulations, the actual texture format is D3DFMT_A8R8G8B8 when you check it in a plugin.
One thing to note here. Actually, DXT compression doesn't require textures to be of power of two size. It requires them to be of size of multiple of 4. Hope this helps :)

Related

Optimization of the project structure

My project structure looks like the picture
The Code directory has all the code that I am generating.
Is it possible to move everything (except Code) from Assembly-CSharp to another Assembly?
After each small change in the code, it takes a long time to load the project. Can it help?
Let me add that in some classes I use references to these additions.
Actually only code is placed in assemblies. You can however subdivide your code into several assemblies if that would make sense in your project.
This is what Assembly Definition is for. You create it in a folder and from then on every script in that folder and all its subfolders will be part of that separate assembly (unless a sub folder contains another Assembly Definition in which case that part of the hierarchy will become another .dll)
The cause of long pauses after every code modification is a long standing problem with newer versions of Unity (I think 2020+). It is discussed at length here:
Unity Forum
Splitting your code into assemblies may not necessarily help at all!
Unless you have large chunks of code that you hardly ever change.

How do I export Whitewater as VDB from Houdini to use in another program?

I've had great success exporting fire and smoke as VDB to then open in another 3D program, but I keep failing at exporting whitewater as VDB which can successfully be opened in the next program. It imports with the right attributes and dimensions, but nothing is visible within the object, just the boundary box.
I can't seem to find straightforward documentation on how to do it. My steps are to go into "whitewater_import" add a filecache node to the "render" null and save it to the frame range to disk with the proper naming convention.
I'm using Blenders experimental branch New Object Types. But again, I've had no problem with Fire and Smoke sims in this workflow, I think I'm just doing the process wrong for the whitewater.
Thanks for any help!

export blender file and import into scenekit does not work

I tried to do this:
1) import file into blender (worked) -> it is the original file from apples vehicle example rc_car
2) exported it to .dae file (seemed to work, but unfortunately not in a way scenekit understands it properly)
(without any changes)
if i then start again the apple vehicle example, the car isn't visible and "invisible" hopping around
i did set global orientation to y_up and apply global orientation checked in blender when exporting.
what am i missing/making wrong?
p.s. what also is weird is that the dae file inside says:
Z_UP
although in export i defined y_up !?
I tried also other formats like obj, ply, alembic ...with the same result or nodes had other names than in the original.
This post: 56183036 is how I set the initial orientation and scale on my Turbo Squid models. It looks like you've already figured out that downloaded models don't always start with the rotation desired.
At the end there is a command line for setting Y-Up. Blender versions have changed since I did this, so I can't speak to y-up within Blender.
Models can be pretty finicky and some I've downloaded, just don't work after export. I found that trying a very simple model to make sure my math is working first, helps. A few times, my scale or color scheme was just way off and I didn't know it, couldn't see it, etc.
Hope that helps...

Can Doxygen/Graphviz generate a PNG larger than 32766px?

I am trying to generate a doxygen package with one enormous class hierarchy. (It's for QuickFIX, FWIW). No matter what I do, it seems to be capping the height of the image at 32766:
$ file html/inherit__graph__23.png
html/inherit__graph__23.png: PNG image data, 307 x 32766, 8-bit/color RGBA, non-interlaced
It's not clipping; it's scaling. The result is that at only 307px wide, the class boxes are scaled so small that the text inside them is not readable, and the HTML map doesn't work, either.
Neither the dot nor the doxygen documentation mention this limit, though it seems clear something is doing it, and I can't find any directives to override it. (And yes, I realize an image that big has its own problems in browsers, but I'll deal with that later.) That number seems suspicious due to its proximity to 2^15, and I believe PNG uses a 32-bit size field, so something bigger should be possible.
Anyone know where that limit is coming from and how to bypass it?
Edited to add: doxygen version = 1.6.1, graphviz = 2.26.0. Maybe too old?
Looks like I'm screwed. The 32K limit is imposed by cairo, which is what graphviz uses underneath the hood to render PNG.
Reference: http://comments.gmane.org/gmane.comp.lib.cairo/21068
Unfortunately, you're correct. It's too old; you're not going to be able to exceed that limit unless you manage to upgrade to a newer version.

How to repair Simulink SLX file?

One of my Simulink SLX files has stopped opening as a model. Apparently it was corrupted. Are there any means to repair such a files or extract some information of them? File looks like being a MZ executable. Where is the block schema stored?
SLX is a compressed file which contains XML files with model information. You can try opening the SLX file in winzip and check. See http://www.mathworks.com/help/simulink/ug/saving-a-model.html#btbr7kx-1 for SLX format. I do not think there is any utility to repair corrupted SLX files.
DiffPlug's Simulink Viewer has an .slx parser that was developed independent of The Mathworks, and it's a little more "lenient" than The Mathworks' implementation. You might want to try opening your model in DiffPlug's viewer (it's free, so you don't have much to lose I guess...).
That way you'll at least be able to scout around the model so you can see what piece has been corrupted.
Disclaimer: I work for DiffPlug.
If there's a lot of time invested in the model, I'd be happy to open your model up and poke around inside it using our internal API. It'd only take me a few minutes, and it might be an easy fix like a mis-matched Stateflow id.
Remove the extension 'original' from the file name 'X.slx.original'. This worked for me.
You can actually still load the system using load_system(), use bdroot to see if it loaded, then use save_system() to save what is returned by bdroot, using a new filename. The new model should open correctly.