curve skinning question (vectors & matrix math)

I need to skin a bezier curve…basically the same as the new taper curve feature only I’ll be doing more advanced stuff with it later. I’m using RipSting’s bezier4 function to get the positions along the curve, but what I need is to rotate the vertex loops according to the angle of the current position on the curve. Any ideas? Here’s the blend file. The updateMatrix() function is what I’m using to do the math and it’s called for each vertex ring of the tube the script is creating. The rotations are incorrect for some reason. I don’t know if the angle is the problem or the rotation axis. Here’s updateMatrix():

##########Creates/Modifies segment transformation/rotation matrix
def updateMatrix(self,h,curveRes,matrixList,prevVec):
  z = h * (1.0/curveRes)	#location for current segment (percentage)
	
  curLoc = Bezier4(self.pl[0][1],self.pl[0][2],self.pl[1][0],self.pl[1][1],z)
  #get location along the current bezier curve

  curLoc = Vector(curLoc) 		#change that location to a vector
  vecLoc = curLoc - prevVec[0]    #subtract last segment location from current location
  vecTrans = Vector([0.0,0.0,vecLoc.length])  #create translation vector
	
  if (h == 0):	 #create previous vector from first curve handle
    vecLoc = Vector([0.0,0.0,1.0])
    prevVec[1] = Vector(self.pl[0][2])
    #prevVec[1].negate()
	
    curveAngle = AngleBetweenVecs(vecLoc, prevVec[1])	#get angle between segments
  if (h > 0):
    curveAngle = curveAngle * -1
  vecRot = CrossVecs(vecLoc, prevVec[1])	#get vector for rotation axis
		
  matrixTrans = TranslationMatrix(vecTrans) #create translation matrix
  matrixRot = RotationMatrix(curveAngle, 4, 'r', vecRot)  #create rotation matrix
	
  matrixList[1] = matrixRot * matrixTrans * matrixList[1]  #multiply rot, trans, and previous matrix
	
  prevVec[0] = curLoc
  if (h > 0):
    prevVec[1] = vecLoc
	
  return matrixList

thanks in advance,
bydesign

I tried your blend and everything looks fine. I run the script and a nice tree-like mesh is made. The only problem I did have was that the new mesh had a script-link that was causing errors and keeping me from getting to edit mode.

Can you post a picture of the problem your having?

BTW here is a useful (almost) hidden feature for script links.


import Blender

if Blender.bylink: # Determines if the script is run as a scriptlink
    object = Blender.link # Where Blender.link is the object the script was called by
else:
    pass # Do non-scriptlink stuff here

Hey kitsu, thanks for looking at my script. I found a solution via RipSting’s fiber script. If you change the bezier curve in that blend file, the mesh didn’t always follow the curve correctly. In fact, sometimes it went the opposite direction. Anyway…I know how to fix it now…just gotta sit down and do it. As far as the not being able to edit the mesh, that’s actually purposeful. I may end up changing it if it’s a major usability problem. I’m going to make it so that if you go into edit mode on the mesh, it takes you to edit mode on the controlling curve object. Anyway…later.

bydesign