Giter Site home page Giter Site logo

elringus / sprite-dicing Goto Github PK

View Code? Open in Web Editor NEW
1.3K 42.0 137.0 55.36 MB

Cross-engine tool for lossless compression of sprites with identical areas

Home Page: https://dicing.elringus.me

License: MIT License

C# 45.21% Shell 0.04% Rust 54.27% PowerShell 0.48%
game-development texture unity sprites abi cli rust tool

sprite-dicing's Introduction

SpriteDicing


crates.io CodeFactor CodeCov


Reuse repeating texture regions

Use SpriteDicing to split a set of sprite textures into units, discard identical ones, bake unique units into atlas textures to then seamlessly reconstruct the original sprites at runtime, without actually keeping original textures in the build.

The solution significantly reduces build size when multiple textures with identical areas are used. Consider a visual novel type of game, where multiple textures per character are used, each portraying different emotion; most of the texture space is occupied with identical data, while only a small area varies:

dicing illustration

These original five textures have total size of 17.5MB. After dicing, the resulting atlas texture will contain only the unique areas of the original textures and consume just 2.4MB, effectively compressing the textures by 86.3%.

Sprite Dicing is used in Naninovel β€” visual novel engine. Check it out!

naninovel banner

🎬 Get Started

https://dicing.elringus.me/guide/getting-started

sprite-dicing's People

Contributors

elringus avatar rguerreiro-kb avatar sttz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sprite-dicing's Issues

Fix codecov CI

At some point (probably due to a game-ci/unity-test-runner or codecov/codecov-action action update) codecov no longer uploads the coverage report: https://github.com/Elringus/SpriteDicing/runs/8296569635

I've spotted that game-ci/unity-test-runner action started ignoring -coverageResultsPath setting and now write the reports to /github/workspace/CodeCoverage; I've tried changing project root for codecov/codecov-action to that directory, but it didn't help.

If anyone have any idea on how to fix this, please let us know here.

https://community.codecov.com/t/cant-upload-coverage-report-generated-with-game-ci-unity-test-runner/4022

Sprite Centers are wrong

I'm still having this problem with the latest 1.1 package. The first image is my actual PNG with alpha. As you can see, the sprite is near the bottom half of the PNG. The second image is with the pivot point set to default (the sprite has been re-centered), and the third image is with the pivot point with the checkbox "Keep Original" (the sprite has been offset based on the lower left-hand corner). How do I make this use the actual position of the sprite on the PNG?

Diced Sprites Problem

Generate native Unity sprites

Currently, a custom scriptable object is used to represent diced sprite asset. This leads to multiple complications and issues, like the need to use a custom renderer and the lack of some core native sprite features, like animation and masking support.

The main issue stopping us from switching to the native sprites is the lack of a way to set custom texture UVs to the Sprite objects. This is, alongside with the ability to set custom mesh geometry, is essential to reconstruct the original sprite from the diced atlas texture.

In case someone have an idea how to deal with the issue, or have any info on possible upcoming changes to the Unity’s sprite API, which will allow to set the UVs, please share it in this thread.

Improve dices content hashing speed

Currently, content hash for dices is generated via Unity's Texture.imageContentsHash, which requires creating and filling a texture per dice, which is inefficient: https://github.com/Elringus/SpriteDicing/blob/master/Assets/SpriteDicing/Editor/Processors/TextureDicer.cs#L93

If anyone have an idea on how to replicate the Unity's image content hashing in a way that even slightly different textures will have unique hashes, please share it here or create a pull request. I've already tried hashing color arrays by each item value and its index, but it's not working in some cases (eg, square in Assets/Examples/Atlases/Flat will have artifacts).

We could probably try Hash128.Compute, which accepts arrays in Unity 2020, but I want to keep compatibility with 2019.4 for the time being.

Allow setting custom TextureImporterPlatformSettings

After dicing and generating the diced texture, it'd be nice to automatically apply custom compression settings.

This would make rebuilding it a lot easier because every time it resets to default.

I saw there is a class called UnityEditor.TextureImporterPlatformSettings that seems to hold this information, but I'm not experienced enough in UnityEditor to know how to include it in the SpriteDicing.Editors.DicedSpriteAtlasEditor class.

Screen Shot 2022-04-08 at 12 54 36 PM

.

Atlas size inreased on rebuild

The sample asset (Animation.asset) is about 15MB.

However, an asset created with the same settings is about 8MB.
If I rebuild the asset, it will be about 15MB.

Is this a bug?

SpriteDicing : v1.1
Unity : 2019.4.5f1 / 2019.4.11f1

AnimationAnimation_tmp

the how to use need a small update.

i recently getting a problem from figuring how to use your diced system because apparently, unity changed a bunch of thing related to image component... as shown in this screenshot:
image

Actual Sprite pixel dimensions not being preserved

The sprite dicing algorithm is removing any white space, making fixed-size sprites (32x32, 64x64, etc.) coming out smaller than the really are, which is messing up alignment. For example, if I have a small graphic that animates by moving around the corners of a 32x32 square, the animations just all get cropped to the actual sprite, so it no longer moves around. Does that make sense how I described it? I feel like the dicing algorithm should take into account where it trims the white space and adjusts the pivot point to compensate.

Publish semver tag for OpenUPM

For the ease of installing your package via OpenUPM, please publish with semver tags (e.g. 1.10.0) instead of v1.10. The tag string should match the version string defined in your package.json.
Many thanks!

From OpenUPM:
https://openupm.com/packages/com.elringus.spritedicing/

No valid git tag
OpenUPM only tracks Git tags that adhere to the semver convention. If a valid Git tag is not found, the package will not appear on the package listing.

Nullref when serializing asset on Unity 2022

Unity 2022.3.14
SpriteDicing 1.10.0

I'm receiving this exception when trying tpo build the atlas.

Failed to build diced sprite atlas. System.ArgumentNullException: Value cannot be null.
Parameter name: _unity_self
  at (wrapper managed-to-native) UnityEditor.SerializedObject.ApplyModifiedProperties(UnityEditor.SerializedObject)
  at SpriteDicing.Editors.AtlasBuilder.<PackTextures>g__SaveAtlasTextures|8_2 (System.Collections.Generic.IReadOnlyList`1[T] textures) [0x0003d] in D:\Projects\SpriteDicing\Assets\SpriteDicing\Editor\Editors\AtlasBuilder.cs:106 
  at SpriteDicing.Editors.AtlasBuilder.PackTextures (System.Collections.Generic.IReadOnlyList`1[T] dicedTextures) [0x00068] in D:\Projects\SpriteDicing\Assets\SpriteDicing\Editor\Editors\AtlasBuilder.cs:77 
  at SpriteDicing.Editors.AtlasBuilder.Build () [0x0000f] in D:\Projects\SpriteDicing\Assets\SpriteDicing\Editor\Editors\AtlasBuilder.cs:32 
UnityEngine.Debug:LogError (object)
SpriteDicing.Editors.AtlasBuilder:Build () (at Assets/SpriteDicing/Editor/Editors/AtlasBuilder.cs:38)
SpriteDicing.Editors.DicedSpriteAtlasEditor:DrawInputFolderGUI () (at Assets/SpriteDicing/Editor/Editors/DicedSpriteAtlasEditor.cs:142)
SpriteDicing.Editors.DicedSpriteAtlasEditor:OnInspectorGUI () (at Assets/SpriteDicing/Editor/Editors/DicedSpriteAtlasEditor.cs:43)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.