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

BaseTime and doc->SetTime()

 Post Reply Post Reply
Author
Message
WickedP View Drop Down
Member
Member
Avatar

Joined: 2011 Aug 21
Online Status: Offline
Posts: 458
Post Options Post Options   Quote WickedP Quote  Post ReplyReply Direct Link To This Post Topic: BaseTime and doc->SetTime()
    Posted: 2017 Sep 09 at 7:29pm

User Information:

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

---------

Hi folks,

Edit: same thing happens in the main thread too.

I'm running a threaded operation where I'm playing back a scene in memory. Nothing fancy, just trying to make the document increment one frame at a time. I'm doing this by:

//psuedo code, doc is in memory only

BaseTime tm;
tm.SetDenominator(1.0);

// for the purposes of here, lets assume we're wanting frame 23
tm.SetNumerator(1.0/doc->GetFps()*23);

doc->SetTime(tm); // does not set to frame 23
doc->ExecutePasses(this->Get(),TRUE,TRUE,TRUE,BUILDFLAGS_0); // always returns TRUE

// this always returns RENDERESULT_OK
REDERESULT render = RenderDocument(doc,rdata,nullptr,nullptr,Multipass,RENDERFLAGS_EXTERNAL|RENDERFLAGS_NODOCUMENTCLONE|RENDERFLAGS_PREVIEWRENDER,this->Get());

// if I print the frames from the basetime and the doc, this is what I get
GePrint("Time frame = " + RealToString(tm.GetFrame(..)); // CORRECT 23
GePrint("doc frame = " + RealToString(doc->GetTime().GetFrame(doc->GetFps()))); // INCORRECT 0

The problem I'm having is that the document is not animated to the correct frame. What I have noticed, is that the document changes time based on the frame rate. So if the frame rate is 30fps, then when I set the document time with any frame from 0-29, it only executes frame 0, and when the frame count reaches frame 30 the document is then set to the correct frame. The same thing happens from frames 30-59, the doc doesn't change until it gets to frame 60. It seems to go in multiples of the frame rate.

Is there something about BaseTime I'm not understanding, or doc->SetTime()? Is there something about doing this in a threaded environment means it won't animate correctly? Or, is this another issue, some function call I've missed? An incorrect flag? Something in my math? Something else?

WP.


Edited by WickedP - 2017 Sep 09 at 8:05pm
WickedP® Developer
http://www.wickedp.com
Back to Top
spedler View Drop Down
Member
Member


Joined: 2008 Apr 19
Location: United Kingdom
Online Status: Online
Posts: 673
Post Options Post Options   Quote spedler Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 10 at 12:36am
Set the numerator to the desired frame (23) and the denominator to the document frame rate (e.g 30). This will set the time to 23/30ths of a second.

Steve
Back to Top
WickedP View Drop Down
Member
Member
Avatar

Joined: 2011 Aug 21
Online Status: Offline
Posts: 458
Post Options Post Options   Quote WickedP Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 10 at 2:14am
Hi Steve,

that's what I originally had, which is why I changed it to the above, to try something different (loosely based off some code I saw here somewhere). I was under the impression BaseTime worked as a fraction, e.g. 3 over 25, or 0.25 over 1.0, and that it didn't matter so much the values you set it with but the fraction value it's worth (if that makes sense!).

I changed it back, and the issue is still there, although I can see that the doc time is now showing the correct frame. But it's still not drawing the correct frame.

WP.
WickedP® Developer
http://www.wickedp.com
Back to Top
WickedP View Drop Down
Member
Member
Avatar

Joined: 2011 Aug 21
Online Status: Offline
Posts: 458
Post Options Post Options   Quote WickedP Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 11 at 2:47am
Don't know if it's RenderDocument() doing something here or not. I can GePrint() the correct frame just before I render it, but the rendered frame is not the correct frame.

// prints correct frame
GePrint("Rendering frame " + RealToString(doc->GetTime().GetFrame(Animation->GetFps())));
BaseContainer rdata;
Set_RenderData(&rdata,Width,Height);  // sets some default render settings
rdata.SetTime(RDATA_FRAMEFROM,doc->GetTime());
rdata.SetTime(RDATA_FRAMETO,doc->GetTime());

// renders incorrect frame
RENDERRESULT Result = RenderDocument(doc,rdata,nullptr,nullptr,Renderer,RENDERFLAGS_EXTERNAL|RENDERFLAGS_NODOCUMENTCLONE,Thread);

WP.
WickedP® Developer
http://www.wickedp.com
Back to Top
WickedP View Drop Down
Member
Member
Avatar

Joined: 2011 Aug 21
Online Status: Offline
Posts: 458
Post Options Post Options   Quote WickedP Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 11 at 3:00am
D'oh! I wasn't setting the frame rate in the render container!

I'll see myself out. Tongue

WP.
WickedP® Developer
http://www.wickedp.com
Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Offline
Posts: 1482
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Sep 11 at 9:32am
Hi,

I'm glad you found your problem. Don't feel bad about it, we all have these days...

For everybody reading this thread in future:
1) As steve pointed out, the code in the first post does not properly set BaseTime.
2) The manuals on BaseDocument (Animate) and BaseTime may help on this topic.

Cheers,
Andreas
SDK Support Engineer
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.