Transfer bone values with delay

Forums General Discussion Transfer bone values with delay

This topic contains 9 replies, has 2 voices, and was last updated by  Gavalakis 2 months, 2 weeks ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1839

    poly
    Participant

    I’m trying to transfer the bone rotation values from one skeleton to another. My first attempt was to get/set local euler angles from/to every bone, which worked fine!

    Now, I would like to refine the script so that it becomes modular applicable to different characters without re-assigning every individual bone by hand. I tried to use the get/set bone transform/rotation functions, to which an animator variable can be assigned, and was hoping that I can simply change the dependencies with the animator variable. However, it doesn’t really transfer values from one skeleton to another. Maybe the problem is not related to the script but to the animator object itself. Any hint would be great!

    What I want to achieve is creating character with 10 arms, like a Shiva (example image attached). Thus I need to assign the script to a several instances of the arm rig. Additionally, it needs a time offset for each arm pair. I didn’t get to this point so far, as I’m still struggling with the rotation transfer. However, from looking at the FlowCanvas functions, I assume that the time delay can be achieved by creating a list of the rotation values and read out later positions from this list, right?

    Many thanks for any help!

    Attachments:
    You must be logged in to view attached files.
    #1842

    poly
    Participant

    Currently, I am using this nodes: Get Bone Transform -> Get local Rotation -> Set Bone local Rotation to get the values from the source skeleton and send it to the target skeleton. The debug mode shows that values are being sent from “Get local Rotation” to “Set Bone local Rotation”. But the target skeleton is not moving at all. I hope I have assigned all animator dependencies and settings correctly (e.g. activated “IK Pass” in the target animator), but there must be something I’ve missed (I’m new to Unity). Grateful for any hints. Here is an animated example of what I am trying to achieve: https://vimeo.com/248464203
    Thanks for any help!

    #1843

    Gavalakis
    Keymaster

    Hmm. Does the target skeleton has any animation of it’s own by any chance?
    I think that even if you copy/paste bone transform values per-frame to a target skeleton, if that skeleton has any animation or is anyhow being controlled by an Animator component, then the Animator animation will “win” over the copy/pasted values.
    For what you want to achieve, and considering I understood correctly, I think that you don’t even need an Animator controller on the target “duplicate” skeletons, but I might be wrong.

    #1846

    poly
    Participant

    The animator component needs to be assigned to the “Set Bone Local Rotation” node (screenshot), although there is no keyframe in the animation. The description of that node says “Sets local rotation of a human bone during a IK pass”. Maybe it needs an additional node to trigger the pass? The values from the source are streaming fine, but somehow the target does not react.

    Attachments:
    You must be logged in to view attached files.
    #1860

    Gavalakis
    Keymaster

    Ahh. This method works in the IK Pass. That means that you probably need to call this method in “OnAnimatorIK” event instead of a regular “Update” event. To do so, please try using the Animator event node (“Events/Object/Animator”) and more specifically the “On Animator IK” port of that node, in place of the “Update” node you have now.
    OnAnimatorIK

    Just make sure, to assign the “tree pose” animator gameobject you have in the “target” animator field of that event node’s inspector.
    AnimatorEventsInspector

    Let me know if that works for you.
    Thank you.

    Attachments:
    You must be logged in to view attached files.
    #1866

    poly
    Participant

    That works perfect, thanks a lot! Now it needs a time offset from the source to the target skeleton, so that the target skeleton plays the animation with a short delay. thus all arms will have an offset based on the delay of the motion. Couldn’t find a “time delay” node, but maybe there is a way to buffer the rotation values for a certain time and read it out after a given time constantly. Or an array in which values are stored every 1/30 seconds and then been read out by ID (higher ID number would cause longer delay). Would be great if you could give me a hint how to approach this in flowCanvas. Many thanks!

    #1870

    Gavalakis
    Keymaster

    Hello again and sorry for the late reply!

    There is actually a “wait” node, but I don’t think it will work for what you are after.
    I will try create a “buffer delay” / “echo” node and post it here for you once ready (expect tomorrow please)
    I think it is an interesting node to have anyway! 🙂

    Thanks!

    #1874

    poly
    Participant

    That would be awesome! Many thanks!
    Btw, that might be pretty close to a damper function too, where time based values are interpolated over a certain timespan. Could be quite useful to ease user controlled camera movements, soften jitter in mocap’s, etc…

    #1917

    poly
    Participant

    Any news about this new node? It’s getting more and more crucial for my current project to write/store joint rotation values in a buffer and delay, replay or interpolate/damp them.

    #1921

    Gavalakis
    Keymaster

    Hello again and sorry for the late reply.
    I’ve just manage to create this node you requested as well as a damp node (for floats and vectors).
    Since I find them to be useful and will be included in the next, the best way for you to use them now would be to open up the file “Time.cs” and copy/paste the following code in there instead of sending you a separate package file.

    Here is the code:

    
    	[Category("Time")]
        [Description("Input values are buffered and returned in order of buffering once the buffered amount reaches the buffer size. In practice this creates a delayed value output when the node is constantly updated per-frame.\nWhen the node ceases to update, a new buffer is created.")]
    	[ExposeAsDefinition]
    	public class Buffer<T> : PureFunctionNode<T, T, int> {
            
    		private int lastFrame = -10;
    		private Queue<T> q;
    		
    		public override T Invoke(T value, int size = 60) {
                var currentFrame = Time.frameCount;
    			
    			//init
    			if (currentFrame - lastFrame > 1){
    				q = new Queue<T>();
    			}
    
    			lastFrame = currentFrame;
    			q.Enqueue(value);
    			return q.Count >= size? q.Dequeue() : q.Peek();
            }
        }
    
    	[Name("Damp (Float)")]
    	[Category("Time")]
    	[Description("Returns a smoothly interpolated value towards the input value.")]
    	public class DampFloat : PureFunctionNode<float, float, float>{
    		private float last;
    		public override float Invoke(float value, float damp = 1f){
    			last = Mathf.Lerp(last, value, damp * Time.deltaTime);
    			return last;
    		}
    	}
    
    	[Name("Damp (Vector3)")]
    	[Category("Time")]
    	[Description("Returns a smoothly interpolated value towards the input value.")]
    	public class DampVector3 : PureFunctionNode<Vector3, Vector3, float>{
    		private Vector3 last;
    		public override Vector3 Invoke(Vector3 value, float damp = 1f){
    			last = Vector3.Lerp(last, value, damp * Time.deltaTime);
    			return last;
    		}
    	}
    

    Simply paste the code anywhere within the Time.cs file and within the namespace brackets of course.

    Here is an example usage:
    Buffer

    There is a big difference between Buffer and Damp of course:
    – Buffer, will output the exact input value in the exact order they were queued. Buffer also works with all types.
    – Damp, will instead output an interpolated value (float or Vector) towards the input value.

    Let me know if this works for you.
    Thanks!

    Attachments:
    You must be logged in to view attached files.
Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.