Giter VIP home page Giter VIP logo

fabriziospadaro / spritesheetrenderer Goto Github PK

View Code? Open in Web Editor NEW
370.0 31.0 47.0 1.84 MB

Spritesheet renderer is a powerful Unity ECS API to render massive numbers of sprites using the new dots stack, taking full advantage of Jobs, DynamicBuffers and ComputeBuffer

Home Page: https://www.linkedin.com/in/fabrizio-spadaro/

License: Other

C# 41.12% ShaderLab 51.78% HLSL 7.10%
unity ecs entity-component-system unity2d unity-dots

spritesheetrenderer's People

Contributors

fabriziospadaro avatar sarkahn 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

spritesheetrenderer's Issues

Sprites are not sorted from top to bottom

I finally got the time to play with this framework. It is indeed very fast.

However, I've observed that sprites are not sorted from top to bottom:
image

How could I go to fix this? I still don't understand the code that much, but my initial look is that I probably need to sort the buffer of SpriteIndexBuffer by using the y position at its MatrixBuffer. Although I'm not sure if scrambling the array of SpriteIndexBuffer would affect the rendering. Like if I should also move the corresponding MatrixBuffer.

NullReferenceException in CreateBuffersContainer after upgrading to Entities 0.17.0-preview.42

Trying to launch the SingleSpriteSheetSpawner demo, and getting callstack below. In short, DynamicBufferManager.CreateBuffersContainer crashes when creating this archetype:

var archetype = EntityManager.CreateArchetype(
          typeof(SpriteIndexBuffer),
          typeof(MatrixBuffer),
          typeof(SpriteColorBuffer),
          typeof(SpriteSheetMaterial),
        typeof(UvBuffer)
        );

It works on previous version - 0.16.0-preview.21
Interestingly, creating the same archetype elsewhere - I did it in Convert() of SingleSpriteSheetSpawner - works.

Callstack:

NullReferenceException: Object reference not set to an instance of an object
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <a5172b547855499dbc8d9d50552f0797>:0)
Unity.Entities.EntityManager.GetCheckedEntityDataAccess () (at Library/PackageCache/[email protected]/Unity.Entities/EntityManager.cs:76)
Unity.Entities.EntityManager.CreateArchetype (Unity.Entities.ComponentType[] types) (at Library/PackageCache/[email protected]/Unity.Entities/EntityManagerCreateArchetype.cs:29)
DynamicBufferManager.CreateBuffersContainer (SpriteSheetMaterial material) (at Assets/SpriteSheetRenderer/Scripts/DynamicBufferManager.cs:58)
DynamicBufferManager.GenerateBuffers (SpriteSheetMaterial material, System.Int32 entityCount) (at Assets/SpriteSheetRenderer/Scripts/DynamicBufferManager.cs:46)
SpriteSheetManager.RecordSpriteSheet (UnityEngine.Sprite[] sprites, System.String spriteSheetName, System.Int32 spriteCount) (at Assets/SpriteSheetRenderer/Scripts/SpriteSheetManager.cs:134)
SingleSpriteSheetSpawner.Convert (Unity.Entities.Entity entity, Unity.Entities.EntityManager eManager, GameObjectConversionSystem conversionSystem) (at Assets/SpriteSheetRenderer/Examples/SingleSpawnSprite[DEMO]/Script/SingleSpriteSheetSpawner.cs:36)

Bulk Spawn With SpriteSheetAnimator

Would you be able to give an example of A bulk spawn using The SpriteSheetAnimator?

I keep running into this error when switching animations.

IndexOutOfRangeException: Index 0 is out of range in DynamicBuffer of '0' Length.
Unity.Entities.DynamicBuffer1[T].CheckBounds (System.Int32 index) (at Library/PackageCache/[email protected]/Unity.Entities/Iterators/DynamicBuffer.cs:125) Unity.Entities.DynamicBuffer1[T].set_Item (System.Int32 index, T value) (at Library/PackageCache/[email protected]/Unity.Entities/Iterators/DynamicBuffer.cs:174)
CCZ.Code.SpriteSheetRendererSystem.SpriteSheetRenderer.Systems.MatrixBufferSystem+UpdateJob.Execute (CCZ.Code.SpriteSheetRendererSystem.SpriteSheetRenderer.Components.SpriteMatrix& data, CCZ.Code.SpriteSheetRendererSystem.SpriteSheetRenderer.Components.BufferHook& hook) (at Assets/CCZ/Code/SpriteSheetRendererSystem/SpriteSheetRenderer/Systems/MatrixBufferSystem.cs:19)
Unity.Entities.JobForEachExtensions+JobStruct_Process_CC3[T,T0,T1].ExecuteChunk (Unity.Entities.JobForEachExtensions+JobStruct_Process_CC3[T,T0,T1]& jobData, System.IntPtr bufferRangePatchData, System.Int32 begin, System.Int32 end, Unity.Entities.ArchetypeChunk
chunks, System.Int32
entityIndices) (at Library/PackageCache/[email protected]/Unity.Entities/IJobForEach.gen.cs:3846)
Unity.Entities.JobForEachExtensions+JobStruct_Process_CC3[T,T0,T1].Execute (Unity.Entities.JobForEachExtensions+JobStruct_Process_CC3[T,T0,T1]& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/[email protected]/Unity.Entities/IJobForEach.gen.cs:3817)**

Sprites not rendering unless the Camera FOV is Wide

Hello,

Thanks for making such a great example. I'm having a strange issue where your example scene works great, and I can copy/paste the example MakeSpriteEntities to a blank scene and it works great, but if I copy/paste into my game scene the sprites only render if the camera is pulled very far back, or if the camera has a wide FoV.

I have made sure no other objects are blocking the sprites due to sorting etc. The entity systems all appear to be running consistently either way.

I know you can't dig into my game scene, but any technical reason come to mind why the camera or screen size might toggle the rendering on and off?

Appreciate your thoughts as I've spent a good 10 hours trying to solve this one issue. Thank you either way!

[question] is it possible to change spritesheet/material through a system ?

I wanted my entity to change animation so i regestered 2 spritesheet materials for the two animations

spriteSheets = new SpriteSheetMaterial[spriteNames.Length];

            for (int s = 0; s < spriteNames.Length; s++)
            {

                var name = spriteNames[s];

                SpriteSheetManager.RecordSpriteSheet(spriteList[s].sprites, name, spriteList[s].sprites.Length);

                spriteSheets[s] = new SpriteSheetMaterial { material = SpriteSheetCache.GetMaterial(name) };
            }

then i assigned the first to my entities (along with the standard stuff you documented in the readme)

eManager.SetSharedComponentData(e, spriteSheets[0]);

and I was tryng to swap material in a system to change the animation

public class UnitChangeMaterialSystem : SystemBase
{

    protected override void OnUpdate()
    {
        var elapsed = Time.ElapsedTime;

        SpriteSheetMaterial material = new SpriteSheetMaterial { material = SpriteSheetCache.GetMaterial("idle se") };

        Entities.WithAll<SpriteSheetMaterial>().ForEach((Entity entity, BufferHook bufferHook, ref UnitOrientationComponent orientation) =>
        {
            if (elapsed > 5 && orientation.Value == Orientation.NE )
            {

                orientation.Value = Orientation.SE;
                EntityManager.SetComponentData(entity, new BufferHook { bufferID = 10 + bufferHook.bufferID, bufferEnityID = DynamicBufferManager.GetEntityBufferID(material) });
                EntityManager.SetComponentData(entity, new SpriteIndex { Value = 10 + bufferHook.bufferID });
                EntityManager.SetComponentData(entity, new SpriteSheetAnimation { maxSprites = SpriteSheetCache.GetLength("idle se"), play = true, repetition = SpriteSheetAnimation.RepetitionType.Loop, samples = 10 });
                EntityManager.SetSharedComponentData(entity, material);


            }

        })
            .WithStructuralChanges()
            .WithoutBurst()
            .Run();

    }
}

what am I doing wrong ? Excuse the noob question but I'm a week into Unity and not much is clear

Unable to remove null materials?

You intend to remove missing materials in SpriteSheetRenderer.cs but you may miss nulls if you don't iterate through the loop backwards, correct? (The list's remove method will decrease the Count)

for(int i = 0; i < materials.Count; i++) if(!materials[i].material) materials.Remove(materials[i]);

[question] Is it possible to flip the spritesheet? Using ScaleX or FlipX?

Hi, I just start to use this framework. It is pretty nice and fast implementation of spritesheet in DOTs.

I just wonder if there is anyway to flip the sprite in runtime (like the FlipX method in the old way)? Any suggestion for me to implement it myself is also really appreciated if you dont have much time yet. ๐Ÿ˜„

MakeSprite fails when the sprites sheet has only 1 sprite

It seems the material is not registered to dictionaries when the sprites.Length == 1. (SpriteSheetCache.cs:15)

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary2[TKey,TValue].get_Item (TKey key) (at <437ba245d8404784b9fbab9b439ac908>:0) SpriteSheetCache.GetMaterialName (UnityEngine.Material material) (at Assets/SpriteSheetRenderer/Scripts/SpriteSheetCache.cs:45) SpriteSheetCache.GetLenght (UnityEngine.Material material) (at Assets/SpriteSheetRenderer/Scripts/SpriteSheetCache.cs:46) RenderInformation..ctor (UnityEngine.Material material, Unity.Entities.Entity bufferEntity) (at Assets/SpriteSheetRenderer/Scripts/RenderInformation.cs:17) SpriteSheetManager.RecordSpriteSheet (UnityEngine.Sprite[] sprites, System.String spriteSheetName, System.Int32 spriteCount) (at Assets/SpriteSheetRenderer/Scripts/SpriteSheetManager.cs:123) ECSSpriteSheetAnimation.Examples.MakeSpriteEntities.Convert (Unity.Entities.Entity entity, Unity.Entities.EntityManager eManager, GameObjectConversionSystem conversionSystem) (at Assets/SpriteSheetRenderer/Examples/BulkSpawnSprites[DEMO]/Scripts/MakeSpriteEntities.cs:37) Unity.Entities.Conversion.ConvertGameObjectToEntitySystem.Convert (UnityEngine.Transform transform, System.Collections.Generic.List1[T] convertibles) (at Library/PackageCache/[email protected]/Unity.Entities.Hybrid/GameObjectConversion/ConvertGameObjectToEntitySystem.cs:43)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
Unity.Entities.Conversion.JournalingUnityLogger:LogException(Exception, Object) (at Library/PackageCache/[email protected]/Unity.Entities.Hybrid/GameObjectConversion/JournalingUnityLogger.cs:50)
UnityEngine.Debug:LogException(Exception, Object)
Unity.Debug:LogException(Exception, Object) (at Library/PackageCache/[email protected]/Unity.Entities/Stubs/Unity/Debug.cs:29)
Unity.Entities.Conversion.ConvertGameObjectToEntitySystem:Convert(Transform, List1) (at Library/PackageCache/[email protected]/Unity.Entities.Hybrid/GameObjectConversion/ConvertGameObjectToEntitySystem.cs:48) Unity.Entities.Conversion.<>c__DisplayClass1_0:<OnUpdate>b__0(Transform) (at Library/PackageCache/[email protected]/Unity.Entities.Hybrid/GameObjectConversion/ConvertGameObjectToEntitySystem.cs:56) Unity.Entities.EntityQueryBuilder:ForEach(F_C1) (at Library/PackageCache/[email protected]/Unity.Entities/EntityQueryBuilder_ForEach.gen.cs:215)
Unity.Entities.Conversion.ConvertGameObjectToEntitySystem:OnUpdate() (at Library/PackageCache/[email protected]/Unity.Entities.Hybrid/GameObjectConversion/ConvertGameObjectToEntitySystem.cs:56)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/[email protected]/Unity.Entities/ComponentSystem.cs:107)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:182)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:169)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/[email protected]/Unity.Entities/ComponentSystem.cs:107)
Unity.Entities.GameObjectConversionUtility:Convert(World) (at Library/PackageCache/[email protected]/Unity.Entities.Hybrid/GameObjectConversion/GameObjectConversionUtility.cs:153)
Unity.Entities.ConvertToEntitySystem:Convert() (at Library/PackageCache/[email protected]/Unity.Entities.Hybrid/ConvertToEntity.cs:172)
Unity.Entities.ConvertToEntitySystem:OnUpdate() (at Library/PackageCache/[email protected]/Unity.Entities.Hybrid/ConvertToEntity.cs:67)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/[email protected]/Unity.Entities/ComponentSystem.cs:107)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:182)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:169)
Unity.Entities.ComponentSystem:Update() (at Library/PackageCache/[email protected]/Unity.Entities/ComponentSystem.cs:107)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/[email protected]/Unity.Entities/ScriptBehaviourUpdateOrder.cs:152)

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.