Antoshidza / NSprites-Foundation

Basic assets for working with NSprites package
MIT License
65 stars 17 forks source link

Incorrect Scale calculation #14

Closed foxor closed 5 months ago

foxor commented 5 months ago

The baker in SpriteSettingsAuthoringModule.cs calculates the size of a sprite in a very different way than standard unity conventions dictate. The rendered size of a sprite ends up introducing a novel unnecessary scale scalar and ignoring the conventional pixels per unit. This also implicitly assumes that all sprites in a sheet are the same size.

An improved version:

SpriteSettingsAuthoringModule.cs:

        public void Bake<TAuthoring>(Baker<TAuthoring> baker, TAuthoring authoring, Sprite source, in float4 uvAtlas)
            where TAuthoring : Component
        {
            var authoringTransform = authoring.transform;
            var authoringScale = authoringTransform.lossyScale;

            baker.BakeSpriteRender
            (
                baker.GetEntity(TransformUsageFlags.Dynamic),
                authoring,
                uvAtlas,
                GetTilingAndOffsetByDrawMode(),
                Pivot,
                new float2(source.texture.width, source.texture.height) * uvAtlas.xy / source.pixelsPerUnit * new float2(authoringScale.x, authoringScale.y),
                flipX: Flip.x,
                flipY: Flip.y
            );
        }
Antoshidza commented 5 months ago

Hello! Thank you for pointing this out. Would you like to make a pull request?