Deltatime ?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 21/02/2011 at 09:23, xxxxxxxx wrote:
Hi Guys,
I'm going to write a deltatime plugin and i need a global variable which represents the previous frame of the scene.
But this doesn't work:global prevframe if frame is not prevframe: pass
The console tells me that prevframe is not defined.
Any idea how to to this ?
Thanks, nux
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/02/2011 at 10:57, xxxxxxxx wrote:
AFAIK. You can't go directly to getting frame info.
You have to first call the baseTime class using doc.GetTime(). Then from there you can proceed and get access to the frame data.import c4d from c4d import gui def main() : global previousframe #The frame to the left of the time scrubber time = doc.GetTime() frame = time.GetFrame(doc.GetFps()) previousframe = frame -1 print previousframe if __name__=='__main__': main()
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/02/2011 at 11:51, xxxxxxxx wrote:
Hehe, of course I didn't write the whole Code in here, but thanks anyway Scott.
This was just an example how i tried to do it. The Fullcode looks something like this, on a Generator or Tag.import c4d global prevframe prevframe = 0 def main() : frame = doc.GetTime().GetFrame(doc.GetFps()) if frame > prevframe: pass # The Stuff i want to do with the Deltatime global prevframe prevframe = frame
Setting the Prevframe to Frame-1 makes no Sense actually in Case i want to check if the actual frame is really next to the previous frame. So i can figure out if the timeline is playing. If I replace the commwnt for example with this:
op.SetAbsPos(op.GetAbsPos()*2)
The object will moved even the timeline is not playing, because of the Editorupdate and the Deltatime if-expression doesnt work ..
cheers, nux
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/02/2011 at 12:44, xxxxxxxx wrote:
Why are you redefining the global variable in the main section after it's already been defined?
When I use this code. The if statement works as expected. And only executes if the scrubber is located beyond frame 10.import c4d global prevframe def main() : prevframe = 10 frame = doc.GetTime().GetFrame(doc.GetFps()) #Gets the frame the scrubber is on if frame > prevframe: print "true"
From there any other kind of code can be written to test the location of the scrubber. In relation to the the other frames.
Including the usage of: doc.GetMinTime().GetFrame(fps) & doc.GetMaxTime().GetFrame(fps).
And they all seem to work fine for me.I'm confused about what the heck you're doing.
Hopefully someone else with more experience will understand it better than me. Good Luck.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/02/2011 at 13:07, xxxxxxxx wrote:
So I'll try to explain it to you.
In your Code, the main stuff will only be executed if the active frame is greater than 10.
That's not what I want. Finally, i want to use it with particles. But i did some stuff in coffee like this, too.Imagine the following: A sphere's position is moved every frame about 100 on x. Of course i could calculate it with a formula like this:
sph.SetAbsPos(INIT_POS+c4d.Vector(frame*100,0,0))
But this is not simulation, its simple calculation. The spheres Position is beeing set by its initial position. If afterwards another calculation moves the sphere in a completely different direction, the next frame: the sphere is still on its position beeing calculated by its initial position. Can you follow me ?
So the new position must be calculated depending on its actual position.
sph.SetAbsPos(sph.GetAbsPos()+c4d.Vector(100,0,0))
If now afterwards another "force" moves the Sphere, the next frame: the effect of this force is still there. (Sorry for my bad english xD)
Lets look at some values, i think they can show it betterForce 1 pulls the sphere about 100 in x per frame Force 2 pulls the sphere about 500 in y to frame 2 The order how the forces are applied is given. with "order" I mean the order in the code. e example for Force 2 after Force 1: InitPos = sph.GetAbsPos() def main() : ApplyForce1() ApplyForce2() ------------------ Calculating the Spheres Position with a Formula, applying Force 2 after Force 1 Frame 0: 0, 0, 0 Frame 1: 100, 0, 0 Frame 2: 200, 500, 0 Frame 3: 300, 0, 0 Frame 4: 400, 0, 0 Calculating the Spheres position with a Formula, applying Force 2 before Force 1 Frame 0: 0, 0, 0 Frame 1: 100, 0, 0 Frame 2: 200, 0, 0 Frame 3: 300, 0, 0 Frame 4: 400, 0, 0 SIMULATING THE SPHERES POSITION, the order of forces is unimportant Frame 0: 0, 0, 0 Frame 1: 100, 0, 0 Frame 2: 200, 500, 0 Frame 3: 300, 500, 0 Frame 4: 400, 500, 0
But the problem of Simulating is, it gets calculated even if the timeline is *not* moved, because of the editoredraw.
So i have to check if the Timeline is really playing. I need a variable frame which contains the active frame, and a variable prevframe which contains the last obtained frame, not frame-1. If frame != prevframe+1, it must be because the user slides in the timeline or something.But now, back to the Origin of the hole problem:
To edit global variables i must call "global [variablename]". *but* doing this deinitialises the variable first, so its kinda less than None, and my previously saved frame is just nothing.In coffee i could do it like this:
var prevframe; main() { if(!prevframe) prevframe = 0; //Really missing this in Python :-( var frame = doc->GetTime()->GetFrame(doc->GetFps()); if (frame == prevframe+1) { println("The Timeline is playing"); } if (frame == prevframe) { println("not playing"); } if (frame < prevframe) { println("Playinh backwards"); } prevframe = frame; }
When want to edit a global variable in python, it just gets edited locally, after that it gets set to its original value. How the hell to do it like in Coffee ? How to edit global variables ?
I hope you could uderstand what I mean .. Really difficult to explain
Especially when beeing on a mobile device x/ -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/02/2011 at 14:16, xxxxxxxx wrote:
I think I understand the problem now. Forgive me ..... I'm a bit dense sometimes.
Your last bit of coffee code is what made me understand the problem.
So I'm going to use it as the basis for my python example.
Give this code a try and see if it solves your global variable problem:import c4d prevframe = 0 def main() : global prevframe time = doc.GetTime() frame = time.GetFrame(doc.GetFps()) if not prevframe: prevframe = 0 if frame == prevframe+1: prevframe = prevframe +1 print "The Timeline is playing" if frame == prevframe: print "not playing" if frame < prevframe: print "Playing backwards"
Please bear in mind that I am very new to Python. And I only know enough to be dangerous at this point.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 22/02/2011 at 14:16, xxxxxxxx wrote:
I'll give it a try tomorrow, thanks
But I think it won't work ..
AFAIK this tells you that the variable has not been initialised (or None ?)prevframe = 0 def main() : global prevframe print prevframe
what makes me think, that the global - expression resets the variable first ..
But anyway, I'll give it a try !I'm new to it, too. Started learning 2 days ago.
Cheers and thanks,
nux -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/02/2011 at 06:15, xxxxxxxx wrote:
OMG it works !! :OOO Thanks man
But I don't get why it suddenly does ! O.o But, anyway, thanks. I'll try to implement this now and come back with problems for sureThanks haha
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/02/2011 at 07:05, xxxxxxxx wrote:
lol.
Even a blind squirrel finds a nut once in a while.The thought process in my head was this:
You need to have a global variable in order to override it. But python doesn't let you assign a value to a variable with the word "global" in front of it. Which causes definition errors later on.
So I sort of cheated.
I created a standard variable and defined it with a value.
Then later on. I told python to treat it as a global variable in the main section.The fact that it worked was a complete accident. And I have no idea if this is the proper way to do it.
-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/02/2011 at 07:15, xxxxxxxx wrote:
Hehe testing goes over studieng
Great work. !I think i found out, why Python told me the variables was not initialiesed.
My code was:global prevtime def main() : global prevframe //do stuff prevframe = frame
But it works fine with simply adding this:
global prevframe prevframe = 0 ## Adding this, it works def main() : global prevframe //do stuff prevframe = frame
Actually I don't get the sense why it must be defined once before it can be changed. But, it works fine
If you may want the Code i was working on, here it is.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/02/2011 at 07:37, xxxxxxxx wrote:
Thanks,
I'm always looking for code snippets to learn from.
-ScottA