• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
Question by Totoro83y · Nov 23, 2018 at 03:27 PM · editor-scriptingmathinterpolationkeyframetangents

Meaning of inWeight and outWeight in Keyframe, or recalculate tangents from sampling

I'm writing an editor plugin to mirror automatically some animations. It works, but I cannot generate the correct tangents, and I suspect it is for I don't understand the tangent weight meaning. Here the long story:

I have a function GetValueAtTime(EditorCurveBinding binding, float time) that sample the animation and get the corresponding binded value. It works, because the flipped animation respond perfectly on the keyframes.

Now I want to calculate the tangents and weights between two keyframes, oldKey and newKey. To do t$$anonymous$$s I simply sample the model in two different equally spaced intermediate points and define the 4 points I'll use for the interpolation:

 var intermediateTime1  = 1 / 3f * (2 * oldKey.time +     newKey.time);
 var intermediateTime2  = 1 / 3f * (    oldKey.time + 2 * newKey.time);
 
 var intermediateValue1 = GetValueAtTime(binding, intermediateTime1);
 var intermediateValue2 = GetValueAtTime(binding, intermediateTime2);
 
 var p1 = new Vector2(oldKey.time,       oldKey.value);
 var p2 = new Vector2(intermediateTime1, intermediateValue1);
 var p3 = new Vector2(intermediateTime2, intermediateValue2);
 var p4 = new Vector2(newKey.time,       newKey.value);

The next t$$anonymous$$ng I do is to calculate the coefficients of the corresponding hermite polynomial c1 t^3 + c2 t^2 + c3 * t^1 + c4, supposing it is the correct interpolation unity do between keyframes:

 //var c1 = - 9/2f * p1 + 27/2f * p2 - 27/2f * p3 + 9 / 2f * p4;
 var c2 =   9    * p1 - 45/2f * p2 + 18    * p3 - 9 / 2f * p4;
 var c3 = -11/2f * p1 +  9    * p2 -  9/2f * p3 +          p4;
 //var c4 =          p1;

I don't need c1 and c4 so I commented out their calculation. t is a parameter that goes from 0 to one.

Now I need to calculate the tangents, and knowing that each point of the curve can be defined as (2p1 - 2p4 + p1' + p4') t^3 + (-3p1 + 3p2 - 2p1' - p4') t^2 + p1' t + p1, where p1' and p4' are the componentwise derivatives of the respective points, I can calculate the respective tangents and slopes:

 var t1 = c3;
 var t2 = -3 * p1 + 3 * p2 - 2 * t1 - c2;
 
 var slope1 = t1.y / t1.x;
 var slope2 = t2.y / t2.x;

 oldKey.outTangent   = slope1;
 newKey.inTangent    = slope2;

By now it seems almost correct, the elements seems to start to move in the right direction and the animation don't seems too weird, but in the hermite polynomial the interpolation between the points does not depend just on the tangents but even on the strenght the tangents have, strenght that I lose in the division I make to obtain the slope. Trying the animation, in fact, I don't have the same values of the original animation when I'm not in the keyframes. The mirrored animation is not so distant from the original one but does not perfectly match.

I experimented a lot with the inWeight and outWeight parameters of the Keyframe, trying to understand what they reresent, but I was not able to figure out it. I even tryed to read the Unity sources to figure out the exact algorithm it uses, but I didn't find the implementation in it, maybe the evaluation is in a part of the sources Unity Technologies didn't publish. So my answers are: are my thoughts correct untill t$$anonymous$$s point? And what exactly represents inWeight and outWeight in the curve interpolation?

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

173 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Elastic Interpolation of Quaternion 0 Answers

What exactly does Mathf.InverseLerp() do? 4 Answers

Finding a tangent vector from a given point and circle 1 Answer

Logarithmic Interpolation 1 Answer

Lazy Inspector customisation 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges