Action interpolation based on Unity3d three-dimensional model (implementation of space key frame animation)

Source: Internet
Author: User
Tags cos sin

1. Introduction

A skeleton animation based on a custom mesh mesh was recently implemented in Unity3d. Stores the keyframe information and then interpolates to form an intermediate animation. There is a parent-child relationship between grid Gameobject. Interpolation animations blend position, sclae, rotation three parts of the model bone.

Also note that the general selection is the transform information of the child bone relative to the parent bone, that is, the above key frame information should be transform.localposition, Localscale, Localrotation.

And the key frame of this system is defined in three-dimensional space, the user drags a preset point between a series of key frame points, the system automatically mixes to generate the model action information at the preset point location.

Demo Video Address: http://v.qq.com/page/c/f/j/c0149v62gfj.html

The red is the preset point in the video, the green is the keyframe point, the keyframe is defined in a space position, the preset point calculates itself to the key frame point distance, generates n weights information, then mixes into the model animation.

2. Distance weights

The distance between the preset point and the N space keyframe is D1,D2,D3...DN, my weight function: weight_i=1/(di^4), which converges faster near the keyframe, and the whole process is smoother, and sum_weight=weight_1 + weight_2 + Weight_3 +...+weight_n

The default weights for n space points are weight_i/sum_weight (i=1,2,3 ... N).

Position and scale only need to multiply the sum of weights, the trouble is that the rotation,3d space rotation is generally used is four yuan, four of the number has not produced "universal joint Lock (Gimbal Lock)" and other excellent characteristics. The following is a discussion of the nature of the four-tuple and the interpolation operations on n four-ary numbers.

Interpolation calculation of 3.N four-dollar number

A four-tuple represents an angular pair of space ((x, Y, z), W), also represented ((Sin (THETA/2) nx,sin (THETA/2) ny,sin (THETA/2) Nz), cos (THETA/2))

And in Unity3d, the generated quaternion class of four is the unit of four yuan, even if the x^2+y^2+z^2+w^2==1, and Nx^2+ny^2+nz^2==1.

So, the question is, for n four-dollar number, we have also obtained the corresponding n weight value, now how to find the mixed value?

First on the code:

1 //calculates the power of a four-dollar number2     Static  Publicquaternion quaternion_exp (quaternion q,floatexp)3     {4         //if w==1, then W==cos (THETA/2), theta/2==360, then sin (theta/2) ==05         //if w>1, the input four Yuan is not the unit four Yuan number6         if(q.w>=1.0f)7         {8             returnquaternion.identity;9         }Ten         //Calculate THETA/2 One         floatTheta_2=Mathf.acos (Q.W); A         //a power of four is exp, which equals the rotation angle multiplied by exp -         floatnewtheta_2=theta_2*exp; -         floatneww=Mathf.cos (newtheta_2); the         //in order to make the newly constructed four-dollar number also conforms to the unit four-dollar definition -         //i.e. [W,x,y,z]=[cos (THETA/2), sin (THETA/2) *nx,sin (THETA/2) *ny,sin (THETA/2) *NZ] -         floatMult=mathf.sin (newtheta_2)/Mathf.sin (theta_2); -         floatnewx=q.x*mult; +         floatnewy=q.y*mult; -         floatnewz=q.z*mult; +Quaternion result=Newquaternion (NEWX,NEWY,NEWZ,NEWW); A         returnresult; at}

This code is the power of the four-dollar algorithm, why the power of the request?

Because we're going to interpolate the four-dollar number. The so-called interpolation, is necessarily the weight of the value multiplied by the "specific geometric meaning value", and then get a reasonable median value of the process.

The "specific geometrical meaning value" here is the degree of rotation.

For example, a four-dollar Q (SIN60*NX,SIN60*NY,SIN60*NZ,COS60), which represents a 30-degree rotation around the (NX,NY,NZ) axis, at which time q^k represents the rotation 30*k degrees around (NX,NY,NZ).

Specific proof not to repeat, recommended reference "3D Mathematical Fundamentals: Graphics and Game development" 153 pages.

So here we know very well that the Rotation provided by each keyframe should finally be provided to the preset point in the form of rotation^ (Weight_i/sum_weight).

And then what? How does the operation of the addition, in the four-dollar number, be manifested here?

The answer is: four-dollar cross-multiply, four-dollar number fork by geometric meaning is connected to two rotations.

So, the rotation value of the preset point, the formula for the mixed calculation should be this:r1^ (weight_1/sum_weight) *r2^ (weight_2/sum_weight) *...*rn^ (weight_n/sum_weight).

With a four-tuple multiplication, the quaternion operator overload is provided in Unity3d and is used directly.

Action interpolation based on Unity3d three-dimensional model (implementation of space key frame animation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.