# Strange Rope behavior

Hi to all of you

I have been playing arround with the ropes and found a very strange behavior

the code of RopeTestA

``````from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.showutil.Rope import Rope

from numpy import arange, cos, linspace, pi, sin, random
from scipy.interpolate import splprep, splev, interp1d
import scipy

class Main(DirectObject):
def __init__(self):

self.a = []
base.setBackgroundColor(0.0, 0.0, 0.0, 1)
base.cam.setPos(0, -100, 25)

self.Light()
self.GenerateTextures()

# make ascending spiral in 3-space
t=linspace(0,1.75*2*pi,100)

x = sin(t)
y = cos(t)
z = t

# spline parameters
s=3.0 # smoothness parameter
k=3 # spline order
nest=-1 # estimate of number of knots needed (-1 = maximal)

self.tckp,self.u = splprep([x,y,z],s=s,k=k,nest=-1)
# Kontrollpunkte in 3D laden
for i in range (len(self.tckp[1][0])):
self.a.append( (None,(self.tckp[1][0][i],self.tckp[1][1][i],self.tckp[1][2][i])))
self.KPoint.setPos(self.tckp[1][0][i],self.tckp[1][1][i],self.tckp[1][2][i])
self.KPoint.setTexture(self.texGrayPink)
self.KPoint.reparentTo(render)

# Seil in 3D laden
self.r = Rope()
self.r.setup(4, self.a,self.tckp[0])
self.r.reparentTo(render)
#self.curve = self.r.ropeNode.getCurve()

def Light(self):
alight = AmbientLight('alight')
alight.setColor(VBase4(0.2, 0.2, 0.2, 1))
alnp = render.attachNewNode(alight)
render.setLight(alnp)

dlight = DirectionalLight('dlight')
dlight.setColor(VBase4(0.8, 0.8, 0.5, 1))
dlnp = render.attachNewNode(dlight)
dlnp.setHpr(0, -60, 0)
render.setLight(dlnp)

def GenerateTextures(self):

if __name__ == '__main__':
m = Main()
run() ``````

and RopetestB

``````from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.showutil.Rope import Rope

from numpy import arange, cos, linspace, pi, sin, random
from scipy.interpolate import splprep, splev, interp1d
import scipy

class Main(DirectObject):
def __init__(self):

self.a = []
base.setBackgroundColor(0.0, 0.0, 0.0, 1)
base.cam.setPos(0, -100, 25)

self.Light()
self.GenerateTextures()

# make ascending spiral in 3-space
t=linspace(0,1.75*2*pi,100)

x = sin(t)
y = cos(t)
z = t

# spline parameters
s=3.0 # smoothness parameter
k=3 # spline order
nest=-1 # estimate of number of knots needed (-1 = maximal)

self.tckp,self.u = splprep([x,y,z],s=s,k=k,nest=-1)
# Kontrollpunkte in 3D laden

# Seil in 3D laden
self.r = Rope()
self.r.setup(4, self.a,self.tckp[0])
self.r.reparentTo(render)
#self.curve = self.r.ropeNode.getCurve()

for i in range (len(self.tckp[1][0])):
self.a.append( (None,(self.tckp[1][0][i],self.tckp[1][1][i],self.tckp[1][2][i])))
self.KPoint.setPos(self.tckp[1][0][i],self.tckp[1][1][i],self.tckp[1][2][i])
self.KPoint.setTexture(self.texGrayPink)
self.KPoint.reparentTo(render)

def Light(self):
alight = AmbientLight('alight')
alight.setColor(VBase4(0.2, 0.2, 0.2, 1))
alnp = render.attachNewNode(alight)
render.setLight(alnp)

dlight = DirectionalLight('dlight')
dlight.setColor(VBase4(0.8, 0.8, 0.5, 1))
dlnp = render.attachNewNode(dlight)
dlnp.setHpr(0, -60, 0)
render.setLight(dlnp)

def GenerateTextures(self):

if __name__ == '__main__':
m = Main()
run() ``````

only differ in the position of the insertation of the KontrollPointsbut RopetestB throws an
assertation error
in Line 40->
self.recompute line 69 ->self.curve.setKnot(i,self.knots.size[i]) line 124
-> AssertationError: i>=00 && < (int)_knots.size() line 106 in nurbsCurveEvaluator.cxx

with kind regards

Martin
[/img]

In case B, at the time you call setup(), you are passing an empty list, self.a. You donâ€™t populate the list until after you call setup(), which is obviously too late.

David

Thx David I missed the obvious