I have gotten a little further.
Here is my latest script:
import Blender
import math
from Blender import Mathutils
from Blender.Mathutils import *
from Blender import *
from math import *
def bezFromVecs(vecs):
bt= BezTriple.New(vecs[0].x, vecs[0].y, vecs[0].z, vecs[1].x, vecs[1].y, vecs[1].z, vecs[2].x, vecs[2].y, vecs[2].z)
bt.handleTypes= (BezTriple.HandleTypes.FREE, BezTriple.HandleTypes.FREE)
return bt
def bezList2Curve(bezier_vecs):
# Create the curve data with one point
cu= Curve.New()
cu.appendNurb(bezFromVecs(bezier_vecs[0])) # We must add with a point to start with
cu_nurb= cu[0] # Get the first curve just added in the CurveData
i= 1 # skip first vec triple because it was used to init the curve
while i<len(bezier_vecs):
bt_vec_triple= bezier_vecs[i]
bt= bezFromVecs(bt_vec_triple)
cu_nurb.append(bt)
i+=1
# Add the Curve into the scene
scn= Scene.GetCurrent()
ob = scn.objects.new(cu)
return ob
def vecList2bezList(vecs, smoothness):
smoothness = smoothness * 0.5
if len(vecs) == 0:
return [[[0,0,0],[0,0,0],[0,0,0]]]
if len(vecs) == 1:
return [[vecs[0],vecs[0],vecs[0]]]
if len(vecs) == 2:
return [[vecs[0],vecs[0],vecs[1]],[vecs[0],vecs[1],vecs[1]]]
newbezlist = [[vecs[0],vecs[0],vecs[0]+smoothness*(2 * vecs[1] - vecs[0] - vecs[2])]]
for i in xrange(1,len(vecs) - 1):
newbezlist.append([vecs[i]-smoothness*(vecs[i+1] - vecs[i-1]),vecs[i],vecs[i]+smoothness*(vecs[i+1] - vecs[i-1])])
newbezlist.append([vecs[-1]+smoothness*(2*vecs[-2] - vecs[-1] - vecs[-3]),vecs[-1],vecs[-1]])
return newbezlist
print "Starting text generation."
localScene = Scene.GetCurrent() #Get a reference to the scene.
myTextValue = "Blender Text Moving Along A Path"
myTextName = "ap_Text"
localTextObject = Text3d.New(myTextName) #Create a text object.
localTextObject.setText(myTextValue) #Set the copy for the text.
localTextObject.setExtrudeDepth(0.01) #Give it some depth.
localObj = localScene.objects.new(localTextObject) #Add it to the scene.
myNewMeshObject = Mesh.New('myFontMesh') #Create a new mesh container.
myNewMeshObject.getFromObject(localObj,0,0) #Make this new mesh get it's data from the 3D text already in the scene.
localScene.unlink(localObj) #We are done with this object, let's get rid of it.
localObj = localScene.objects.new(myNewMeshObject) #Add this new mesh object to the scene.
localObj.makeDisplayList()
localObj.select(1)
print "Finished text generation."
print "Starting curve generation."
#Build a three point curve.
localCurvePoints = []
localCurvePoints.append(Vector(0,10,-10))
localCurvePoints.append(Vector(0,0,0))
localCurvePoints.append(Vector(0,10,10))
localCurveObj = bezList2Curve(vecList2bezList(localCurvePoints,0.5))
localCurveObj.setName("ap_Curve")
localModifiers = localObj.modifiers
tempMod = localModifiers.append(Modifier.Types.CURVE)
tempMod[Modifier.Settings.OBJECT] = localCurveObj
print "Finished curve generation."
print "Done."
This does work, but there is a strange anomaly where the text crosses over the zero-point of the curve. My font mesh gets stretched and inverted when it crosses the center of the curve.
Try this:
1.) Run the script posted.
2.) Delselct all and select the font mesh.
3.) Activate the grab tool and drag along the X axis (red arrow) and observe the error as it crosses the center of the curve.
My guess is that the problem is in the generation of the curve.
That’s odd, I can’t add an image attachment to a reply…:no: