Branch's now have weights assigned to the mesh and an armature modifier applied so the bones effect the tree.
This commit is contained in:
@@ -540,9 +540,9 @@ class tree:
|
|||||||
|
|
||||||
return self.mesh
|
return self.mesh
|
||||||
|
|
||||||
def toArmature(self, armature):
|
def toArmature(self, ob_arm, armature):
|
||||||
armature.drawType = Blender.Armature.STICK
|
|
||||||
|
|
||||||
|
armature.drawType = Blender.Armature.STICK
|
||||||
armature.makeEditable() # enter editmode
|
armature.makeEditable() # enter editmode
|
||||||
|
|
||||||
# Assume toMesh has run
|
# Assume toMesh has run
|
||||||
@@ -550,57 +550,99 @@ class tree:
|
|||||||
for bonename in armature.bones.keys():
|
for bonename in armature.bones.keys():
|
||||||
del armature.bones[bonename]
|
del armature.bones[bonename]
|
||||||
|
|
||||||
|
|
||||||
|
group_names = []
|
||||||
|
|
||||||
for i, brch in enumerate(self.branches_all):
|
for i, brch in enumerate(self.branches_all):
|
||||||
|
|
||||||
# get a list of parent points to make into bones. use parents and endpoints
|
# get a list of parent points to make into bones. use parents and endpoints
|
||||||
bpoints_parent = [pt for pt in brch.bpoints if pt.isParent or pt.prev == None or pt.next == None]
|
bpoints_parent = [pt for pt in brch.bpoints if pt.isParent or pt.prev == None or pt.next == None]
|
||||||
bone_last = None
|
bpbone_last = None
|
||||||
for j in xrange(len(bpoints_parent)-1):
|
for j in xrange(len(bpoints_parent)-1):
|
||||||
bone = Blender.Armature.Editbone() # automatically added to the armature
|
|
||||||
self.armature.bones['%i_%i' % (i,j)] = bone
|
# bone container class
|
||||||
bpoints_parent[j].blender_bone = bone
|
bpoints_parent[j].bpbone = bpbone = bpoint_bone()
|
||||||
bone.head = bpoints_parent[j].co
|
bpbone.name = '%i_%i' % (i,j) # must be unique
|
||||||
bone.head = bpoints_parent[j].co
|
group_names.append(bpbone.name)
|
||||||
bone.tail = bpoints_parent[j+1].co
|
|
||||||
|
bpbone.editbone = Blender.Armature.Editbone() # automatically added to the armature
|
||||||
|
self.armature.bones[bpbone.name] = bpbone.editbone
|
||||||
|
|
||||||
|
bpbone.editbone.head = bpoints_parent[j].co
|
||||||
|
bpbone.editbone.head = bpoints_parent[j].co
|
||||||
|
bpbone.editbone.tail = bpoints_parent[j+1].co
|
||||||
|
|
||||||
# parent the chain.
|
# parent the chain.
|
||||||
if bone_last:
|
if bpbone_last:
|
||||||
bone.parent = bone_last
|
bpbone.editbone.parent = bpbone_last.editbone
|
||||||
bone.options = [Blender.Armature.CONNECTED]
|
bpbone.editbone.options = [Blender.Armature.CONNECTED]
|
||||||
|
|
||||||
bone_last = bone
|
bpbone_last = bpbone
|
||||||
|
|
||||||
|
|
||||||
for brch in self.branches_all:
|
for brch in self.branches_all:
|
||||||
if brch.parent_pt: # We must have a parent
|
if brch.parent_pt: # We must have a parent
|
||||||
|
|
||||||
# find the bone in the parent chain to use for the parent of this
|
# find the bone in the parent chain to use for the parent of this
|
||||||
parent_pt = brch.parent_pt
|
parent_pt = brch.parent_pt
|
||||||
parent_bone = None
|
bpbone_parent = None
|
||||||
while parent_pt:
|
while parent_pt:
|
||||||
parent_bone = parent_pt.blender_bone
|
bpbone_parent = parent_pt.bpbone
|
||||||
if parent_bone:
|
if bpbone_parent:
|
||||||
break
|
break
|
||||||
|
|
||||||
parent_pt = parent_pt.prev
|
parent_pt = parent_pt.prev
|
||||||
|
|
||||||
# in rare cases this may not work. should be verry rare but check anyway.
|
|
||||||
if parent_bone:
|
|
||||||
brch.bpoints[0].blender_bone.parent = parent_bone
|
|
||||||
else:
|
|
||||||
print 'this is really odd... look into the bug.'
|
|
||||||
|
|
||||||
|
if bpbone_parent:
|
||||||
|
brch.bpoints[0].bpbone.editbone.parent = bpbone_parent.editbone
|
||||||
|
else: # in rare cases this may not work. should be verry rare but check anyway.
|
||||||
|
print 'this is really odd... look into the bug.'
|
||||||
|
|
||||||
self.armature.update() # exit editmode
|
self.armature.update() # exit editmode
|
||||||
|
|
||||||
|
# Skin the mesh
|
||||||
|
if self.mesh:
|
||||||
|
for group in group_names:
|
||||||
|
self.mesh.addVertGroup(group)
|
||||||
|
|
||||||
|
for brch in self.branches_all:
|
||||||
|
|
||||||
|
|
||||||
|
vertList = []
|
||||||
|
group = '' # dummy
|
||||||
|
|
||||||
|
for pt in brch.bpoints:
|
||||||
|
if pt.bpbone:
|
||||||
|
if vertList:
|
||||||
|
self.mesh.assignVertsToGroup(group, vertList, 1.0, Blender.Mesh.AssignModes.ADD)
|
||||||
|
|
||||||
|
vertList = []
|
||||||
|
group = pt.bpbone.name
|
||||||
|
|
||||||
|
vertList.extend( [v.index for v in pt.verts] )
|
||||||
|
|
||||||
|
if vertList:
|
||||||
|
self.mesh.assignVertsToGroup(group, vertList, 1.0, Blender.Mesh.AssignModes.ADD)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return self.armature
|
return self.armature
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
zup = Vector(0,0,1)
|
zup = Vector(0,0,1)
|
||||||
|
|
||||||
class bpoint:
|
class bpoint_bone:
|
||||||
|
def __init__(self):
|
||||||
|
self.name = None
|
||||||
|
self.editbone = None
|
||||||
|
self.blenbone = None
|
||||||
|
self.posebone = None
|
||||||
|
|
||||||
|
class bpoint(object):
|
||||||
''' The point in the middle of the branch, not the mesh points
|
''' The point in the middle of the branch, not the mesh points
|
||||||
'''
|
'''
|
||||||
|
__slots__ = 'branch', 'co', 'no', 'radius', 'vecs', 'verts', 'children', 'faces', 'next', 'prev', 'isParent', 'bpbone', 'roll_angle', 'nextMidCo', 'childrenMidCo', 'childrenMidRadius', 'targetCos'
|
||||||
def __init__(self, brch, co, no, radius):
|
def __init__(self, brch, co, no, radius):
|
||||||
self.branch = brch
|
self.branch = brch
|
||||||
self.co = co
|
self.co = co
|
||||||
@@ -613,7 +655,7 @@ class bpoint:
|
|||||||
self.next = None
|
self.next = None
|
||||||
self.prev = None
|
self.prev = None
|
||||||
self.isParent = False
|
self.isParent = False
|
||||||
self.blender_bone = None
|
self.bpbone = None # bpoint_bone instance
|
||||||
|
|
||||||
# when set, This is the angle we need to roll to best face our branches
|
# when set, This is the angle we need to roll to best face our branches
|
||||||
# the roll that is set may be interpolated if we are between 2 branches that need to roll.
|
# the roll that is set may be interpolated if we are between 2 branches that need to roll.
|
||||||
@@ -1252,9 +1294,7 @@ def buildTree(ob):
|
|||||||
# New object
|
# New object
|
||||||
mesh = bpy.data.meshes.new('tree_' + ob.name)
|
mesh = bpy.data.meshes.new('tree_' + ob.name)
|
||||||
ob_mesh = newCurveChild(mesh)
|
ob_mesh = newCurveChild(mesh)
|
||||||
# Do subsurf?
|
# do subsurf later
|
||||||
if PREFS['seg_density'].val:
|
|
||||||
mod = ob_mesh.modifiers.append(Blender.Modifier.Types.SUBSURF)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Existing object
|
# Existing object
|
||||||
@@ -1281,9 +1321,23 @@ def buildTree(ob):
|
|||||||
armature = bpy.data.armatures.new()
|
armature = bpy.data.armatures.new()
|
||||||
ob_arm = newCurveChild(armature)
|
ob_arm = newCurveChild(armature)
|
||||||
|
|
||||||
t.toArmature(armature)
|
t.toArmature(ob_arm, armature)
|
||||||
|
# Add the modifier.
|
||||||
|
mod = ob_mesh.modifiers.append(Blender.Modifier.Types.ARMATURE)
|
||||||
|
mod[Blender.Modifier.Settings.OBJECT] = ob_arm
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Add subsurf last it needed. so armature skinning is done first.
|
||||||
|
# Do subsurf?
|
||||||
|
if PREFS['seg_density'].val:
|
||||||
|
if not [mod for mod in ob_mesh.modifiers if mod.type == Blender.Modifier.Types.SUBSURF]:
|
||||||
|
mod = ob_mesh.modifiers.append(Blender.Modifier.Types.SUBSURF)
|
||||||
|
|
||||||
|
#ob_mesh.makeDisplayList()
|
||||||
|
#mesh.update()
|
||||||
|
bpy.data.scenes.active.update()
|
||||||
|
|
||||||
def Prefs2IDProp(idprop, prefs):
|
def Prefs2IDProp(idprop, prefs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -1403,7 +1457,7 @@ def gui():
|
|||||||
# ---------- ---------- ---------- ----------
|
# ---------- ---------- ---------- ----------
|
||||||
|
|
||||||
|
|
||||||
PREFS['do_armature'] = Draw.Toggle('Generate Armature', EVENT_NONE, xtmp, y, but_width*2, but_height, PREFS['do_armature'].val, 'Generate Armatuer'); xtmp += but_width*2;
|
PREFS['do_armature'] = Draw.Toggle('Generate Armature & Skin Mesh', EVENT_NONE, xtmp, y, but_width*4, but_height, PREFS['do_armature'].val, 'Generate Armatuer'); xtmp += but_width*4;
|
||||||
|
|
||||||
y-=but_height+MARGIN
|
y-=but_height+MARGIN
|
||||||
xtmp = x
|
xtmp = x
|
||||||
|
|||||||
Reference in New Issue
Block a user