Search Unity

Cruncher - Polygon Reduction Plugin for Unity Pro

Discussion in 'Assets and Asset Store' started by bibbinator, Sep 4, 2012.

  1. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    Here is an example that I have given to others as a guide to how to use the API.

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. //#define LOG_TRACE_INFO
    3. //#define LOG_EXTRA_INFO
    4.  
    5. using UnityEngine;
    6. using System.Collections;
    7.  
    8. //------------------------------------------------------------------------------
    9. // class definition
    10. //------------------------------------------------------------------------------
    11. [ExecuteInEditMode]
    12. public class CruncherApiController : MonoBehaviour
    13. {
    14.     public float quality = 1.0f;
    15.     private float savedQuality;
    16.  
    17.     //--------------------------------------------------------------------------
    18.     // protected mono methods
    19.     //--------------------------------------------------------------------------
    20.     protected void Awake()
    21.     {
    22.     }
    23.    
    24.     protected void Start()
    25.     {
    26.     }
    27.    
    28.     protected void Update()
    29.     {
    30.         if(quality != savedQuality)
    31.         {
    32.             quality = Mathf.Clamp01(quality);
    33.             ReduceMesh();
    34.             savedQuality = quality;
    35.         }
    36.     }
    37.    
    38.     //--------------------------------------------------------------------------
    39.     // private methods
    40.     //--------------------------------------------------------------------------
    41.     private void ReduceMesh()
    42.     {
    43.         MeshFilter meshFilter = gameObject.GetComponent<MeshFilter>();
    44.         if (meshFilter != null)
    45.         {
    46.             if(CruncherPluginManager.Startup() == false)
    47.             {
    48.                 return;
    49.             }
    50.  
    51.             CruncherIO cruncherIO = new CruncherIO();
    52.             cruncherIO.vertices = meshFilter.sharedMesh.vertices;
    53.             cruncherIO.triangles = meshFilter.sharedMesh.triangles;
    54.             cruncherIO.normals = meshFilter.sharedMesh.normals;
    55.             cruncherIO.subMeshTriangles = new int[meshFilter.sharedMesh.subMeshCount][];
    56.             for(int i = 0; i < cruncherIO.subMeshTriangles.Length; i++)
    57.             {
    58.                 cruncherIO.subMeshTriangles[i] = meshFilter.sharedMesh.GetTriangles(i);
    59.             }
    60.  
    61.             CruncherMeshConfiguration meshConfiguration = new CruncherMeshConfiguration();
    62.             meshConfiguration.joinVertices = true;
    63.             meshConfiguration.joinNormals = true;
    64.             meshConfiguration.recalculateNormals = true;
    65.             meshConfiguration.removeTJunctions = true;
    66.             meshConfiguration.joinUvs = true;
    67.  
    68.             int meshId = CruncherPluginManager.AddMesh(cruncherIO, meshConfiguration);
    69.  
    70.             CruncherAdjustment cruncherAdjustment = new CruncherAdjustment();
    71.             cruncherAdjustment.type = CruncherAdjustment.Type.TargetQuality;
    72.             cruncherAdjustment.quality = quality;
    73.             bool crunched = CruncherPluginManager.AdjustMeshes(cruncherAdjustment);
    74.             if (crunched)
    75.             {
    76.                 cruncherIO = CruncherPluginManager.RetrieveMesh(meshId, true, false);
    77.                 Debug.Log(gameObject.name + " with quality " + quality + " yields a mesh with " + cruncherIO.vertices.Length + " vertices.");
    78.             }
    79.             CruncherPluginManager.Shutdown();
    80.         }
    81.     }
    82. }
    83. #endif // UNITY_EDITOR
     
  2. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Hi,

    After putting the latest version of Cruncher back into my project, I'm finding it now fails validation during the upload process to iTunes Connect (iOS build). I believe that looking at the logs, the issues relate to Cruncher. Is there some way to exclude the Cruncher libraries from being part of the build from Unity?
     
  3. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    Hi Rajmahal

    Sorry you're having issues. Which version of Cruncher are you using? Which version of Unity?

    If you're using Unity 5, click on the plugin files and be sure that the properties are properly configured for editor-only and all should be stripped from the builds. In all cases the code is wrapped by editor only defines and should be stripped.
     
  4. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    I am trying to find a good workflow for optimising 4x 64k mesh terrain tiles. The verts on each edge where the tiles meet all match seamlessly.

    What I would like to do is reduce the number of triangles on each mesh while keeping the edge verts identical where the tiles meet. Currently when I select all 4 meshes and crunch them I can reduce the triangles no problem but then the edges don't align and there are very visible seams where they meet.

    The only solution I've found so far is exporting them out as a .obj and then importing into blender. I can then join the meshes, weld the edge verts and decimate before bringing it back into Unity.

    Is there any way Cruncher could do this within Unity itself, matching the edge verts on each adjacent mesh?

    Edit - also to add I have found Mesh Materializer is very useful as it can convert any number of terrain meshes e.g. 2x2 into 64k (max size) meshes that look very good. I'm just looking for a way to then optimise all these meshes while still keeing their edges aligned without any seams.
     
    Last edited: May 7, 2015
  5. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    @radimoto

    What you want can be done already in Cruncher, but you'll have to write a script and use the Cruncher API to do what you want. See the API.rtf doc that comes with Cruncher. You need to populate the "lockedVertices" array with the edge vertices of your terrain tiles. Then they should line up. I don't ship Cruncher with examples and past experience shows it takes a day or two to get something working using the API. So if you want to go this route, create a new test project with a simple tessellated plane and learn how to use the Cruncher API in a simple test. Then use that code as the basis for solving your use-case. Otherwise you'll get bogged down in thousand of vertices and geometry and not quite understand what's happening or why it's not working, etc.

    Note that this method though will mean that the overall mesh reduction will be less because it will maintain the vertices at full complexity at the edges.

    Good luck!
    Brett
     
  6. radimoto

    radimoto

    Joined:
    Aug 23, 2012
    Posts:
    257
    Can I please request for multi aligned mesh reduction to be added to Cruncher? Basically where Cruncher detects any matching verts in the selected Meshes and presents an option to lock them preventing any seams to be misaligned.

    I am aware you have an API for this but given the high cost of this Asset I believe this feature should really be built into the product. Thanks!

    Edit - I have one other feature suggestion - add a vert selection tool (box, circle, paint select) so that you can add verts to be locked for crunching. This could be used to ensure high detail remains in places on the mesh.
     
    Last edited: May 9, 2015
  7. Incendiary-Games

    Incendiary-Games

    Joined:
    Mar 24, 2015
    Posts:
    18
  8. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    @radimoto

    Your feature suggestion for ability to select vertices is already on my list, but given how much work it would take to implement, I haven't gotten around to it. Auto detecting vertices within a tolerance for sub-meshes and locking those might work and be much easier. I can't promise when I can get to it though. Crazy busy these days.

    @Incendiary Games

    No idea. Cruncher works on asset meshes, but given it's a 3rd party tool and a brief look at it I'm not sure if the data is stored in the same way Cruncher expects it. In this case the only solution would be to buy Cruncher and if it doesn't work ask for a refund (which Unity does without issue). Sorry, wish I could say for certain.
     
  9. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    439
    If I try to import in 64-bit Unity 5.0.3f2, I get errors between the BalancerSDK.dll and BalancerSDK64.dll (somewhat same kind what's quoted below). If I try to import without BalancerSDK.dll, then I get these confusing errors:

    If I try to import without BalancerSDK64.dll, then I only get this error: (This error also pops when trying to Play the scene.)

    When trying to actually use Cruncher with some model prefab, I get these errors:
    (the last one keeps repeating again and again to console)
     
  10. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    439
    Adding to previous one, I'm also getting this as the first error when importing
    I noticed importing to empty project works ok with nothing else in Plugins. When I had other stuff in Plugins as well, it wouldn't work... so, I'm not 100% sure what exactly helped, but I removed some stuff from Plugins which I didn't need (mac specific bundle folders and android/linux specific files), plus I moved the cruncher dlls to x86 and x86_64 under Plugins which were added by the Oculus SDK.

    So seems to work now. I guess it's mostly about those x86 and x86_64 folders - if they are present, maybe Unity gets confused with the dlls in the top level of Plugins/ ...?
     
  11. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    439
    Sorry that was a false positive. It partially seemed to worked once or so, but I still get those same problems. And it does not seem to be about the x86 and x86_64 folders like I suspected.

    BUT I am not getting the same stuff in an isolated emptier project. So if you have any ideas how to fix this issue, I'd still be glad to hear.
     
  12. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    @tonic Sorry to hear you're having problems, not something I have heard or seen before.

    I need some more info to understand:

    1. Did you already have Cruncher installed and upgraded it? Or you upgraded your project from Unity 4 but not Cruncher? Or? Any details on the configuration would be helpful.

    2. Which version of Cruncher are you using?

    Thanks,
    Brett
     
  13. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    I just tried Unity 5.1.0f3, imported Cruncher from the Asset Store, and everything is working fine. Hopefully once I get more info from you we can figure it out.
     
  14. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    439
    Hi @bibbinator. The project was created using Unity 5.0.2 and now I'm using 5.0.3 with it, and cruncher was imported directly to the project. It seems there's something wrong or incompatible in that project with Cruncher (I think the only larger extra sdk is the Oculus VR SDK v.0.6.0 beta, but I'm not sure if it can cause those problems..?)
    The Cruncher about dialog shows it is version 2.0 (64-bit) - in the temp project described below.

    But for now I found a workaround:
    I was able to import and work with Cruncher in a new separate temp project (with same Unity version), so I copied the original models to that temp project and worked there (in combination with mesh materializer after working with cruncher). Finally I manually removed the Simple Cruncher Target components from the generated models and was able to copy&export all the final resulting stuff to my original project.

    So I don't have any urgent problems anymore. However, here's bit of info about issues I still faced in case it might help you to do other improvements:

    I did have a bit of problems with some complex models, with Cruncher reporting "Plugin operation failed, aborting." whenever trying to change the optimization settings (and telling to check out the plugin log file). For such a case it was still able to make some sort of "best effort" optimized model though - the Target component just seemed to report partly erroneous data.
    One example: In the log file I saw "WARNING: Mesh can only be reduced to 65510 vertices and 28409 triangles."
    In this case the Target component is showing 46365/84212 vertices and 28409/85069 triangles, with the Modifications->Quantity pre-set automatically to 82958 (I was modifying the Quality setting myself). And when checking the actual mesh from Mesh Filter, it shows there's 46365 verts, 28409 tris and 53 submeshes (the original also had 53 submeshes, each having its own material as well... after Cruncher I reduced the amount of materials with another asset).

    Also, my source 3D models were part of single big FBX input file, which had many models (or groups of models) under it. When working with this, Cruncher added a single Cruncher Root component to the top object, and Simple Cruncher Target component to each model in the large imported hierarchy. When I was done working with cruncher, I had to manually go through each model to remove the Simple Cruncher Target component, so that I could have a final optimized object to copy back to the original project. I wished there would have been easier way to "clear" any sign of cruncher from the final objects than manually doing it for each one like this. Perhaps you could add some feature to help this kind of workflow where the optimization is not left as persistent part of the project but only a single pass done after initial import of models.
     
  15. ventureblocks

    ventureblocks

    Joined:
    Sep 1, 2013
    Posts:
    5
    I have few questions about Cruncher before I purchase:

    Does Cruncher maintain any blendshapes that are in a mesh?
    Does Cruncher allow me to save a decimated mesh separately (so that I don't need to bundle the original mesh with my project?)
    If I have an FBX with several meshes in it, does cruncher allow me to separately decimate each mesh?

    Thanks!
     
  16. Rainking

    Rainking

    Joined:
    Jun 10, 2013
    Posts:
    41
    Hi, the plugin looks great!
    ...but I can not get it to work because I see the error in installation:
    Error importing folder (The pathName assets/plugins is already mapped to xxxx. But the meta data wants it to be mapped to xxxxxx)

    How can i contact your support? did not found anything on your website...

    my unity pro version: 5.1.1f1
    It was a new installation of cruncher (no upgrade)

    kind regards,
    Tino
     
  17. Rainking

    Rainking

    Joined:
    Jun 10, 2013
    Posts:
    41
    its working now, I dont know why... I tried a lot of stuff. cannot tell what fixed it...
     
  18. SchnauzerCorp

    SchnauzerCorp

    Joined:
    Oct 1, 2014
    Posts:
    7
    Purchased earlier today, mostly impressed so far. Certainly a huge time-save over manually creating LODs.

    The way I generally work in Unity (5.1) is to import .fbx files that contain multiple sub-meshes & then create prefabs out of these. It's the prefabs that I'm wanting to create LODs for.

    When I use Cruncher on these I'm seeing that it creates new sub-meshes for each of the reduction levels; but they all have the same name, which makes finding the correct one to insert into a LODgroup a bit tricky, and also if I try and iterate on the quality settings of the different settings Unity seems to jumble up which mesh gets loaded. It would be nice if these newly createed sub-meshes repsected the suffix setting, is this possible? Or perhaps you could recommend a slight change in my work flow to get the desired behaviour?


    I also discovered a situation where editing the quality level made it then impossible for me to generate a mesh of quality higher than that, even though it was at rather a low setting. Bug or user error?
     
  19. SchnauzerCorp

    SchnauzerCorp

    Joined:
    Oct 1, 2014
    Posts:
    7
    Another issue I'm facing is that on some meshes Cruncher just doesn't seem to do much : Even if I reduce the quality level to 0 I'll be left with ~90% of my starting polycount.
     
  20. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    Yikes, sorry all. I didn't get any notifications about the posts. So sorry for that. Looks like everything is sorted out, I emailed @ngwilliams directly.

    If you have any problems I can always be contacted at support@realworldunity.com

    Thanks!
     
  21. ev3d

    ev3d

    Joined:
    Apr 19, 2013
    Posts:
    327
    I emailed last week and have not gotten a response.. need help ASAP
     
  22. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    Was at Oculus Connect last week, just got back. Will take a look this week. Sorry for delay.
     
  23. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    @ev3d

    Actually I emailed you promptly the same day you sent me the email with a list of suggestions to try to find the cause of your problem and you never replied. I resent you the questions. Basically I think your plugin settings in Unity 5 are not correct and you need to specify editor only for them.
     
  24. StealThePixels

    StealThePixels

    Joined:
    Apr 2, 2015
    Posts:
    68
    Hi,
    do the LODs generated by Cruncher work with static and dynamic batching (expecially static), in order to get the benefits of both the LOD and batching together for maximum optimization ?

    If not, i will opt for just static&dynamic batching without LODs, i got a good result on PC in this way.
    For the mobile version of my game i want to follow the same approach as PC but using lower-resolution meshes.
    So i would want to use Cruncher to reduce poly count BUT the game will not use LODs , i want just to replace all the original meshes with low-poly versions of them.
    Can Cruncher do this, or will it force the game to use LODs in any case?
     
  25. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    I maintain the material list exactly as it is, and lower polygon counts allows for better batching because there is a limit on triangles/verts per batch in Unity. So in all cases Crunched models should work as well or better than non-Crunched ones.
     
  26. unityB

    unityB

    Joined:
    Oct 28, 2015
    Posts:
    4
    I'd like to poke this item, I am very interested in saving the mesh out in the build and not have it computed at runtime. This would be my tipping point for purchasing this plugin.
     
  27. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    @unityB The mesh isn't computed at runtime, Cruncher is only an editor-time tool that creates new decimated meshes. As long as you don't link the mesh in some other way, the original mesh shouldn't be included in the build
     
  28. unityB

    unityB

    Joined:
    Oct 28, 2015
    Posts:
    4
    Thanks @bibbinator for the fast response. I have V2.0 (x64) of the plugin on Unity 5.2 and I am unable to get it to create more than 1 lod (LOD0). The error message I get is:
    ----------------------------------------------
    IndexOutOfRangeException: Array index is out of range.
    CruncherEditorPlugin.CruncherConverterWindow.UpdateConversion ()
    CruncherEditorPlugin.CruncherConverterWindow.OnInspectorUpdate ()
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.HostView.Invoke (System.String methodName, System.Object obj)
    UnityEditor.HostView.Invoke (System.String methodName)
    UnityEditor.HostView.OnInspectorUpdate ()
    ------------------------------------------------

    this even happens even when I use the Dinosuar prefeab.

    Any ideas?
     
  29. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    @unityB

    Yes, create multiple LODs by clicking on the asset in the project window, not on an object in the scene. It's an annoying "bug" whereby I should disable multiple LODs from being created if selecting a scene asset (because after the first one is converted there is no source mesh available).
     
  30. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    575
    how can i ask for a refund regarding the cruncher unity asset
     
  31. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    You request from Asset Store, they follow up with me. Let me know if you have any problems!
     
  32. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    575
    is there a especific email soo that i can email the refund request please
     
  33. bibbinator

    bibbinator

    Joined:
    Nov 20, 2009
    Posts:
    507
    Send me a private message with your order number and I will ask them to refund you.
     
  34. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    575
    Sure thing! Thank you!
     
  35. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    575
    i also tryed other refunds regarding unity store packages. The refund responsability is from the unity store or from the author, since many authors refused to refund me.
     
  36. unityB

    unityB

    Joined:
    Oct 28, 2015
    Posts:
    4
    Thanks dude, working well now.
     
  37. TheJimz

    TheJimz

    Joined:
    Jun 26, 2015
    Posts:
    50
    I'll give another poke, a year later because I'd like these answers as well. From my experience so far however, cruncher does not support blend shapes which doesn't allow my team to use it.
     
  38. julianr

    julianr

    Joined:
    Jun 5, 2014
    Posts:
    1,212
    really sad that this asset is no longer supported. it doesn't work 100% with Unity 2017.x. The only way I can use it is if I install an old version of Unity and crunch assets before moving them over which is such a time consuming exercise and defeats the objective of saving time.

    In the end I purchased another asset called SimpleLOD it does the same, but doesn't have that editor visual aspect where you can change things on the fly to see the results.
     
    Last edited: Feb 21, 2018
    halcyonideals, ibyte and milox777 like this.