Giter Site home page Giter Site logo

animation-instancing's Introduction

As developers, we’re always aware of performance, both in terms of CPU and GPU. Maintaining good performance gets more challenging as scenes get larger and more complex, especially as we add more and more characters. Me and my colleague in Shanghai come across this problem often when helping customers, so we decided to dedicate a few weeks to a project aimed to improve performance when instancing characters. We call the resulting technique Animation Instancing.

It needs at least Unity5.4.

Features:

  • Instancing SkinnedMeshRenderer
  • root motion
  • attachments
  • LOD
  • Support mobile platform
  • Culling

Note: Before running the example, you should select menu Custom Editor -> AssetBundle -> BuildAssetBundle to build asset bundle.

Attachments:

There's a attachment scene. It shows how to use the attachments. How to setup the object which hold the attachment?

  • Open the generator menu -> AnimationInstancing -> Animation Generator
  • Enable the attachment checkbox
  • Selece the fbx which refrenced by the prefab
  • Enable the skeleton's name to generate
  • Press the Generate button.

animation-instancing's People

Contributors

ashwin911 avatar cloudjin avatar shahinrostami 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  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

animation-instancing's Issues

相同fbx,不同贴图的情况

我在应用到我的项目时,又遇到个问题就是有些角色只是换了一个皮肤,动作什么的都一样。我分别生成了两个prefab,这两个prefab只有贴图不一样其它都一样,然后再分别generator。但是实例出来的都是一样的。比如我先加载prefabA,再加载prefabB后出来的效果都是prefabA一样的贴图效果。如果先加载prefabB,后再加载prefabA出来的效果就是始终是prefabB的效果,请问这种情况要怎么处理呢?谢谢

GPU Instancing draw call衔接处的网格模型没有渲染

hello,我遇到个比较奇怪的问题,实例化了220个对象,发现有个对象没有被渲染,查看Frame Debugger发现是GPU Instancing draw call衔接处,请问可能是什么原因呢?

Frame Debugger的2个draw calls:

NullReferenceException

I think, this would be a great use for my zombie assignment, but i cannot get it work.
I am using these zombies here:
https://assetstore.unity.com/packages/3d/characters/humanoids/rpg-monster-pack-27663

If i want to follow the tutorial i found here:
https://blogs.unity3d.com/2018/04/16/animation-instancing-instancing-for-skinnedmeshrenderer/

the demos work fine, but if i want to use that on my zombie, i get this:

NullReferenceException: Object reference not set to an instance of an object
AnimationInstancing.AnimationGenerator+c__AnonStorey0.<>m__0 (UnityEngine.AnimationClip q) (at Assets/AniInstancing/Editor/AnimationGenerator.cs:257)
System.Collections.Generic.List1[UnityEngine.AnimationClip].GetIndex (Int32 startIndex, Int32 count, System.Predicate1 match) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:313)
System.Collections.Generic.List1[UnityEngine.AnimationClip].Find (System.Predicate1 match) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:216)
AnimationInstancing.AnimationGenerator.OnGUI () (at Assets/AniInstancing/Editor/AnimationGenerator.cs:257)
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/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/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

leading me to:
AnimationClip clip = clips.Find(q => q.name == clipName);

What's wrong with my animation clips ???

loop animation

Currently every animation loops.
It would be nice if the animation generator stored the clip loop value instead of having to manually manage the loop variable on AnimationInstance.cs

Instancing works in editor, not in build

Hello!

I have got the instancing to work in an editor scene, in which I render 100 animated models. But when I build and run the exact same scene, I first got the following error:

Could not find a part of the path "D:\Github\FarNorthZ Bin\FarNorthZ_Data\AnimationTexture\AnimInstance.bytes".

So I simply copied the AnimationTexture folder containing the .bytes files into the FarNorthZ_Data folder.

Now I receive no errors, and the prefab is instantiated a 100 times, just like in the editor, but there is no animation/model visible.

IndexOutOfRangeException

Click on "Generate" and i have this:

IndexOutOfRangeException: Array index is out of range.
AnimationInstancing.AnimationGenerator.GenerateAnimation () (at Assets/AniInstancing/Editor/AnimationGenerator.cs:114)
AnimationInstancing.AnimationGenerator.Update () (at Assets/AniInstancing/Editor/AnimationGenerator.cs:96)
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/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/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.SendUpdate () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:370)
UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at C:/buildslave/unity/build/Editor/Mono/EditorApplication.cs:127)

Animator does not have an AnimatorController

GenerateAnimation()中的workingInfo.animator.Play(workingInfo.info.animationNameHash);
每次第一个动画都会报Animator does not have an AnimatorController
我在网上查说是activeself要为true
我看见您在代码中加了workingInfo.animator.gameObject.SetActive(true);
而且调试看起来没问题。
这是为什么?

example doesn't work

I opened the Crowd Simulation scene in your project. when I try to run it, there is an error:
image
after that I saw a lot of characters instantiated but couldn't appear in game windows.
(in unity 2018.1.0b9 on Win10,)

Why custom serializer?

Is there a good reason for this? Why I ask is that I want to make it so you can create instances at runtime, and I was going to change the code so it stores animation info in a ScriptableObject. Unless there is a good reason not to do that.

How is the culling supposed to work?

I've managed to bake my own character and am using him to visualise some pedestrian simulation data. The batching works great but what I've got now is a poly count problem. If I even slightly start to get towards having one of the crowd entities near the camera frustrum it's like I'm suddenly rendering them all - even with shadows disabled. Is this correct behaviour?

Small typo in label

It's a really small thing, but since it's on a label I report anyway.
The typo is also in the image that is in the readme.md:

"Animation texture wiil be..."

It happens here:

EditorGUILayout.LabelField(string.Format("Animation Texture wiil be one {0} X {1} texture", textureWidth, textureWidth));

and here:

EditorGUILayout.LabelField(string.Format("Animation Texture wiil be {2} 1024 X 1024 and one {0} X {1} textures", textureWidth, textureWidth, textureCount - 1));

Lighting

So what is the solution to correct lighting with this approach?

useInstancing conflicts with packaging

If useInstancing is false, the system still packages data as if instancing should be used. Which results in not all meshes being rendered. If you have a mix of same and not same meshes, with useInstancing it's going to call DrawMeshInstanced for all of them. Not sure how much extra overhead that is.

On PC the simple fix is in Render instead of if (useInstance) do if (package.instancingCount > 1). But packaging needs to be aware of useInstancing to make it just work for all cases.

Shaders ?

I don't want to bother you, but now something is wrong.

The Animator and Skinned Mesh Renderer are deactivated, when spawning, even for the low poly dude, so the original example is broken now.
Same happened to the Animation Instancing Shaders.
There's no more Dude low or anything showing now.
He looks fine, if i switch back to Standard Shader, but i think, that's not, what we want ^^

BTW. Generating my Animation Instances now is working.

Initialize animation failed. Please check out the backed animation infos.
UnityEngine.Debug:Log(Object)
AnimationInstancing.AnimationInstancingMgr:AddInstance(GameObject) (at Assets/AniInstancing/Scripts/AnimationInstancingMgr.cs:278)
AnimationInstancing.AnimationInstancing:Start() (at Assets/AniInstancing/Scripts/AnimationInstancing.cs:156)

不能用在IOS?

在bake的时候看到这个提示You can't bake animations on IOS or Android. Please switch to PC.
面向metal或者gles3的移动应用也不能用这个么?

系统内置的Shader应该怎么修改呢?

我直接替换人物的shader从standard成Normal-BumpSpecinstancing后,这个人物我本地该过模型的mesh的材质球,加载出来的人物与原人物不一样了。
image
image

Crowd Simulation Scene, some random character flickering 角色闪烁

In crowd simulation scene, sometimes one or several character may flickering. Happens both in unity editor and android build.
在crowd simulation scene中有时会有一个或几个角色的闪烁,在editor以及android build上都有相同问题。
(一般在一个block 的 package 中instance数量满的时候 (范例是200) )

Can shadows be disabled?

So far i get okay performance, but after about 1000 low poly units the FPS starts to suffer. Profiler shows high cpu usage on animationmanager Update function. Can i improve performance by disabling shadows or possibly making it update every second frame?

Animation Events triggered at wrong time

In AnimationInstance.cs method UpdateAnimationEvent() the code implies that the event time is normalised when in fact it is not.
A change to the time variable in this method is required to check the time based on actual time the animation has been running.
Making the following changes at line 403 and 407 corrected the problem for me.
float time = curFrame / info.totalFrame;
To
float time = curFrame / info.fps;

Example Scene does not work

Launching the example scene just throw errors straight from the start.
In the hierarchy "Dude_low_instancing", AnimationInstancing component is missing the Prototype.
The problem does not end here as filling in the prefab still does not work throwing further errors.
I'm currently running through the code and see if I can help

Can it bake more than one character?

Sry i'm new i just want to ask if i can bake more than one character
if they use same textures, materials and animations

is there a doc or videos to know how to use it

Thanks

运行示例场景时,BinaryReader读取报错“Failed to read past end of stream”

info.eventList = new List<AnimationEvent>(); for (int j = 0; j != evtCount; ++j) { AnimationEvent evt = new AnimationEvent(); evt.function = reader.ReadString(); evt.floatParameter = reader.ReadSingle(); evt.intParameter = reader.ReadInt32(); evt.stringParameter = reader.ReadString(); evt.time = reader.ReadSingle(); evt.objectParameter = reader.ReadString(); info.eventList.Add(evt); }

操作顺序:CustomEditor->AssetBundle->BuildAssetBundle
绑定prefab上AnimationInstancing中的prototype为自身。
运行场景

"Instancing is not supported" exception on android

I download the project from github, try this, and its worked great on PC,
but it didnt worked when I build the project on android, it return exception "InvalidOperationException: Instancing is not supported"

ps: I already build the assetbundle, and it wordked on unity editor

Layers

Was thinking about the best way to handle layers, looking for some feedback on approaches.

  1. Abstract out the concept of a playing animation from AnimationInstancing. So an instance can have multiple animations playing. This would require passing more data to shaders when more then one layer is active. Plus logic for masking. Would change a lot of code throughout the entire runtime flow.

  2. Handle it at generation time. Record each combination you want. Would require some new logic to start/record multiple animations playing but seems far simpler then #1. Potentially this could use a lot of memory but I think it would work well for most use cases and seems like a good bang for the buck.

No transitions

There are no transitions for animations, this would make the system a lot more robust and usable.

Can anyone direct me on roughly what would need to be added?

完善Transition遇到问题,求帮助

我在自己完善Transition功能时遇到问题,当从动画A过渡到动画B,当实现动画重叠时,我需要给每个instance多提交一个原来动画的texture,就像您源码里给每个instance提交frameIndex一样,我该怎么做?

我测试时动作不工作

你好,非常感谢能提供这个功能,我下载demo工程后直接buildassetbundle,运行工程后,角色动作正常。但是我再Animation generator一次后,再buildassetbundle,然后运行工程,角色的动作不能播放出来了,没怎么仔细看代码(ps:看不太懂:()。用的是unity2017.2.0p3

Shows only the first object of the animated charcter.

I have a skeleton which has such structure
Skeleton
-- Bip (bones)
-- Body (has skinned mesh renderer)
-- Sword (has skinned mesh renderer)

After generation it works fine but renders only the first object which has mesh renderer. In this case Body. If I change order it will render only the sword.

Issue with XBOX One uwp.

I am attempting to get this to work on Xbox One altering the manager code but i keep getting access denied and wondering if anyone got this working for Consoles yet?

Runtime generation

To support things like character customization and clothing you need to break out all the stuff that is editor only mode. I started working on this not too far away from having something workable.

I split out the generation into two steps and created a template abstraction.

So you start with a template, which is your model and skinned mesh(s), along with a list of animation clips you populate manually. In a real workflow you won't be creating animation controllers. So the editor mode generator creates a temporary one for you and generates the AnimationBakeInfo's, which it saves with the template.

Step two continues but it doesn't have anything that requires UnityEditor. So you can swap meshes in your template and generate a new instance at runtime.

Most all of that leaves the existing code untouched for the most part. AnimationBakeInfo needed to be put into it's own file and made public. Loading instance data needs another option to load from a ScriptableObject container I use that holds templates and instances. But mostly it's just an addition.

I'll create a pull request once it's ready. And let me know if you have any thoughts on any of the above.

Needs asset bundles?

Does this asset needs the project to use asset bundles? Can there be an option not to use them, maybe include a path to the animation textures as a string variable or serialize them per animation converted?

Shaders with Outline

Hello - trying to use this with a shader which has outline (Toony colors pro 2) but the outline either doesn't move with the animation, or floats in in the middle of the screen. I've tried adding those 2 lines in various places to make it work...

可以支持多个camera,改变layer的情况吗?

如题,因为我们项目中是2d场景+3d角色的处理,需要对角色在不同情况下修改layer让不同的camera渲染,目前好象不支持这种情况,不知道有办法支持吗?
还有个现象:我用正交camera,改变size时,角色移动时会留下残影,如图
谢谢
image

具体如何添加武器呢?

您好,Attachment settings骨骼节点如何与武器绑定在一起,武器需要符合什么样的格式!
image

自己尝试了,发现各种报错
Debug.Log("Initialize animation failed. Please check out the backed animation infos.");

Setup documentation/tutorial

Hello, I really need to make this asset work ASAP however I can't manage to set it up correctly with attachements. How the prefab should be setup before generating animations ? how to organize the mesh ?
Having a documentation page or a video tutorial would be MUCH appreciated !! Thanks !

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.