Hi all
New to the world of Code, so forgive my noob questions
Id like to control the playback of a video texture with some keyboard input events
Im adding values to video.setTime() to advance the video’s playback
and subtracting values to video.setTime() to reverse the video’s playback
This works fine when adding/advancing the playback, but when subtracting to reverse the video, the playback jumps around and becomes very laggy.
Any idea what the issue is and is there a better way to set this up?
Thanks, any comments are appreciated
code:
from panda3d.core import loadPrcFileData
from panda3d.core import WindowProperties
from panda3d.core import LPoint3, LVector3
from panda3d.core import VideoTexture
from direct.showbase.ShowBase import ShowBase
from direct.task.Task import Task
confVars = """
win-size 1280 720
window-title test
"""
loadPrcFileData("", confVars)
keyMap = {
"forward" : False,
"reverse" : False
}
def updateKeyMap(key, state):
keyMap[key] = state
class MyGame(ShowBase):
def __init__(self):
super().__init__()
sphere = self.loader.loadModel("models/sphere.obj")
self.videoTex = loader.loadTexture("videos/drone.mp4")
sphere.setTwoSided(True)
sphere.setTexture(self.videoTex)
self.videoTex.stop()
self.videoTex.setTime(1.0)
sphere.setScale(5,5,5)
sphere.setHpr(160,90,0)
sphere.reparentTo(self.render)
self.disableMouse()
self.camLens.setFov(100)
taskMgr.add(self.controlVideo, "controlVideo")
self.accept("w", updateKeyMap, ["forward", True])
self.accept("w-up", updateKeyMap, ["forward", False])
self.accept("s", updateKeyMap, ["reverse", True])
self.accept("s-up", updateKeyMap, ["reverse", False])
self.speed = 1.0
def controlVideo(self, task):
dt = globalClock.getDt()
pos = self.videoTex.getTime()
if keyMap["forward"]:
pos += self.speed * dt
if keyMap["reverse"]:
pos -= self.speed * dt
self.videoTex.setTime(pos)
self.last = task.time
return Task.cont
game = MyGame()
game.run()