i just found this nice rope class, but couldn’t get it to work and/or modify its shape.
now i can, and if someone has the same problem, here are two small samples.
the first curve modification works with nodepaths, which is the simpler one (and maybe more useful).
the second sample shows you how to modify the vertices directly.
from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.showutil.Rope import Rope
class Main(DirectObject):
def __init__(self):
base.setBackgroundColor(0.0, 0.0, 0.0, 1)
base.cam.setPos(0, -100, 25)
r = Rope()
self.ropeVertex2NP = render.attachNewNode("ropeVertex2NP")
self.ropeVertex3NP = render.attachNewNode("ropeVertex3NP")
r.setup(4, [(None, (10, 0, 0)),
(None, (10, 0, 10)),
(self.ropeVertex2NP, (0, 0, 10)),
(self.ropeVertex3NP, (0, 10, 10)),
(None, (0, 10, 0)),
(None, (10, 10, 0))])
r.reparentTo(render)
taskMgr.add(self.modifyCurve, "modify")
def modifyCurve(self, task):
factor = globalClock.getDt() * 100.0
self.ropeVertex2NP.setZ(self.ropeVertex2NP.getZ()+(0.1*factor))
self.ropeVertex3NP.setY(self.ropeVertex3NP.getY()+(0.1*factor))
return task.cont
if __name__ == '__main__':
m = Main()
run()
from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.showutil.Rope import Rope
class Main(DirectObject):
def __init__(self):
base.setBackgroundColor(0.0, 0.0, 0.0, 1)
base.cam.setPos(0, -100, 25)
r = Rope()
r.setup(4, [(None, (10, 0, 0)),
(None, (10, 0, 10)),
(None, (0, 0, 10)),
(None, (0, 10, 10)),
(None, (0, 10, 0)),
(None, (10, 10, 0))])
r.reparentTo(render)
self.curve = r.ropeNode.getCurve()
taskMgr.add(self.modifyCurve, "modify")
def modifyCurve(self, task):
factor = globalClock.getDt() * 100.0
val2 = VBase4(self.curve.getVertex(2))
val3 = VBase4(self.curve.getVertex(3))
val2.setZ(val2.getZ()+(0.1*factor))
val3.setY(val3.getY()+(0.1*factor))
self.curve.setVertex(2, val2)
self.curve.setVertex(3, val3)
return task.cont
if __name__ == '__main__':
m = Main()
run()
greets