- Home /
switching entire model each frame
Hello all,
I'm having a hard time wrapping my head around a simple idea :
I have a photogrammetry model where a figure is walking.
So there are 7 models making up a walk cycle.
How can I cycle through these?
Thanks
~be
I would recommend you use another method to animate the model. The method you are talking about using will cause significant strain on the cpu and gpu, due to the model having to be loaded with textures and then destroyed each single frame. I know this does not answer your question, but there are much better solutions available such as creating rigs and animations.
Thanks,
Yes I agree, and I am rigging the model as well, but there are times when I will want this ability too...
Any ideas? Setting from rate to 8 fps
Thanks
!be
Sure, I have some ideas. The default mecanim animation system built into Unity should be able to swap models during each animation frame. Just create a new animation and controller, start recording the animation and swap the mesh attached to the mesh rendererer. An alternative would be to hide/show particular mesh rendererers according to which model you want visible.
You basically have to write a custom animator that uses custom classes for clips and frames. A frame would have information about the mesh that should be used, and how long the frame is (so it's not related to the frames that the program runs at). A clip would have an array of frames, and a name, and wether it is looped or not. The animator itself would have an array of clips in turn, and have function that play and stop clips via Coroutines. I have written such a system for my own project and added editor extensions so I can easily create animations in a custom window.
@cherno, @ JonathanCzeck Thanks guys ! Interesting I think John's script below would do that without having to use a coroutine:
I am actually dealing with something like this for a pixel based animation because I am creating voxel characters. I need to implement object pooling and each animation frame is about 1/4 a second. Bbut if it is a 3D model I would not even consider it, just animate in mechanism or third party ($$anonymous$$aya, Blender) etc or create a texture and swap out the textures every quarter second.
Answer by JonathanCzeck · Dec 04, 2015 at 10:55 AM
Just change the rendered mesh at runtime.
using UnityEngine;
[RequireComponent(typeof(MeshRenderer))]
public class MeshCycler : MonoBehaviour {
public float fps = 8f;
public Mesh[] meshes;
MeshFilter meshFilter;
void Awake() {
meshFilter = GetComponent<MeshFilter> ();
}
void Update () {
int index = ((int)(Time.time * fps)) % meshes.Length;
meshFilter.sharedMesh = meshes [index];
}
}
Is that what you want?
Answer by percycampos · May 03, 2017 at 08:43 AM
Hello.
I have been experimenting with this idea as well. I'm trying to animate multiple, different meshes ( in this case, an obj seq,) and I'm wondering if this is really optimal (for mobile.)
I understand there are Assets that can play obj seq's (MegaCache, which I own) but i can't seem to master .mtl libraries due to each obj having it's own unique material.
I was able to animate each obj with the mesh renderer, but do you know if this is optimal?
Thanks!
Did you find the answer? did it works fine on mobiles?
Your answer
Follow this Question
Related Questions
Import multiple models in runtime into Unity3d scene and make an animation sequence out of it 0 Answers
Animation Lag With Maximo? 1 Answer
Vehicle animation on a 2d map 0 Answers
the animation walk but he still in the same place and rotate left and right on this white circle 0 Answers
How can I create a home position where my character returns to after every animation? 0 Answers