calcul point longueur courbe dans blender ( juste pour moi)
mon objectif calculer longeur et point(x,y,z) d'un path pour faire déplacer via un script un objet sur ce path
mesurer longueur path: select votre path puis aller onglet script et dans la console mettre
bpy.context.object.data.splines.active.calc_length(resolution=0)
attention votre path doit pas etre scalé( faire un apply scale)
http://www.f-legrand.fr/scidoc/docmml/graphie/geometrie/bezier/bezier.html
http://www.f-legrand.fr/scidoc/srcdoc/graphie/geometrie/bezier/bezier-pdf.pdf
https://blender.stackexchange.com/questions/47926/get-length-of-bezier-curve-with-python-for-driver
https://blender.stackexchange.com/questions/93434/animation-nodes-setup-not-updating-when-rendering
https://squircleart.github.io/animation-nodes/the-essense-of-animation-nodes-preface.html
https://docs.blender.org/api/2.70/mathutils.html
https://blenderartists.org/t/how-to-work-out-object-speed-in-game/507123/4
https://blenderartists.org/t/use-of-foreach-get-and-foreach-set/524646
https://blender.stackexchange.com/questions/27465/running-a-script-for-each-frame
https://docs.blender.org/manual/fr/dev/editors/python_console.html
obj.data.splines[...].length
bpy.context.scene.objects.active = bpy.data.objects['Sphere.017']
import bpy
from mathutils import *
from bpy.props import *
#distance between 2 points
def dist(p1, p2):
return (p2-p1).magnitude
#cuadratic bezier value
def quad(p, t):
return p[0]*(1.0-t)**2.0 + 2.0*t*p[1]*(1.0-t) + p[2]*t**2.0
#cubic bezier value
def cubic(p, t):
return p[0]*(1.0-t)**3.0+3.0*p[1]*t*(1.0-t)**2.0+3.0*p[2]*(t**2.0)*(1.0-t)+p[3]*t**3.0
def calct(obj, t):
mw = obj.matrix_world
spl = obj.data.splines.active
points = spl.bezier_points
nsegs =len(points)-1
d = 1.0/nsegs
seg = int(t/d)
t1 = t/d - int(t/d)
if t==1:
seg-=1
t1 = 1.0
p = getbezpoints(spl,mw, seg)
coord = cubic(p, t1)
print(coord)
return coord
#gets a bezier segment's control points on global coordinates
def getbezpoints(spl, mt, seg=0):
points = spl.bezier_points
p0 = mt @ points[seg].co
p1 = mt @ points[seg].handle_right
p2 = mt @ points[seg+1].handle_left
p3 = mt @ points[seg+1].co
return p0, p1, p2, p3
obj=bpy.data.objects['BezierCircle']
#bpy.context.scene.objects.active = bpy.data.objects['Sphere.017']
#obj1=bpy.data.objects['Cube']
obj.location.x += 1.0
bpy.context.object.location[0] = 0
bpy.context.object.location[1] = 0
bpy.context.object.location[2] = 0
bpy.ops.object.select_all(action='SELECT')
length = 0.0
prec = 1000 #precision
inc = 1/prec #increments
for i in range(0, prec):
ti = i*inc
tf = (i+1)*inc
a = calct(obj, ti)
print(a)
b = calct(obj, tf)
print(b)
r = (b-a).magnitude
length+=r
print(length)
https://snakify.org/fr/lessons/two_dimensional_lists_arrays/