Skip to content

Commit

Permalink
0.6.0-preview - 2018/06/01
Browse files Browse the repository at this point in the history
@2018.2
  • Loading branch information
ErikMoczi committed Sep 3, 2018
1 parent cacb434 commit 0cd061f
Show file tree
Hide file tree
Showing 54 changed files with 2,994 additions and 41 deletions.
74 changes: 70 additions & 4 deletions package/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,75 @@ All notable changes to this package will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.1.0] - 2018-05-07
## [Unreleased]

### This is the first release of *Unity Package Animation C# Jobs Samples*.
### Added

- New installation steps: copy-paste the Unity scene files in your `Assets` folder.

### Changed

- Better CHANGELOG.md.
- Animation C# jobs are now in `Runtime/AnimationJobs/`.
- Sample scripts are now in `Samples/Scripts`.
- Sample scenes are now in `Samples/Scenes`.
- Fix warning about the unused `weight` variable.

### Removed

- The .unitypackagefile in favor of copy-pasting the Unity scene files directly.

## [0.5.0-preview] - 2018-05-30

### Changed

- First version into production.

## [0.4.0] - 2018-05-30

### Added

- A unitypackage file for the scenes.

### Fixed

- Some errors when disabling and re-enabling scripts.

## [0.3.0] - 2018-05-28

### Added

- New sample: LookAt.
- The Chomper model from [3D Game Kit](https://assetstore.unity.com/packages/essentials/tutorial-projects/3d-game-kit-115747).

### Changed

- Rename sample BoneWeightMask to WeightedMaskMixer.

## [0.2.0] - 2018-05-24

### Added

- New sample: SimpleMixer.
- A humanoid and a generic DefaultMale FBX files with Idle and ROM animations
for both (see `Resources/DefaultMale/Models/`).

### Changed

- Rename sample CustomMixer to BoneWeightMask.
- Improve the TwoBoneIK script.
- Factorize utility functions in `SampleUtility.cs`

## 0.1.0 - 2018-05-07

### Added

- New samples: CustomMixer, FullBodyIK, and TwoBoneIK.
- First release of *Unity Package Animation C# Jobs Samples*.

[Unreleased]: https://gitlab.internal.unity3d.com/upm-packages/animation/com.unity.animation.cs-jobs-samples/compare/v0.5.0-preview...HEAD
[0.5.0-preview]: https://gitlab.internal.unity3d.com/upm-packages/animation/com.unity.animation.cs-jobs-samples/v0.4.0...v0.5.0-preview
[0.4.0]: https://gitlab.internal.unity3d.com/upm-packages/animation/com.unity.animation.cs-jobs-samples/v0.3.0...v0.4.0
[0.3.0]: https://gitlab.internal.unity3d.com/upm-packages/animation/com.unity.animation.cs-jobs-samples/v0.2.0...v0.3.0
[0.2.0]: https://gitlab.internal.unity3d.com/upm-packages/animation/com.unity.animation.cs-jobs-samples/compare/v0.1.0...v0.2.0

First set of examples for the Animation C# Jobs feature. It includes
CutsomMixer, FullBodyIK, and TwoBoneIK.
85 changes: 85 additions & 0 deletions package/Documentation~/cs-jobs-samples.md
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. |
7 changes: 7 additions & 0 deletions package/Documentation~/cs-jobs-samples.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 1 addition & 35 deletions package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,4 @@ system is required.
How to use this package
-----------------------

Go to the `Packages/Animation C# Jobs Samples/Samples` directory and import `SampleScenes.unitypackage`.

Once imported, go to your `Assets` directory 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.

See also
--------

The [GraphVisualizer](https://github.com/Unity-Technologies/graph-visualizer)
allows to dynamically see all the Playable graphs in the scene.
See the [documentation](Documentation~/cs-jobs-samples.md).
8 changes: 8 additions & 0 deletions package/Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions package/Runtime/AnimationJobs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

145 changes: 145 additions & 0 deletions package/Runtime/AnimationJobs/FullBodyIKJob.cs
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);
}
}
11 changes: 11 additions & 0 deletions package/Runtime/AnimationJobs/FullBodyIKJob.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0cd061f

Please sign in to comment.