Beispiel #1
0
 def __init__(self, p1, p2):
     self.v1 = SoSFVec3f()
     self.v2 = SoSFVec3f()
     self.v3 = SoSFVec3f()
     self.h = SoSFFloat()
     self.calc = SoCalculator()
     ## ============================
     self.calc.expression.set1Value(0, "oA=A-h*(A-B)")
     self.calc.A.connectFrom(self.v1)
     self.calc.B.connectFrom(self.v2)
     self.calc.h.connectFrom(self.h)
     self.v3.connectFrom(self.calc.oA)
     ## ============================
     self.v1.setValue(p1)
     self.v2.setValue(p2)
Beispiel #2
0
class OneShot(QtCore.QObject):
    def __init__(self, duration, times):
        QtCore.QObject.__init__(self)
        self.times = self.timesleft = times
        self.oneshot = SoOneShot()
        self.oneshot.duration = duration
        self.oneshot.flags = SoOneShot.HOLD_FINAL
        ## necesitamos un SoField para poder extraer el
        ## valor con getValue()
        ## can't this value be obtained directly from a SoEngineOutput?
        self.value = SoSFFloat()
        self.value.connectFrom(self.oneshot.ramp)
        self.sensor = SoFieldSensor(self.callback, self.value)
        self.sensor.attach(self.value)
        connect(self, "finished()", self.cycle)

    def callback(self, ffloat, sensor):
        t = ffloat.getValue()
#        QtCore.QObject.emit(self, QtCore.SIGNAL("ramp(float)"), t)
        ## 0 <= t <= 1
        ## nmin <= nmin + (nmax-nmin) * t <= nmax
        i = int(self.startFrame + self.spanFrame * t)
        QtCore.QObject.emit(self, QtCore.SIGNAL("frameChanged(int)"), i)
        if t == 0.0:
            self.emit(QtCore.SIGNAL("started()"))
        elif t == 1.0:
            self.emit(QtCore.SIGNAL("finished()"))

    def start(self):
        self.oneshot.trigger.touch()

    def stop(self):
        #self.oneshot.disable = True
        self.timesleft = self.times

    def setFrameRange(self, nmin, nmax):
        self.startFrame = nmin
        self.endFrame = nmax
        self.spanFrame = nmax - nmin

    def cycle(self):
        self.timesleft -= 1
        if self.timesleft > 0:
            self.start()

    def setDuration(self, milliseconds):
        self.oneshot.duration = milliseconds / 1000.0
Beispiel #3
0
class SegmentoEngines(object):
    def __init__(self, p1, p2):
        self.v1 = SoSFVec3f()
        self.v2 = SoSFVec3f()
        self.v3 = SoSFVec3f()
        self.h = SoSFFloat()
        self.calc = SoCalculator()
        ## ============================
        self.calc.expression.set1Value(0, "oA=A-h*(A-B)")
        self.calc.A.connectFrom(self.v1)
        self.calc.B.connectFrom(self.v2)
        self.calc.h.connectFrom(self.h)
        self.v3.connectFrom(self.calc.oA)
        ## ============================
        self.v1.setValue(p1)
        self.v2.setValue(p2)

    def eval(self, t):
        self.h.setValue(t)
        return self.v3.getValue().getValue()
Beispiel #4
0
 def __init__(self, duration, times):
     QtCore.QObject.__init__(self)
     self.times = self.timesleft = times
     self.oneshot = SoOneShot()
     self.oneshot.duration = duration
     self.oneshot.flags = SoOneShot.HOLD_FINAL
     ## necesitamos un SoField para poder extraer el
     ## valor con getValue()
     ## can't this value be obtained directly from a SoEngineOutput?
     self.value = SoSFFloat()
     self.value.connectFrom(self.oneshot.ramp)
     self.sensor = SoFieldSensor(self.callback, self.value)
     self.sensor.attach(self.value)
     connect(self, "finished()", self.cycle)