Page MenuHome

hang_curve_2.48.py

hang_curve_2.48.py

#!BPY
"""
Name: 'Hang Curve_248'
Blender: 248
Group: 'Add'
Tooltip: 'Hang curve between 2 objects or empties'
"""
__author__ = ["Elephants Dream Team"]
__url__ = ()
__version__ = "248 - 2008-10"
__bpydoc__ = """\
Hang a curve between two objects or empties,
Parameters can be edited in the text editor.
.\n\
"""
#
# Licence: Creative Commons. Please see http://orange.org/ for details.
import Blender
from Blender import Scene, Object, Mesh #reading
from Blender import Curve, BezTriple #creating
from Blender.Mathutils import Vector, MidpointVecs
from obscene import global_loc
W = 0.040
BEVRESOL = 10
RESOLU = 24
MIDLEN = 1
G = 3.5 #'gravity' i.e. how much midpoint is lowered
#RESOLV =
scene = Scene.getCurrent()
try:
a, b = Blender.Object.GetSelected()
except ValueError:
raise RuntimeError, "Please select exactly two objects to connect with a hanging tube."
else:
print "Got:", a, b
ob = Object.New('Curve', 'Hangtube')
cob = Curve.New('HangtubeData')
aloc = global_loc(a)
bloc = global_loc(b)
print aloc, bloc
avec = Vector(aloc)
bvec = Vector(bloc)
mvec = MidpointVecs(avec, bvec)
print mvec
mvec.z -= G
#assuming the selected object has a single face:
#data = Mesh.Get(a.getData(name_only=True))
#no = data.faces[0].no
#print no
def sort(p1, p2, tvec, which):
if which == 'a':
if (tvec - Vector(p1)).length < (tvec - Vector(p2)).length:
print 'a'
return p2, p1
else:
return p1, p2
elif which == 'b': #yet another ugliest hack ever!
if (tvec - Vector(p1)).length > (tvec - Vector(p2)).length:
print 'b'
return p2, p1
else:
return p1, p2
def attach(target, mvec, which):
no = target.matrix[2][:3] #object z-axis in worldspace
x, y, z = global_loc(target)
h1 = x-no[0], y-no[1], z-no[2]
h2 = x+no[0], y+no[1], z+no[2]
h1, h2 = sort(h1, h2, mvec, which)
btri = BezTriple.New((h1[0], h1[1], h1[2],
x, y, z,
h2[0], h2[1], h2[2]))
return btri
btri_a = attach(a, mvec, 'a')
btri_b = attach(b, mvec, 'b')
#middle
x, y, z = mvec[0], mvec[1], mvec[2]
m1 = x-MIDLEN, y, z
m2 = x+MIDLEN, y, z
m1, m2 = sort(m1, m2, bvec, 'a') #go figure
btri_m = BezTriple.New((m1[0], m1[1], m1[2],
x, y, z,
m2[0], m2[1], m2[2]))
bez = cob.appendNurb(btri_a)
bez.append(btri_m)
bez.append(btri_b)
cob.ext2 = W
cob.bevresol = BEVRESOL
cob.resolu = RESOLU
cob.update()
ob.link(cob)
scene.link(ob)
Blender.Redraw()

File Metadata

Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
35/aa/09f3b00d5584f384b67d728273ef

Event Timeline