record animation

432 views
Skip to first unread message

Christos Mousas

unread,
Feb 22, 2012, 5:45:03 PM2/22/12
to unitykinect
Hi there...

I found this post (http://answers.unity3d.com/questions/28580/
recording-animations.html) for animation capture and i am trying to
implemented in my Unity-Kinect...
My code now looks like

var object : Transform;
var clip1 : AnimationClip;
var posXCurve;
var posYCurve;
var posZCurve;
var rotXCurve;
var rotYCurve;
var rotZCurve;
var rotX2Curve;
var rotY2Curve;
var rotZ2Curve;
static var recStart : boolean;
static var isRecording : boolean;
static var recMode = false;
static var stopMode = false;
static var playMode = false;


function OnGUI() {
// Make a background box
GUI.Box (Rect (10,10,100,120), "Motion Capture");

if (GUI.Button (Rect (20,40,80,20), "Record")) {
recMode = true;
stopMode = false;
playMode = false;
}
if (GUI.Button (Rect (20,70,80,20), "Stop")) {
recMode = false;
stopMode = true;
playMode = false;
}
if (GUI.Button (Rect (20,100,80,20), "Play")) {
recMode = false;
stopMode = false;
playMode = true;
}
}


function startRec(){
posXCurve = new AnimationCurve();
posYCurve = new AnimationCurve();
posZCurve = new AnimationCurve();
rotXCurve = new AnimationCurve();
rotYCurve = new AnimationCurve();
rotZCurve = new AnimationCurve();
rotX2Curve = new AnimationCurve();
rotY2Curve = new AnimationCurve();
rotZ2Curve = new AnimationCurve();
recStart = true;
isRecording = true;
print("RECORDING");
}

function stopRec(){

isRecording = false;
clip1.SetCurve("", Transform, "localPosition.x", posXCurve);
clip1.SetCurve("", Transform, "localPosition.y", posYCurve);
clip1.SetCurve("", Transform, "localPosition,z", posZCurve);
clip1.SetCurve("", Transform, "localRotation,x", rotXCurve);
clip1.SetCurve("", Transform, "localRotation,y", rotYCurve);
clip1.SetCurve("", Transform, "localRotation,z", rotZCurve);
clip1.SetCurve("_d_camera", Transform, "localRotation,x",
rotX2Curve);
clip1.SetCurve("_d_camera", Transform, "localRotation,y",
rotY2Curve);
clip1.SetCurve("_d_camera", Transform, "localRotation,z",
rotZ2Curve);

object.animation.AddClip (clip1, "aniMo");
print("STOPPED!!");
}

function playAnim(){
object.animation.Play("aniMo");
print("Playing");
}

function Update(){
if(recMode){
startRec();
}else if(stopMode){
stopRec();
}else if(playMode){
playAnim();
}else{
}
}

/*mainObj is the same GameObject that is being used when you add
keyframes to the
position curve and it is recording the localRotation instead of the
localEulerAngles.*/
function LateUpdate(){
if(recStart) {
nowTime = 0;
recStart = false;
}

if(isRecording){
posXCurve.AddKey(nowTime, object.transform.localPosition.x);
posYCurve.AddKey(nowTime, object.transform.localPosition.y);
posZCurve.AddKey(nowTime, object.transform.localPosition.z);
rotXCurve.AddKey(nowTime, object.transform.localEulerAngles.x);
rotYCurve.AddKey(nowTime, object.transform.localEulerAngles.y);
rotZCurve.AddKey(nowTime, object.transform.localEulerAngles.z);
rotX2Curve.AddKey(nowTime,
object.transform.localEulerAngles.x);
rotY2Curve.AddKey(nowTime,
object.transform.localEulerAngles.y);
rotZ2Curve.AddKey(nowTime,
object.transform.localEulerAngles.z);

nowTime = nowTime + Time.deltaTime;
}
}

When I am trying to record he motion it puts just only one keyframe...
Do you know why this doesn't work??

Christos Mousas

unread,
Feb 23, 2012, 6:12:00 PM2/23/12
to unitykinect
OK i found the problem.... The following capture the translation and
rotation of an object.... Now I have another question.... In order to
capture the whole human body movements using unity and kinect I should
have more than one .anim archives and every body part should attached
to a Transform object in unity? Is it posible to capture the whole
body unsing one single .anim file to store the movements??? Any
suggestion????

Thanks
Chris

var clip1 : AnimationClip;
var obj : Transform;
static var recStart = false;
static var isRecording = false;
static var nowTime;
static var posXCurve;
static var posYCurve;
static var posZCurve;
static var rotXCurve;
static var rotYCurve;
static var rotZCurve;
static var rotX2Curve;
static var rotY2Curve;
static var rotZ2Curve;

function OnGUI () {
GUI.Box (Rect (10,10,100,120), "Motion Capture");
if (GUI.Button (Rect (20,40,80,20), "Rec")) {
startRec();
}
if (GUI.Button (Rect (20,70,80,20), "Stop")) {
stopRec();
}
if (GUI.Button (Rect (20,100,80,20), "Play")) {
playAnim();
}
}

function startRec() {
    posXCurve = new AnimationCurve();
    posYCurve = new AnimationCurve();
    posZCurve = new AnimationCurve();
    rotXCurve = new AnimationCurve();
    rotYCurve = new AnimationCurve();
    rotZCurve = new AnimationCurve();
    rotX2Curve = new AnimationCurve();
    rotY2Curve = new AnimationCurve();
    rotZ2Curve = new AnimationCurve();
    recStart = true;
    isRecording = true;
    print("REC");
}

function stopRec() {

    isRecording = false;
    clip1.SetCurve("", Transform, "localPosition.x", posXCurve);
    clip1.SetCurve("", Transform, "localPosition.y", posYCurve);
    clip1.SetCurve("", Transform, "localPosition.z", posZCurve);

    clip1.SetCurve("", Transform, "localRotation.x", rotXCurve);
    clip1.SetCurve("", Transform, "localRotation.y", rotYCurve);
    clip1.SetCurve("", Transform, "localRotation.z", rotZCurve);

    clip1.SetCurve("_d_camera", Transform, "localRotation.x",
rotX2Curve);
    clip1.SetCurve("_d_camera", Transform, "localRotation.y",
rotY2Curve);
    clip1.SetCurve("_d_camera", Transform, "localRotation.z",
rotZ2Curve);

    obj.animation.AddClip (clip1, "aniMo");
print("STOPPED!!");
}

function playAnim() {
    obj.animation.Play("aniMo");
    print("PLAY");
}

function FixedUpdate () {
    if(recStart) {
        nowTime = 0;
        recStart = false;
    }

    if(isRecording){
        posXCurve.AddKey(nowTime, obj.transform.localPosition.x);
        posYCurve.AddKey(nowTime, obj.transform.localPosition.y);
        posZCurve.AddKey(nowTime, obj.transform.localPosition.z);

        rotXCurve.AddKey(nowTime, obj.transform.localRotation.x);
rotYCurve.AddKey(nowTime, obj.transform.localRotation.y);
rotZCurve.AddKey(nowTime, obj.transform.localRotation.z);

        rotX2Curve.AddKey(nowTime, obj.transform.localRotation.x);
        rotY2Curve.AddKey(nowTime, obj.transform.localRotation.y);
        rotZ2Curve.AddKey(nowTime, obj.transform.localRotation.z);

        nowTime = nowTime + Time.deltaTime;
        print(nowTime);

Amir Hirsch

unread,
Feb 24, 2012, 2:14:51 AM2/24/12
to unity...@googlegroups.com, unitykinect
I think you can use a single anim that specifies the start time and stop time for each subcomponent, but I'm not in front of a pc.

We have code in our openni package for dumping and playing back json data on our skeleton controller. We should talk about features for a mocap suite for unity devs. We can easily store point clouds and let you use nonrealtime and noncausal filters to analyze the data.

Cheers!

People love us on github.com/zigfu

SteveElbows

unread,
Feb 26, 2012, 2:58:09 PM2/26/12
to unitykinect
When I tried to do something similar quite a long time ago, I cut
corners by buying the 'physics to animation tool' from the Unity Asset
Store because it does something similar and there code is all there to
see how it works. And Im pretty sure it captures the animation of
multiple objects into a single animation clip, as thats the entire
reason I wanted to use it in the first place.

Im just about to try some of this stuff again after a long break but
it won't really be fair of me to reveal every detail of a commercially
available script. But in a nutshell they have a script that goes on
the parent which ensures that another script is attachéd to every
child (which in this case will be all of the joint transforms) and
this script deals with recording the data into a animation clip that
is attached to the parent, and making sure that these curves are
associated with the right child.

Cheers

Steve

On Feb 24, 7:14 am, Amir Hirsch <a...@kinectarcade.com> wrote:
> I think you can use a single anim that specifies the start time and stop time for each subcomponent, but I'm not in front of a pc.
>
> We have code in our openni package for dumping and playing back json data on our skeleton controller. We should talk about features for a mocap suite for unity devs. We can easily store point clouds and let you use nonrealtime and noncausal filters to analyze the data.
>
> Cheers!
>
> People love us on github.com/zigfu
>

SteveElbows

unread,
Feb 26, 2012, 3:18:22 PM2/26/12
to unitykinect
Another thing to consider when writing code for this sort of thing is
whether you should be recording the position of all the joint
transforms. If you have an OpenNI skeleton linked up to a proper set
of bones, which have a heirarchy, then you will normally just want to
record their rotation, not position like your code currently does. The
exception is the root bone, which you may want to record the position
of if you are allowing your character moves around in space using
OpenNI data.

Obviously this is not true if you are driving something else via
position data rather than rotation, e.g. a set of primitive objects
whose transforms are completely independent and do not influence each
other.

Cheers

Steve
> ...
>
> read more »

Amir Hirsch

unread,
Feb 28, 2012, 4:52:08 PM2/28/12
to unity...@googlegroups.com
I did a bit of work on an inverse kinematics system to stabilize a ragdoll character positions using fixed joints to invisible rigid bodies positioned by the kinect data. the issue here is scaling the invisible "blockman" to match the user to the character and adding constraints to the block-man's motion avoid character instabilities. the other thing to add to this sort of system is a IK system for the legs kind of like Unity's locomotion system and using inference about the user's feet position to stabilize the character's lower body and detect if the feet should be on the ground.

this kind of advanced retargeting stuff will have to come later...

Amir

Dave A

unread,
Jan 14, 2013, 6:40:36 PM1/14/13
to unity...@googlegroups.com
Been a long time, any news on this?
Reply all
Reply to author
Forward
0 new messages