SOLUTION:
I modified some code I found here.
def make_matrix(center, v1, v2, v3):
a = v2-v1
b = v3-v1
c = a.cross(b)
if c.magnitude>0:
c = c.normalized()
else:
raise BaseException("A B C are colinear")
b2 = c.cross(a).normalized()
a2 = a.normalized()
m = Matrix([a2, b2, c]).transposed()
s = a.magnitude
m = Matrix.Translation(center) * Matrix.Scale(1,4) * m.to_4x4()
return m
that function will give you the transformation matrix needed to properly place meshes or objects in the correct position on a given face.
“center”: the center position of the face. this is basically the new (0,0,0) point of the object being placed.
“v1, v2, v3”: three vertices that are part of the face that you want said object attached too.
then if m = trans_matrix:
bmesh.ops.transform(bm, matrix= trans_matrix, verts= bm.verts[-8:])
I used “bm.verts[-8:]” because the last eight verts that were created are the ones I needed moved. bm = bmesh.from_edit_mesh(bpy.context.object.data). this works on a mesh that is in edit mode.
I have a script that will attach polyhedrons to each other. I need a way to modify the x,y,z coordinates of the vertices of a mesh shape so that it is placed on a given face of another mesh object. I want to do this as I generate the vertices of the new object to be attached to the old. here is an example:
the only thing I can think of, is to get the face normal of the face that will have a new shape attached to it, and use that information somehow to position the new verts accordingly. how might I do this?
EDIT: yes, I know about duplifaces. unless there is something I don’t know about duplifaces, it won’t work for what I am doing.
EDIT: I found a wolframe alpha page that explains face normal vectors. hopefully I can understand it enough to make use of it