Hi,
How do you find a point that is located n-percent along the line defined by points A and B?
Aligorith
Hi,
How do you find a point that is located n-percent along the line defined by points A and B?
Aligorith
Not percent… but between 0.0 and 1.0
percent = 0.5
midVec = (vecApercent) + (vecb(1-percent))
import Blender
#------------------
# ME is supposed to be a mesh
#------------------
ME=Blender.Object.GetSelected()[0].getData()
#------------------
# for the example, get the two first vertices of ME
#------------------
A=ME.verts[0]
B=ME.verts[1]
#------------------
# for the example, a list of values for "percent"
# this will create 4 point on the edges [AB]
#------------------
for percent in [10,20,45,75] :
#------------------
# create a vertex to be added to the mesh
#------------------
C=Blender.NMesh.Vert()
#------------------
# Calculate the location of C between A and B, in x,y and z axis .
# like that : C=A+(B-A)*percent
#------------------
for n in [0,1,2]:
C.co[n]=A.co[n]+(B.co[n]-A.co[n])*percent/100.0
#------------------
# have an echo in the console
#------------------
print C.co
#------------------
# Add new vertex to the list
#------------------
ME.verts.append(C)
#------------------
# insert the new data of ME in Blender daat base .
#------------------
ME.update()
Of course both these answers are right
but why can’t I do?
a = Vector(1,2,3)
vv = Blender.NMesh.Vert()
vv.co = a
( you would like to think that cambos
vv.co = .5a + .5b
would work but it fails)
Apparently vv.co and a are both type <vector>
whereas the syntactically obscure
a = Vector(1,2,3)
vv = Blender.NMesh.Vert()
vv.co[:] = a[:]
works.
The wonderfool vectors’ world . This works :
http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_addvertexalongedge.htm#alternative
Sure these all work but what one’s intuition tells one
should work fails – ie mixing Cambo’s code with
the Vert() constructor
1/ the Vert constructor (still) doesn’t take a <vector> object
where it really should - I hate working with indices
2/ type(vv.co) should be polymorphic to a <vector>
but the assignment fails with a (not very useful)
Attribute error.
I know it’s not read only as vv.co[:] = a[:] works
you cant do
v.co=…
you have to assign the x/y/z
co=…
v.co.x = co.x
v.co.y = co.y
v.co.z = co.z
Assigning slices works but is less explicit than your code
and therefore (Pythonically) worse.
BTW I think the .x, .y, .z attributes are great…
I can see why the assignment vv.co = co
shouldn’t work as it might only pass a reference
but none of this is clear in the api doc.
And (I suppose I should post this in LetterRips request thread)
The Vert constructor should really take a <vector>.
Here’s a code snippet to test.
it’s a hack to create a mesh
for reading the head position after the IK/IPOs/parenting
is evaluated.
import Blender
from Blender import Armature as AA
sk = Blender.Object.Get("sk") #sk = aramture
skd = sk.getData()
plane = Blender.Object.Get("yplane").getData() #some mesh object "yplane"
for gp in plane.getVertGroupNames():
plane.removeVertGroup(gp)
verts = []
for bone,data in skd.bones.items():
plane.addVertGroup(bone)
xx = data.head['ARMATURESPACE']
vv= Blender.NMesh.Vert(0,0,0)
vv.co[:] = xx[:]
verts.append(vv)
plane.verts = verts
plane.update()
for i,bone in enumerate(skd.bones.keys()):
plane.assignVertsToGroup(bone,[i],1,'add')
plane.update()