deforming a mesh at runtime, using a nurbs curve

Hi all,

I wonder if it is possible to deform a mesh so that it follows a curve.
I read that Panda supports NURBS, but I’m not sure how to use them for deforming a mesh.

I’d like to make road meshes out of curves at runtime.

Would it be possible to do something like this:
home.mnet-online.de/sk9/tutorial … lender.pdf
at runtime (without blender)?

Panda doesn’t have this feature built-in. You can look up the mathematics involved and do the work yourself, or you can locate a third-party library that does this and integrate it.

David

i once wrote a script which would allow you to do something like this. i never implemented UV-stuff but it is possible to extract a curve a long a path.

if you’r interested give me some time to digg it out and polish it up.

thank you for your answers!

My first idea was to make a road-piece which has two bones.
One at the first end, one at the other one.
I thougt about rotating the bones to the direction
of the next road edge point and add the next piece,
rotate its bones and so on.
But I’m afraid that it could slow down the fps if
the road consists of hundrets of seperate actors (which are obviously needed for bone-deformation).

I’ll try to write something on my own, but if i could take a look at your script (@ThomasEgi), it would be helpful I think. But you don’t have to polish up anything for me.:unamused:

Thank you anyway! :smiley:

well… if no polishing is required…

def createTrackGeometry(self,profile=[(.5,0,0),(-.5,0,0)]): #you need to specify in counter-clockwise order. or, clockwise if in a tunnel.
        #shapelist=[(0,-3,0),(0,-3,-1),(0,0,-2),(0,3,-1),(0,3,0)]
        
        shapelist=profile
        finalNP=NodePath("track")
        anchorNP = finalNP.attachNewNode("anchor")
        pointNPList=[]
        for i in shapelist:
            newNode = anchorNP.attachNewNode("childanchor")
            newNode.setPos(i)
            pointNPList.append(newNode)

        format=GeomVertexFormat.getV3n3c4()
        vdata = GeomVertexData('name', format, Geom.UHStatic)
        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')      
        
        self.myMoPathInt = MopathInterval(self.myMoPath,anchorNP, duration=(10*(len(self.track3dPos)/10))*0.02 ,name = "Name")
        #self.myMoPathInt.play()    
        for i in range(len(self.track3dPos)):
            self.myMoPathInt.setT(i*0.02)
            #self.myMoPathInt.stepPlay()
            #print anchorNP.getPos(),self.track3dPos[i]
            #anchorNP.setPos(self.track3dPos[i])
            #anchorNP.setHpr(self.track3dHpr[i])
            for j in pointNPList:
                vertex.addData3f(j.getPos(finalNP))
                normal.addData3f( finalNP.getRelativeVector( anchorNP,VBase3(0,0,1) )   )
                #normal.addData3f((0,0,1))
                if i % 100:
                    color.addData4f(1,1-self.normVolume[i] ,1-self.normVolume[i] , .7)   #i really have to do something about that color...   
                else:
                    color.addData4f(0,0,0,1)
                                        
        prim = GeomTriangles(Geom.UHStatic)
        for i in range(len(self.track3dPos)-1):
            for j in range(len(shapelist)-1):
                width=len(shapelist)
                start = i*(width)+j
                prim.addVertex(start)
                prim.addVertex(start+width)
                prim.addVertex(start+width+1)
                prim.closePrimitive()
                prim.addVertex(start)
                prim.addVertex(start+width+1)
                prim.addVertex(start+1)
                prim.closePrimitive()          
        geom = Geom(vdata)
        geom.addPrimitive(prim)
        node = GeomNode('gnode')
        node.addGeom(geom)
         
        return NodePath(node)

you can find the classes to create motion path from point in the showcase section of the forum.
if you prefer to have it cleaned up, feel free to change your mind :smiley:

Thanks a lot, I’ll take a look at this :slight_smile: