0
$\begingroup$

The cone has it's tip going up the Z axis.

The goal is to have the cone hv it's Z axis up facing the same way the selected face's normal do.

When i run the script, the orientation was a bit off.

enter image description here

Code here:

import bpy
import bmesh
import mathutils

# Get the active mesh (assumes starting in edit mode)
obj = bpy.context.edit_object
mw = obj.matrix_world.copy()
bm = bmesh.from_edit_mesh(obj.data)
# for this example jmake a face active
face = bm.select_history.active
o = face.calc_center_median()
# calculate the axis dif in local coords

axis_src = face.normal
# local z-axis
axis_dst = mathutils.Vector((0, 0, 1))

matrix_rotate = mw.to_3x3()

matrix_rotate = matrix_rotate @ axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = mathutils.Matrix.Translation(mw @ o)

obj2 = bpy.context.view_layer.objects.get("Cone")
obj2.matrix_world = matrix_translation @ matrix_rotate.to_4x4()
$\endgroup$
6
  • $\begingroup$ How this question is different from your previous one: blender.stackexchange.com/questions/173150/… ? $\endgroup$
    – brockmann
    Commented Apr 4, 2020 at 18:19
  • $\begingroup$ i still dont get how to multiply between two matrix, i tried Matrix(matrix1, matrix2), returns the same error. $\endgroup$
    – adrian li
    Commented Apr 4, 2020 at 18:40
  • $\begingroup$ or if 3x3 matrix is different? if so how to fix that. $\endgroup$
    – adrian li
    Commented Apr 4, 2020 at 18:41
  • $\begingroup$ oh god i just realize the @ is the multiplier $\endgroup$
    – adrian li
    Commented Apr 4, 2020 at 19:02
  • $\begingroup$ allow me to edit the question a bit, because i know fixed the code with no error but the result is not expected $\endgroup$
    – adrian li
    Commented Apr 4, 2020 at 19:04

0

Browse other questions tagged .