Search Unity

SpriteSharp - Sprite Mesh Optimizer

Discussion in 'Assets and Asset Store' started by ZimM, May 24, 2015.

  1. deemen

    deemen

    Joined:
    Dec 29, 2013
    Posts:
    17
    @ZimM: SpriteSharp currently isn't playing nice with the Unity Package Manager. When loading a project for the first time with packages being included, your texture pre-processor is trying to modify and re-import assets that are in packages. These assets are read-only and can't be modified so Unity enters an infinite loop and continues trying to reload the asset in a loop. We fixed this on one of our own texture pre-processors by adding a check that the path contained "Assets" at the start.

    Also, the sprite atlas hack changes the userData field but it would be nice if it didn't stomp what was already in there as we use it for something else.
     
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    TBH I would say it's PM not playing nice with everything else. PM causes huge lag entering playmode and does a bunch of stuff it really shouldn't be doing atm.
     
  3. deemen

    deemen

    Joined:
    Dec 29, 2013
    Posts:
    17
    Yeah I don't disagree.
     
  4. HoneyButterAlmond

    HoneyButterAlmond

    Joined:
    Oct 27, 2016
    Posts:
    6
    SpriteSharp v2.5.0
    Unity 2019.1.3f1

    'Use Default Override Settings' is not working when add new sprite asset.
    It only worked with 'reimport'.

    The problem is SpriteImportManager.ProcessSingleSprite
    TextureImporter textureImporter = texture.GetTextureImporter();

    textureImporter is always null.

    So, I added next code to SpriteImportPostProcessorImpl.OnPostprocessSprites
    and using as parameter.
    TextureImporter textureImporter = (TextureImporter) postprocessor.assetImporter;
     
    Last edited: Jun 12, 2019
  5. TimNedvyga

    TimNedvyga

    Joined:
    May 18, 2015
    Posts:
    95
    SpriteSharp 2.5.1.0 not working with Unity 2019.3.0b3
     
  6. piotrlipert

    piotrlipert

    Joined:
    Jun 23, 2015
    Posts:
    4
    Bumping up TimNedvyga, SpriteSharp not working with Unity 2019.3.0b3

    Code (CSharp):
    1.  
    2. System.NullReferenceException: Object reference not set to an instance of an object
    3.   at LostPolygon.SpriteSharp.Utility.BuildPlatformsUtility..cctor () [0x001cb] in <48b0d871d4244170b9e4ba7f4e597991>:0
    4. 0x00007FF6B0B135EC (Unity) StackWalker::GetCurrentCallstack
    5. 0x00007FF6B0B16A51 (Unity) StackWalker::ShowCallstack
    6. 0x00007FF6AF28D555 (Unity) GetStacktrace
    7. 0x00007FF6B179F390 (Unity) DebugStringToFile
    8. 0x00007FF6B0B7A825 (Unity) DebugLogHandler_CUSTOM_Internal_Log
    9. 0x000001A4ACD3817B (Mono JIT Code) (wrapper managed-to-native) UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
    10. 0x000001A4ACD37D8B (Mono JIT Code) UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
    11. 0x000001A4ACD2908E (Mono JIT Code) UnityEngine.Logger:Log (UnityEngine.LogType,object)
    12. 0x000001A4ACD2865A (Mono JIT Code) UnityEngine.Debug:LogError (object)
    13. 0x000001A4ACCFC1A3 (Mono JIT Code) UnityEditor.EditorAssemblies:processInitializeOnLoadAttributes (System.Type[])
    14. 0x000001A4C27ED3EB (Mono JIT Code) (wrapper runtime-invoke) <Module>:runtime_invoke_void_object (object,intptr,intptr,intptr)
    15. 0x00007FF85C23C8B0 (mono-2.0-bdwgc) [mini-runtime.c:2809] mono_jit_runtime_invoke
    16. 0x00007FF85C1C1DA2 (mono-2.0-bdwgc) [object.c:2921] do_runtime_invoke
    17. 0x00007FF85C1CAD9F (mono-2.0-bdwgc) [object.c:2968] mono_runtime_invoke
    18. 0x00007FF6B0A9556E (Unity) scripting_method_invoke
    19. 0x00007FF6B0A8F24D (Unity) ScriptingInvocation::Invoke
    20. 0x00007FF6B0A89225 (Unity) ScriptingInvocation::Invoke<void>
    21. 0x00007FF6ADEFF9F5 (Unity) Scripting::UnityEditor::EditorAssembliesProxy::processInitializeOnLoadAttributes
    22. 0x00007FF6B0A62883 (Unity) MonoManager::SetupLoadedEditorAssemblies
    23. 0x00007FF6B0A5A664 (Unity) MonoManager::EndReloadAssembly
    24. 0x00007FF6B0A60DB7 (Unity) MonoManager::ReloadAssembly
    25. 0x00007FF6AEF18823 (Unity) ReloadAllUsedAssemblies
    26. 0x00007FF6AEEF6B90 (Unity) EditorSceneManager::RestoreSceneBackups
    27. 0x00007FF6AE96DC54 (Unity) PlayerLoopController::EnterPlayMode
    28. 0x00007FF6AE97FC94 (Unity) PlayerLoopController::SetIsPlaying
    29. 0x00007FF6AE982B1F (Unity) Application::TickTimer
    30. 0x00007FF6AF2B3CF0 (Unity) MainMessageLoop
    31. 0x00007FF6AF2BD9FA (Unity) WinMain
    32. 0x00007FF6B223F922 (Unity) __scrt_common_main_seh
    33. 0x00007FF8B8194034 (KERNEL32) BaseThreadInitThunk
    34. 0x00007FF8B87D3691 (ntdll) RtlUserThreadStart
     
  7. TimNedvyga

    TimNedvyga

    Joined:
    May 18, 2015
    Posts:
    95
    @ZimM Hey, any news about 2019.3 update? Or you are waiting for stable release?
     
    flankey and NeatWolf like this.
  8. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    The author does not seem to be active on all visible communication channel since last year. Fortunately he included the source files in the package.
     
  9. HoneyButterAlmond

    HoneyButterAlmond

    Joined:
    Oct 27, 2016
    Posts:
    6
    I fixed a bug. Use Asset Pipeline v1(legacy) and edit source code null exception.
    Here is screenshot. sprite_sharp.JPG
     
  10. TimNedvyga

    TimNedvyga

    Joined:
    May 18, 2015
    Posts:
    95
    How did you deal with null exception?
     
  11. HoneyButterAlmond

    HoneyButterAlmond

    Joined:
    Oct 27, 2016
    Posts:
    6
    @TimNedvyga Edit 'BuildPlatformsUtility.cs' like this. It's just simple reflection.
    edit.JPG
     
    cwennchen, Zeitcatcher and TimNedvyga like this.
  12. TimNedvyga

    TimNedvyga

    Joined:
    May 18, 2015
    Posts:
    95
    Nice, it works :)
    It remains to find a fix for Asset Pipeline v2
     
  13. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    131
    May I ask where do you find the BuildPlatformsUtility.cs? I am unable to locate it within my project files
     
  14. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    1. Remove DLL
    SpriteSharp/Editor/LostPolygon.SpriteSharp.dll

    2. Import Unity Package
    SpriteSharp/SpriteSharpSource.unitypackage

    3. Find 'BuildPlatformsUtility' in Project Window
     
  15. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    131
    Ahh Thank you!
     
  16. Gregoire_Seguin

    Gregoire_Seguin

    Joined:
    Oct 8, 2018
    Posts:
    2
    SpriteSharp 2.5.1.0
    Unity 2018.4.14f1

    Hey,
    I recently bought the SpriteSharp tools, and it works as fine, generating sprite and exporting them it's perfect. Thanks a lot for the Dev and the community for improving the tools.
    But in the console, I have some errors (and I'm not a programmer, either tech artist), I tried the answer of everyone heres, but still had errors.
    If you have a suggestion, I'm here ;)
     
  17. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    Guys, i think Zim has abandoned this asset. The last time he was online was in Oct 28, 2019

    I used this asset and it was great, but now Unity has a build in Tool that accomplishes overdraw reduction on sprites and since some time these sprites can even be used on UI-objects, hurray!

    sprite.gif
     
    Walter_Hulsebos likes this.
  18. Gregoire_Seguin

    Gregoire_Seguin

    Joined:
    Oct 8, 2018
    Posts:
    2
    SpriteSharp is very usefull, and Unity can't create sprite with this kind of details. Here for exemple, you can create a sprite with Opaque surface and keep the sprites border in Alpha. And one more thing, you can export the generate sprites mesh into a seprate mesh and material.
     
  19. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    613
    Then i am wrong! Where is ZimM? We need Updates :D
     
    Gregoire_Seguin likes this.
  20. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Just picked this up from the Asset Store, unfortunate to see that the dev is MIA. Hopefully will return and support it.... Thanks to those with tips on how to hack it for now.
     
  21. TimNedvyga

    TimNedvyga

    Joined:
    May 18, 2015
    Posts:
    95
    I got in touch with him on Facebook. He said that the update is coming. So cross your fingers, guys :)
     
    Glaswyll and rxmarccall like this.
  22. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    131
    Awesome! Can't wait for the update to arrive! :)
     
  23. MacroPinch

    MacroPinch

    Joined:
    Dec 6, 2013
    Posts:
    43
    Did he provide any update when he is expecting to update it?
     
  24. TimNedvyga

    TimNedvyga

    Joined:
    May 18, 2015
    Posts:
    95
    Nah, I no longer heard from him since then :(
     
  25. MacroPinch

    MacroPinch

    Joined:
    Dec 6, 2013
    Posts:
    43
    I tried fixing the bug myself, but the behavior of the asset database APIs has changed in AssetDatabase v2 in a way that's incompatible with the plugin's internals. I've asked, whether the new behavior of the APIs is intended or it might be a bug, but nobody from unity has answered yet. There's no information in the API docs. Here's the thread:

    https://forum.unity.com/threads/ass...n-results-during-onpostprocesssprites.879541/
     
  26. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    upload_2020-6-23_21-38-3.png

    ZimM was last seen: Jun 15, 2020...
     
  27. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Darn it... I have asked for a refund but I highly doubt the author will respond to my email. I will be very surprised to actually get a refund.
     
    Last edited: Sep 3, 2020
    HoneyButterAlmond and Klausology like this.
  28. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    I gave up. I'm making something like spritesharp. It's open source.
    I will release it within this year.

    test.jpg
     
    Glaswyll likes this.
  29. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    131
    Wow Nice! Am looking forward to this!
     
    Seromu likes this.
  30. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
  31. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    131
    Wow! I will definitely be trying your Unity-SpriteAssist asset!! :)

    EDIT: Just tried it out, it is working in new unity versions perfectly!

    showcase.png
    Left: Unity original sprite mesh. Right: SpriteAssist asset
     
    Last edited: Oct 30, 2020
    Seromu likes this.
  32. Glaswyll

    Glaswyll

    Joined:
    Feb 13, 2014
    Posts:
    103
    Hey @Seromu thank you for making this! It works great! Do you have any plans for adding this to the Asset Store?

    I have a feature request: Would you be able to add a "grid" mesh type where we can vary the mesh resolution? I have some vertex animation features in my shader, and would like to make use of them, while still keeping the sprite atlas intact, and not have to make a new material for a traditional mesh.

    If you don't have plans to release on the Asset Store, do you have a PayPal or something? I would like to express tangible thanks.
     
  33. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    @Klausology @Glaswyll
    Thank you for your feedback.

    I want to release this to the Asset Store too.
    (Maybe within this year?)

    Grid mesh... I will try this :)

    I have no Paypal account.
    Sorry.
     
    Glaswyll likes this.
  34. Klausology

    Klausology

    Joined:
    Aug 29, 2017
    Posts:
    131
    I agree with @Glaswyll, I would want to buy your asset in the asset store too!
     
  35. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    Unity-SpriteAssist is always free :)
    On the Asset Store too.
     
  36. Aurigan

    Aurigan

    Joined:
    Jun 30, 2013
    Posts:
    291
    This is a ridiculously helpful asset. I needed normals for lightmapping so added them, only somewhat sure I did it right, LMK if not ;)

    Code (CSharp):
    1.         public static void UpdateMesh(this Sprite sprite, ref Mesh mesh, Vector2[] v, ushort[] t)
    2.         {
    3.             Vector2[] uv = new Vector2[v.Length];
    4.  
    5.             for (var i = 0; i < uv.Length; i++)
    6.             {
    7.                 uv[i] = v[i] * sprite.pixelsPerUnit + sprite.pivot;
    8.                 uv[i].x /= sprite.texture.width;
    9.                 uv[i].y /= sprite.texture.height;
    10.             }
    11.          
    12.             Vector3[] normals = new Vector3[v.Length];
    13.             for (var i = 0; i < normals.Length; i++)
    14.             {
    15.                 normals[i] = Vector3.back;
    16.             }
    17.          
    18.             mesh.Clear();
    19.             mesh.SetVertices(Array.ConvertAll(v, i => (Vector3)i));
    20.             mesh.SetUVs(0, uv);
    21.             mesh.SetNormals(normals);
    22.             mesh.SetTriangles(Array.ConvertAll(t, i => (int)i), 0);
    23.         }
    Please at least provide a Paypal address so we can send you beer money!
     
    Seromu likes this.
  37. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    I
    Thank you for your feedback!
    Would you be interested in contributing your code to SpriteAssist?
     
    Last edited: Dec 16, 2020
  38. Aurigan

    Aurigan

    Joined:
    Jun 30, 2013
    Posts:
    291
    For such small changes I think you could just copy/paste ...

    TBH I'm not sure how best to interact with 3rd party packages that I want to make changes to ... my IDE (Rider) doesn't seem to work properly (code-completion/refactoring/compilation) with anything in packages and changes get reverted somehow (by Unity?). For now I took the easy route and just copied the code vs. using Sprite Assist as a package ... guess ideally I'd set it up as a fork/submodule.
     
  39. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    I see. I'll add normals to mesh;)
     
  40. van800

    van800

    JetBrains Employee

    Joined:
    May 19, 2016
    Posts:
    73
    Changes in read-only packages are usually reverted by Unity Package Manager without any notice.
    If you like to have your own version of a read-only package in Rider you should drag-n-drop it from read-only to `Packages`, it would make a copy of package. This new package is `Local` and Unity would prefer it.
    upload_2020-12-17_22-0-51.png
     
    Walter_Hulsebos likes this.
  41. oakus

    oakus

    Joined:
    Dec 27, 2012
    Posts:
    15
    +1 for the grid mesh type, I also have vertex animation features :)
     
    Gruguir likes this.
  42. Gruguir

    Gruguir

    Joined:
    Nov 30, 2010
    Posts:
    340
    I'd like to revive a project which made heavy use of the sprite mesh grid feature in spritesharp. So, another +1 for the grid mesh type :D
     
  43. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
  44. Glaswyll

    Glaswyll

    Joined:
    Feb 13, 2014
    Posts:
    103
    That's fantastic news! Thank you @Seromu !
     
    Seromu likes this.
  45. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
  46. Glaswyll

    Glaswyll

    Joined:
    Feb 13, 2014
    Posts:
    103
    Thanks @Seromu ! The update is looking good!

    I wanted to share the difference it makes in a project as far as motion consistency compared to Unity's default triangulation method.



    I did find a bug in the alpha detection. It may be something else, but it looks like it's adding additional polygons in areas that are transparent.

     
    Walter_Hulsebos likes this.
  47. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    @Glaswyll Thank you for feedback!! I'll fix it!
     
    Glaswyll likes this.
  48. Seromu

    Seromu

    Joined:
    Nov 30, 2015
    Posts:
    34
    Walter_Hulsebos and Glaswyll like this.
  49. Glaswyll

    Glaswyll

    Joined:
    Feb 13, 2014
    Posts:
    103
    @Seromu Thank you for this update!

    I noticed a couple bugs when working with Sprite Mode set to Multiple. Please check out the following:


    I've noted these three bugs, shown in the above video:
    • The initial mesh looks incorrectly sized and positioned compared to the Sprite bounds.
    • When changing SpriteAssist Mode to Grid, the color information disappears.
    • When using SpriteAssist Mode - Grid and Sprite Mode - Multiple, the grid mesh appears to be applying UV coordinates for the entire atlas to a single Sprite.
    This is looking good so far!
     
    Last edited: Sep 15, 2021
    Seromu likes this.
  50. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    This looks promising, but I am using it on pixel art assets and I need the details to be even finer so that it culls out empty spaces much more extensively. Value of 1 looks identical to what Unity gives for me, is there way to tighten this up?