Hey, I've been trying to create a python node in xpresso to emulate this bit of code from the amazing Mr Ebberts...
http://motionscript.com/articles/speed-control.html
Here's the After Effects expression I'm trying to translate...
spd = effect("Slider Control")("Slider");
n = spd.numKeys;
if (n > 0 && spd.key(1).time < time){
accum = spd.key(1).value*(spd.key(1).time - inPoint);
for (i = 2; i <= n; i++){
if (spd.key(i).time > time) break;
k1 = spd.key(i-1);
k2 = spd.key(i);
accum += (k1.value + k2.value)*(k2.time - k1.time)/2;
}
accum += (spd.value + spd.key(i-1).value)*(time - spd.key(i-1).time)/2;
}else{
accum = spd.value*(time - inPoint);
}
value + accum
Here's where I'm at with my Python translation...
from typing import Optional
import c4d
op: c4d.modules.graphview.GvNode # The Xpresso node
doc: c4d.documents.BaseDocument # The document evaluating this node
tp: Optional[c4d.modules.thinkingparticles.TP_MasterSystem] # Particle system
def main():
global Output1
#Grab the host-object to the xpresso Tag
Rect = op.GetNodeMaster().GetOwner().GetObject()
#Get the UserData
spd = Rect[c4d.ID_USERDATA,1]
# Get the first animation track of the object
track = Rect.GetFirstCTrack()
# Get the animation curve of the track
curve = track.GetCurve()
# Get the number of keyframes on the curve
n = curve.GetKeyCount()
fps = doc.GetFps()
sFrame= doc.GetMinTime().GetFrame(fps)
eFrame= doc.GetMaxTime().GetFrame(fps)
name = op.GetName()
key = curve.GetKey(1)
keyValue = key.GetValue()
keyFrame = key.GetTime().GetFrame(fps)
currentFrame = doc.GetTime().GetFrame(doc.GetFps())
value = spd
if n > 0 and curve.GetKey(1).GetTime().GetFrame(fps) < currentFrame:
accum = curve.GetKey(1).GetValue() * (curve.GetKey(1).GetTime().Get() - sFrame)
for i in range(2, n):
if curve.GetKey(i).GetTime().Get() > currentFrame:
break
k1 = curve.GetKey(i-1)
k2 = curve.GetKey(i)
accum += (k1.GetValue() + k2.GetValue()) * (k2.GetTime().Get() - k1.GetTime().Get()) / 2
accum += (curve.GetValue(curve.GetKey(i-1).GetTime()) + curve.GetKey(i-1).GetValue()) * (currentFrame - curve.GetKey(i-1).GetTime().Get()) / 2
else:
accum = Input1 * (currentFrame - sFrame)
print(Input1 + accum)
Output1 = value + accum
- There are loads of unnecessary variables in there btw - that was me just trying to figure this stuff out!
Basically trying to drive rotation without using time as my driver. Now, I'm no programmer (as you'll soon find out!), but the attached project does work, but doesn't do what I want it to! When the UsrData 'speed' gets to 0 it should stop. And the rotation is meant to be smooth ramp up and then smooth ramp down.
Any python geniuses out there got time to take a look and tell me where I'm going wrong?