Parenting to faces

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
malefico
Posts: 43
Joined: Mon Oct 14, 2002 6:51 am

Parenting to faces

Post by malefico »

For python development gurus:

Hi, this is something I asked months ago in the Tuhopuu feature request tracker. A method that could allow parenting objects to single faces in a mesh.
I don't know if this is either easy or impossible to do. Just suggesting.

I think this would be really useful for animatable feathers, hair and all the things you would do with Beast for instance.
I was thinking about something like NMFace.makeParent(object) but this is probably nonsense for you.

Cheers.

malefico.

z3r0_d
Posts: 289
Joined: Wed Oct 16, 2002 2:38 am
Contact:

Post by z3r0_d »

is there an interface to vertex parenting in the first place?

[because, doing a face parent as a user is implemented as a vertex parent with 3 verts, perhaps the python interface should be the same?]

Ben
Posts: 9
Joined: Wed Oct 23, 2002 8:32 pm

Post by Ben »

-I'm not sure if is this you are looking for.This script
gets an object put it in the center of a face orientated
as its normal and if called everyframe makes the object
to follow the face position and orientation.Its usage is:
Parent(face, p_object, ch_object)
where:
face -- is the face
p_object -- is the object which has the face(parent)
ch_object -- is the child object to be parented with the face

Code: Select all

import Blender
from Blender import NMesh, Mathutils
from Blender.Mathutils import *

def Parent(face, p_obj, ch_obj):
	vlist = []
	nrvx = len(face.v)
	for n in range(nrvx) :
		vlist.append(face.v[n].co)
	if nrvx == 3:
		cen_x = (vlist[0][0] + vlist[1][0] + vlist[2][0]) / 3
		cen_y = (vlist[0][1] + vlist[1][1] + vlist[2][1]) / 3
		cen_z = (vlist[0][2] + vlist[1][2] + vlist[2][2]) / 3
	elif nrvx == 4 :
		cen_x_1 = (vlist[0][0] + vlist[1][0] + vlist[2][0]) / 3
		cen_y_1 = (vlist[0][1] + vlist[1][1] + vlist[2][1]) / 3
		cen_z_1 = (vlist[0][2] + vlist[1][2] + vlist[2][2]) / 3

		cen_x_2 = (vlist[2][0] + vlist[3][0] + vlist[0][0]) / 3
		cen_y_2 = (vlist[2][1] + vlist[3][1] + vlist[0][1]) / 3
		cen_z_2 = (vlist[2][2] + vlist[3][2] + vlist[0][2]) / 3

		cen_x = (cen_x_1 + cen_x_2) / 2 
		cen_y = (cen_y_1 + cen_y_2) / 2 
		cen_z = (cen_z_1 + cen_z_2) / 2

	mid_p = Vector([(vlist[0][0] - vlist[1][0])/2, 
					(vlist[0][1] - vlist[1][1])/2,
					(vlist[0][2] - vlist[1][2])/2])
	mid_p.normalize()
	local_cen = Vector([cen_x, cen_y, cen_z])            #the center of the face
	trans_mat = TranslationMatrix(local_cen)
	no_vec = Vector(face.normal)
	no_vec.normalize()
	z_vec = CrossVecs(mid_p, no_vec)
	rot_mat = Matrix(
					[no_vec[0], no_vec[1], no_vec[2], 0],
					[z_vec[0], z_vec[1], z_vec[2], 0],
					[mid_p[0], mid_p[1], mid_p[2], 0],
					[0, 0, 0, 1])
	mat_face = rot_mat * trans_mat
	mat = p_obj.matrix
	mat_f = mat_face * mat
	ch_obj.setMatrix(mat_f)
Ben

malefico
Posts: 43
Joined: Mon Oct 14, 2002 6:51 am

Post by malefico »

Thanks Ben for the script, however for my own purposes I need a real parenting, that's why I'm suggesting development in that area.

z3r0_d: I don't think there is an interface to vertex parent either... I know, parenting to three vertices would work... but I think it can't be done right now.

So I could reformulate the request: Are there any plans to implement an interface to vertex/face parenting ? Is there any developer interested in developing such a thing ?

Post Reply