-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@2018.2
- Loading branch information
Showing
54 changed files
with
2,994 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
About Animation C# Jobs Samples | ||
=============================== | ||
|
||
The Animation C# Jobs Samples package includes examples of Playable graphs | ||
using Animation C# Jobs. For more information, see | ||
[AnimationScriptPlayable](https://docs.unity3d.com/ScriptReference/Experimental.Animations.AnimationScriptPlayable.html). | ||
|
||
Installing Animation C# Jobs Samples | ||
==================================== | ||
|
||
To install this package, follow the instructions in the | ||
[Package Manager documentation](https://docs.unity3d.com/Packages/com.unity.package-manager-ui@latest/index.html). | ||
|
||
Using Animation C# Jobs Samples | ||
=============================== | ||
|
||
Because package content is read-only, it is not possible to open scenes | ||
directly from a package directory, but it is possible to copy the scene files | ||
locally, in the `Assets` folder. | ||
|
||
To do so, go to `Packages/Animation C# Jobs Samples/Samples/Scenes`, then | ||
select the sample scenes you want to try, and copy them into your `Assets` | ||
folder. | ||
|
||
Once copied, go to your `Assets` folder and open the Unity scene that you would | ||
like to test. | ||
|
||
Samples | ||
------- | ||
|
||
### SimpleMixer | ||
|
||
This sample shows how to mix two clips together on a generic character. | ||
|
||
### WeightedMaskMixer | ||
|
||
This sample is based on the SimpleMixer, but you can change the weights of some | ||
joints (left arm, right arm, and head), so that the second clip only applies | ||
based on the joint weights. | ||
|
||
### LookAt | ||
|
||
This sample adds a look-at behaviour on a Chomper, a quadruped creature from the | ||
[3D Game Kit](https://assetstore.unity.com/packages/essentials/tutorial-projects/3d-game-kit-115747). | ||
|
||
### TwoBoneIK | ||
|
||
This sample adds a two-bone IK on a generic human character. | ||
|
||
### FullBodyIK | ||
|
||
This sample create a fullbody IK on a humanoid character. | ||
|
||
Technical details | ||
================= | ||
|
||
Requirements | ||
------------ | ||
|
||
This version of Animation C# Jobs Samples is compatible with Unity 2018.2 and | ||
later. | ||
|
||
The [GraphVisualizer](https://github.com/Unity-Technologies/graph-visualizer) | ||
can be used to have a visual representation of the graphs in the samples. | ||
|
||
Package contents | ||
---------------- | ||
|
||
The following table indicates the structure of the package: | ||
|
||
| Location | Description | | ||
|---------------------------|-----------------------------------------------------------------------------------------------| | ||
| `Resources` | Contains all the resources that the samples need (e.g. meshes, textures, animations, ...). | | ||
| `Runtime/AnimationJobs` | Contains all the animation C# jobs. | | ||
| `Samples/Scenes` | Contains all the sample scenes. | | ||
| `Samples/Scripts` | Contains all the sample scripts. | | ||
|
||
Document revision history | ||
------------------------- | ||
|
||
| Date | Reason | | ||
|---------------|---------------------------------------| | ||
| June 01, 2018 | New way of testing the samples. | | ||
| May 30, 2018 | First public release: 0.5.0-preview. | | ||
| May 07, 2018 | Creation of the package. | |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using UnityEngine; | ||
using UnityEngine.Playables; | ||
using UnityEngine.Animations; | ||
using UnityEngine.Experimental.Animations; | ||
|
||
public struct FullBodyIKJob : IAnimationJob | ||
{ | ||
public struct EffectorHandle | ||
{ | ||
public TransformSceneHandle effector; | ||
public PropertySceneHandle positionWeight; | ||
public PropertySceneHandle rotationWeight; | ||
} | ||
|
||
public struct HintEffectorHandle | ||
{ | ||
public TransformSceneHandle hint; | ||
public PropertySceneHandle weight; | ||
} | ||
|
||
public struct LookEffectorHandle | ||
{ | ||
public TransformSceneHandle lookAt; | ||
public PropertySceneHandle eyesWeight; | ||
public PropertySceneHandle headWeight; | ||
public PropertySceneHandle bodyWeight; | ||
public PropertySceneHandle clampWeight; | ||
} | ||
|
||
public struct BodyEffectorHandle | ||
{ | ||
public TransformSceneHandle body; | ||
} | ||
|
||
public EffectorHandle leftFootEffector; | ||
public EffectorHandle rightFootEffector; | ||
public EffectorHandle leftHandEffector; | ||
public EffectorHandle rightHandEffector; | ||
|
||
public HintEffectorHandle leftKneeHintEffector; | ||
public HintEffectorHandle rightKneeHintEffector; | ||
public HintEffectorHandle leftElbowHintEffector; | ||
public HintEffectorHandle rightElbowHintEffector; | ||
|
||
public LookEffectorHandle lookAtEffector; | ||
|
||
public BodyEffectorHandle bodyEffector; | ||
|
||
private void SetEffector(AnimationStream stream, AvatarIKGoal goal, ref EffectorHandle handle) | ||
{ | ||
if (handle.effector.IsValid(stream) && handle.positionWeight.IsValid(stream) && handle.rotationWeight.IsValid(stream)) | ||
{ | ||
AnimationHumanStream humanStream = stream.AsHuman(); | ||
humanStream.SetGoalPosition(goal, handle.effector.GetPosition(stream)); | ||
humanStream.SetGoalRotation(goal, handle.effector.GetRotation(stream)); | ||
humanStream.SetGoalWeightPosition(goal, handle.positionWeight.GetFloat(stream)); | ||
humanStream.SetGoalWeightRotation(goal, handle.rotationWeight.GetFloat(stream)); | ||
} | ||
} | ||
|
||
private void SetHintEffector(AnimationStream stream, AvatarIKHint goal, ref HintEffectorHandle handle) | ||
{ | ||
if (handle.hint.IsValid(stream) && handle.weight.IsValid(stream)) | ||
{ | ||
AnimationHumanStream humanStream = stream.AsHuman(); | ||
humanStream.SetHintPosition(goal, handle.hint.GetPosition(stream)); | ||
humanStream.SetHintWeightPosition(goal, handle.weight.GetFloat(stream)); | ||
} | ||
} | ||
|
||
private void SetLookAtEffector(AnimationStream stream, ref LookEffectorHandle handle) | ||
{ | ||
if (handle.lookAt.IsValid(stream)) | ||
{ | ||
AnimationHumanStream humanStream = stream.AsHuman(); | ||
humanStream.SetLookAtPosition(handle.lookAt.GetPosition(stream)); | ||
humanStream.SetLookAtEyesWeight(handle.eyesWeight.GetFloat(stream)); | ||
humanStream.SetLookAtHeadWeight(handle.headWeight.GetFloat(stream)); | ||
humanStream.SetLookAtBodyWeight(handle.bodyWeight.GetFloat(stream)); | ||
humanStream.SetLookAtClampWeight(handle.clampWeight.GetFloat(stream)); | ||
} | ||
} | ||
|
||
private void SetBodyEffector(AnimationStream stream, ref BodyEffectorHandle handle) | ||
{ | ||
if (handle.body.IsValid(stream)) | ||
{ | ||
AnimationHumanStream humanStream = stream.AsHuman(); | ||
humanStream.bodyRotation = handle.body.GetRotation(stream); | ||
} | ||
} | ||
|
||
private void Solve(AnimationStream stream) | ||
{ | ||
AnimationHumanStream humanStream = stream.AsHuman(); | ||
|
||
Vector3 bodyPosition = humanStream.bodyPosition; | ||
Vector3 bodyPositionDelta = Vector3.zero; | ||
float sumWeight = 0; | ||
|
||
for (int goalIter = 0; goalIter < 4; goalIter++) | ||
{ | ||
float weight = humanStream.GetGoalWeightPosition((AvatarIKGoal)goalIter); | ||
weight = Mathf.Clamp01(weight); | ||
bodyPositionDelta += (humanStream.GetGoalPosition((AvatarIKGoal)goalIter) - humanStream.GetGoalPositionFromPose((AvatarIKGoal)goalIter)) * weight; | ||
sumWeight += weight; | ||
} | ||
|
||
if (sumWeight > 1) | ||
{ | ||
bodyPositionDelta /= sumWeight; | ||
} | ||
|
||
bodyPosition += bodyPositionDelta; | ||
humanStream.bodyPosition = bodyPosition; | ||
|
||
if (bodyEffector.body.IsValid(stream)) | ||
{ | ||
bodyEffector.body.SetPosition(stream, bodyPosition); | ||
} | ||
|
||
humanStream.SolveIK(); | ||
} | ||
|
||
public void ProcessRootMotion(AnimationStream stream) { } | ||
|
||
public void ProcessAnimation(AnimationStream stream) | ||
{ | ||
SetEffector(stream, AvatarIKGoal.LeftFoot, ref leftFootEffector); | ||
SetEffector(stream, AvatarIKGoal.RightFoot, ref rightFootEffector); | ||
SetEffector(stream, AvatarIKGoal.LeftHand, ref leftHandEffector); | ||
SetEffector(stream, AvatarIKGoal.RightHand, ref rightHandEffector); | ||
|
||
SetHintEffector(stream, AvatarIKHint.LeftKnee, ref leftKneeHintEffector); | ||
SetHintEffector(stream, AvatarIKHint.RightKnee, ref rightKneeHintEffector); | ||
SetHintEffector(stream, AvatarIKHint.LeftElbow, ref leftElbowHintEffector); | ||
SetHintEffector(stream, AvatarIKHint.RightElbow, ref rightElbowHintEffector); | ||
|
||
SetLookAtEffector(stream, ref lookAtEffector); | ||
|
||
SetBodyEffector(stream, ref bodyEffector); | ||
|
||
Solve(stream); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.