Search Unity

Mesh compression - what does it actually do?

Discussion in 'Editor & General Support' started by monark, Oct 29, 2009.

  1. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    So the help doesn't go into any details, what does the new mesh compression actually do? Does it remove geometry or just reduce the numerical accuracy of the stored points? or something else entirely.
     
  2. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Mesh compression will just reduce the numerical accuracy of the mesh. Instead of 32-bit floats, lower size (exact size depending on value type and compression quality) fixed number will be used to represent mesh data.
     
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    is that really all to it?
    I ask because foliage thats compressed will totally lose their AO capabilities even with low compression, as if normal / tangents were completely cut (tested with the palm to ensure its not my own model going bogus).

    Or would it require to be reimported after compression?
     
  4. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    I wonder if this is related, the only place I get any artifacts is in large flat areas that are made of a number of triangles. The geometry looks fine but I get shading errors where I assume the normals are getting messed up. You sort of see dark and light patches where the shading should be continuous and uniform.
     
  5. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Yes, changing compression settings requires reimporting the model. Also (in case you haven't noticed), there is now an option to disable tangents and normals for your model - the "Tangent Space" popup. You didn't disable them by any chance?
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    No, didn't disable them. Doing this kind of optimization that I leave out unless I'm forced to include them (or when doing something where they are just of no use which is kind of only the case for UI and 2D)

    Will check the reimport.
     
  7. Mchasse

    Mchasse

    Joined:
    Jul 12, 2012
    Posts:
    5
    Is there a way for unity to delete UV channel or Vertex color info on meshes on import, for example through an editor script running on preprocess?
     
  8. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    I think setting a null or empty array as mesh component data should work.

    However, since Unity 3.5.3 there's also an option in Player Settings to remove any mesh components that aren't used by any of the shaders. So that "removal of unneeded mesh data" is largely automatic with this option.
     
  9. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Sorry for this bump, but I feel like this is an important question that I can't find an answer to anywhere.

    Is there anyway to do this on a mesh created/copied as an asset, without being "imported". I can't find any information about being able to add mesh compression on a post-imported mesh.

    Thanks for any insight!
     
  10. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Currently, no. I agree that it would be useful, though. Maybe add a feature request on feedback.unity3d.com?
     
  11. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Ok, I will add a feature request.

    So there is absolutely there is no way I can do this manually right now, even if it's not a built in editor procedure I can access?
     
  12. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    225
    I know this is an old thread but I think is better to keep the same questions on a single post so...

    The mesh compression reduces the memory it uses by lowering numerical accuracy but has this any effect on rendering power consumption?
     
  13. goldbug

    goldbug

    Joined:
    Oct 12, 2011
    Posts:
    768
    What about animations? Is there a way to compress animation clips created in unity?
     
  14. TijnTje

    TijnTje

    Joined:
    Oct 14, 2013
    Posts:
    1
    Here is what you could do to compress the mesh on importing, this is an editor script:
    Code (csharp):
    1. using System;
    2. using UnityEditor;
    3.  
    4. /// <summary>
    5. /// Class that hooks into the model importer
    6. /// </summary>
    7. public class ModelImporterProcessor : AssetPostprocessor
    8. {
    9.    /// <summary>
    10.    /// Preprocess method that gets called by the editor when importing a model
    11.    /// </summary>
    12.    public void OnPreprocessModel()
    13.    {
    14.      // Get the model importer
    15.      ModelImporter modelImporter = (ModelImporter)this.assetImporter;
    16.  
    17.      // Change settings
    18.      modelImporter.meshCompression = ModelImporterMeshCompression.High;
    19.    }
    20. }
    Reference: http://docs.unity3d.com/ScriptReference/AssetPostprocessor.html

    You have to reimport all your assets to make use of this script.
    You could also change other model import settings in here ;-)
     
    radiantboy and CMcN like this.
  15. KuangZheng

    KuangZheng

    Joined:
    Feb 25, 2013
    Posts:
    75
    Still no idea about compressing mesh that generates by script in Unity?
     
  16. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    Actually, this is solved now in Unity 5:

    Code (csharp):
    1.  
    2. MeshUtility.SetMeshCompression (myMesh, ModelImporterMeshCompression.High);
    3.  
     
    forestrf likes this.
  17. shadab_badar

    shadab_badar

    Joined:
    Aug 2, 2013
    Posts:
    3

    Once I was trying to use a 3d model which was of 3.5 mb , as it was a big size I started exploring forums to reduce it .
    Somewhere I came to know that mesh compression will help in this case and when I change the mesh compression from off to high the used size shown in editor log was just 1.2 mb.
    It worked fine for me when I was working with android but when I switched the platform from android to windows.the texture of that model started behaving abnormally.
    So can u please tell me whats the solution for windows.(Didnt tried it for IOS)