Execute once per frame



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/05/2011 at 08:29, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   12 
    Platform:      
    Language(s) :     C++  ;

    ---------
    I don't like asking silly questions here, but I've been puzzling over this for two days and still can't figure it out, so here goes.

    I'm writing an ObjectData plugin. I want an action to be carried out once per frame - just once, on each frame. I tried using GetVirtualObjects (it's a generator plugin) but that seems to be called multiple times per frame, which is no good.

    Am I: a) missing something obvious, b) trying to force Cinema to work in a way it's not supposed to, or c) just thick as a plank?

    Can anyone offer any hints on what I should be doing?

    Many thanks,

    Steve



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/05/2011 at 09:17, xxxxxxxx wrote:

    I don't know if you missed something obvious, because I don't program in C++.
    But if a is not the point, then you may try this (pseudo)code

    class Object() {  
      bool lastTimeExecuted;  
      //and everything else  
    }  
    Object::GetVirtualObjects(doc, op, etc) {  
      time                    = doc->GetTime()->GetSecond();  
      if (time != this.lastTimeExecuted) {  
          //Do your stuff  
      }  
      this.lastTimeExecuted   = time;  
      return EXECUTIONRESULT_OK;  
    }
    

    Cheers, Niklas



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 20/05/2011 at 09:57, xxxxxxxx wrote:

    I wouldn't use GetSecond() as you may be processing 30 fps (where s = Second).  Use doc->GetTime()->GetFrame(doc->GetFps()) instead.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/05/2011 at 02:53, xxxxxxxx wrote:

    Thanks guys, that works perfectly.

    See, it was option c) after all :-(



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/05/2011 at 10:19, xxxxxxxx wrote:

    Np :)

    Robert, I do not understand what you mean. Comparing Integers may
    be more safe, but why wouldn't comparing the seconds won't work if the Framerate is 30 ?

    Cheers, Niklas



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/05/2011 at 11:48, xxxxxxxx wrote:

    He wants to check once per frame.  If he used seconds then he would only be checking once per every 30 frames instead.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/05/2011 at 12:06, xxxxxxxx wrote:

    Uhm... Since when does GetSecond only return the Second as an Integer ?

    Frame 15 with 30 Fps would return 0.5 and not 0. That's my experience using GetSecond(); (Coffee) or Get() (Python).



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 21/05/2011 at 13:44, xxxxxxxx wrote:

    I wouldn't trust comparing floating point numbers when integer representation is available though.  Floating point is not an exact representation and is subject to drift and error (such as 1.0 sometimes ending up as 0.999999999999999).  Integers are exact and will never fail in comparison - and they are significantly faster in comparisons.  That's all I'm saying.



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 22/05/2011 at 00:17, xxxxxxxx wrote:

    Ah Ok, of course.
    You are right.


Log in to reply