All pastes #586632 Raw Edit

Something

public text v1 · immutable
#586632 ·published 2007-06-23 23:24 UTC
rendered paste body
# Function MakeOctaedron() creates an octaedron with the given Lenght
import Blender
from Blender import *


def MakeOctaedron(L):
	
	editmode = Window.EditMode()    # are we in edit mode?  If so ...
	if editmode: Window.EditMode(0) # leave edit mode before getting the mesh
	
	# define vertices and faces for an octaedron
	
	D = 0.12	# distancia de semidiametro mayor del octaedro al extremo
	#L= 4.0	# longitud del hueso octaedro.
	coords=[ [0,0,0], [D, D, D], [D, D, -D], [-D, D, -D],[-D, D, D], [0,L,0]]
	#coords=[ [-1,-1,-1], [1,-1,-1], [1,1,-1], [-1,1,-1], [0,0,1] ]  
	faces= [ [0,1,2], [0,2,3], [0,3,4], [0,4,1], [5,1,2],[5,2,3],[5,3,4],[5,4,1] ]
	
	me = Mesh.New('Bone')          # create a new mesh
	
	me.verts.extend(coords)          # add vertices to mesh
	me.faces.extend(faces)           # add faces to the mesh (also adds edges)
	
	scn = Scene.GetCurrent()          # link object to current scene
	ob = scn.objects.new(me, 'BoneMesh')
	
	return ob
	if editmode: Window.EditMode(1)  # optional, just being nice
		
#MakeOctaedron(12.0) # Makes a sample Octaedron

def ReadBones():
	scn= Scene.GetCurrent()
	arm_ob= scn.objects.active

	if not arm_ob or arm_ob.type != 'Armature':
		Draw.PupMenu('not an armature object')
		return

# Deselect all
	for ob in scn.objects:
		if ob != arm_ob:
			ob.sel= 0
	arm_mat= arm_ob.matrixWorld
	arm_data= arm_ob.getData()
	bones= arm_data.bones.values()
	print "huesos", bones
 	for bone in bones:
		bone_mat= bone.matrix['ARMATURESPACE']
		bone_mat_world= bone_mat*arm_mat
		bone_len= bone.length
		print bone_len
		if Blender.Armature.NO_DEFORM not in bone.options:
			print "Hueso no deformable", bone.name
			octaedron = MakeOctaedron(bone_len)
			octaedron.setMatrix(bone_mat_world)
			arm_ob.makeParentBone(octaedron, bone.name)
			print "Emparente malla: ",octaedron, "a hueso: ", bone.name
		#print bone_len
#   ob_empty= scn.objects.new('Empty')
#   ob_empty.setMatrix(bone_mat_world)

ReadBones()