Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Setting Keyframes for Object Position

 Post Reply Post Reply
Author
Message
SSDW View Drop Down
Member
Member


Joined: 2006 Jan 03
Location: Germany
Online Status: Offline
Posts: 58
Post Options Post Options   Quote SSDW Quote  Post ReplyReply Direct Link To This Post Topic: Setting Keyframes for Object Position
    Posted: 2010 Mar 03 at 10:55am

User Information:

Cinema 4D Version:   10 
Platform:   Windows  ;   
Language(s):     C++  ;  

---------

Hi,

I have created a CommandData plugin that adds an object to an existing scene and makes it follow a certain pre-defined path. For this I am setting the keyframes for the position of the object, i.e.


CTrack *bodyTrack = CTrack::Alloc(bodyOp,DescLevel(ID_BASEOBJECT_POSITION,DTYPE_VECTOR,0));
if (!bodyTrack)     { return FALSE; }
bodyOp->InsertTrackSorted(bodyTrack);
CKey *bodyKey = NULL;
for (LONG simCount = 0; simCount<=simRuns; simCount++)
{
Vector posVector = ComputeCoords(body,time);
bodyKey = bodyTrack->GetCurve()->AddKey(BaseTime(simCount,framerate),NULL);
bodyKey->SetGeData(bodyTrack->GetCurve(),posVector);          
time++;
}


It seems to work, and I see all the keyframes and the object moves. However, I was expecting to also see these keyframes in the Attribute Manager (i.e. in the object description) and also to see the path in the editor window (like it happens when I manually change the position and set the keyframe). Why is that not shown? What do I have to do to show it?

Thanks,
Juergen
Back to Top
c4dJack View Drop Down
Member
Member
Avatar

Joined: 2007 Jul 13
Location: Turkey
Online Status: Offline
Posts: 454
Post Options Post Options   Quote c4dJack Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Mar 03 at 3:02pm

Does it show after you moved the timeslider? If yes, it's just a refresh/redraw problem.

If not, I also don't know.

Cheers,
Jack



Edited by c4dJack - 2010 Mar 03 at 3:04pm
"Violets are blue. Roses are red.
We're coming aboard. Prepare to eat lead."

Rapp Scallion
Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 1644
Post Options Post Options   Quote Matthias Bober Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Mar 04 at 8:18am
Make sure to inform the object and managers about the changes.


bodyOp->Message(MSG_UPDATE);

EventAdd();


cheers,
Matthias

MAXON
developer support
Back to Top
SSDW View Drop Down
Member
Member


Joined: 2006 Jan 03
Location: Germany
Online Status: Offline
Posts: 58
Post Options Post Options   Quote SSDW Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Mar 08 at 12:15pm
Hi Matthias,

I am doing that. I have the keyframes and the objects are moving in the scene.

I just don't see the object path in the editor window and the respective coordinate fields in the attribute manager are not highlighted. I don't care so much about the latter, but is there a way to make the path show up as a spline in the editor window?

Juergen
Back to Top
MWittav View Drop Down
Member
Member


Joined: 2010 Feb 16
Location: Germany
Online Status: Offline
Posts: 21
Post Options Post Options   Quote MWittav Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Mar 09 at 11:28pm
I find it worrysome that it moves correctly but doesn't highlight the coordinates in the attribute manager.

How about


    CCurve *seq=bodyTrack->GetCurve();
    bodyKey=CKey::Alloc();
    bodyKey->SetGeData(seq,posVector);
    bodyKey->SetTime(seq,BaseTime(simCount,framerate));
    key->SetInterpolation(seq,CINTER_STEP);
    if (!(seq->InsertKey(key))) {
        GeConsoleOut(String("I'm in trouble :-)"));
    }


That way you'll already have the correct values at the time you make the key known to Cinema 4D and you don't have to worry about refreshing.
I'm using this code snippet in a project of mine and I see the object path just fine in the editor.

Best regards
Mike

Back to Top
Matthias Bober View Drop Down
Forum Moderator
Forum Moderator


Joined: 2006 Oct 16
Location: Germany
Online Status: Offline
Posts: 1644
Post Options Post Options   Quote Matthias Bober Quote  Post ReplyReply Direct Link To This Post Posted: 2010 Mar 15 at 2:02am
The error lies in your track allocation and key creation. Position tracks are three independent Real tracks.

Have a look at following code, it should be pretty much self explainatory:

Bool MenuTest::Execute(BaseDocument *doc)
{
    BaseObject *op = doc->GetActiveObject();

    if (!op) return FALSE;

    StopAllThreads();

    CTrack *trackX = NULL;
    CTrack *trackY = NULL;
    CTrack *trackZ = NULL;

    trackX = CTrack::Alloc(op,DescID(DescLevel(ID_BASEOBJECT_POSITION,DTYPE_VECTOR,0),DescLevel(VECTOR_X,DTYPE_REAL,0)));
    if (!trackX) goto Error;

    trackY = CTrack::Alloc(op,DescID(DescLevel(ID_BASEOBJECT_POSITION,DTYPE_VECTOR,0),DescLevel(VECTOR_Y,DTYPE_REAL,0)));
    if (!trackY) goto Error;

    trackZ = CTrack::Alloc(op,DescID(DescLevel(ID_BASEOBJECT_POSITION,DTYPE_VECTOR,0),DescLevel(VECTOR_Z,DTYPE_REAL,0)));
    if (!trackZ) goto Error;

    op->InsertTrackSorted(trackX);
    op->InsertTrackSorted(trackY);
    op->InsertTrackSorted(trackZ);

    CKey *key = NULL;
   
    //add keys add 0s
    key = trackX->GetCurve()->AddKey(BaseTime()); if (!key) return FALSE;
    key->SetValue(trackX->GetCurve(), 100.0);

    key = trackY->GetCurve()->AddKey(BaseTime()); if (!key) return FALSE;
    key->SetValue(trackY->GetCurve(), 100.0);

    key = trackZ->GetCurve()->AddKey(BaseTime()); if (!key) return FALSE;
    key->SetValue(trackZ->GetCurve(), 100.0);

    //add keys at 1s
    key = trackX->GetCurve()->AddKey(BaseTime(1.0)); if (!key) return FALSE;
    key->SetValue(trackX->GetCurve(), 0.0);

    key = trackY->GetCurve()->AddKey(BaseTime(1.0)); if (!key) return FALSE;
    key->SetValue(trackY->GetCurve(), 0.0);

    key = trackZ->GetCurve()->AddKey(BaseTime(1.0)); if (!key) return FALSE;
    key->SetValue(trackZ->GetCurve(), 0.0);

    op->Message(MSG_UPDATE);
    EventAdd();

    return TRUE;

Error:
    blDelete(trackX);
    blDelete(trackY);
    blDelete(trackZ);
    return FALSE;
}


cheers,
Matthias

MAXON
developer support
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.094 seconds.