Skip to main content
edited body
Source Link
ideasman42
  • 48k
  • 10
  • 144
  • 226

Blender doesn't have a tool built-in to perform this operation currently.

If you would write your own tool, a method you can use to achieve this using Python.

  • Define the source vector (face normal in this case).
  • Define the destination vector (the axis vector).
  • Use the rotation between these vectors to define a 3D rotation
    (see Vector.rotation_difference).
  • Then rotate your object by this.

This example uses the normal of the first face, assumes object

import bpy
from mathutils import Matrix, Vector

obj = bpy.context.object
matrix_orig = obj.matrix_world.copy()

# for this example just pick the first face.
axis_src = matrix_orig.to_3x3() * obj.data.polygons[0].normal
# z-axis, could be any direction
axis_dst = Vector((0, 0, 1))

matrix_rotate = matrix_prevmatrix_orig.to_3x3()
matrix_rotate = matrix_rotate * axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = Matrix.Translation(matrix_orig.to_translation())

obj.matrix_world = matrix_translation * matrix_rotate.to_4x4()

Blender doesn't have a tool built-in to perform this operation currently.

If you would write your own tool, a method you can use to achieve this using Python.

  • Define the source vector (face normal in this case).
  • Define the destination vector (the axis vector).
  • Use the rotation between these vectors to define a 3D rotation
    (see Vector.rotation_difference).
  • Then rotate your object by this.

This example uses the normal of the first face, assumes object

import bpy
from mathutils import Matrix, Vector

obj = bpy.context.object
matrix_orig = obj.matrix_world.copy()

# for this example just pick the first face.
axis_src = matrix_orig.to_3x3() * obj.data.polygons[0].normal
# z-axis, could be any direction
axis_dst = Vector((0, 0, 1))

matrix_rotate = matrix_prev.to_3x3()
matrix_rotate = matrix_rotate * axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = Matrix.Translation(matrix_orig.to_translation())

obj.matrix_world = matrix_translation * matrix_rotate.to_4x4()

Blender doesn't have a tool built-in to perform this operation currently.

If you would write your own tool, a method you can use to achieve this using Python.

  • Define the source vector (face normal in this case).
  • Define the destination vector (the axis vector).
  • Use the rotation between these vectors to define a 3D rotation
    (see Vector.rotation_difference).
  • Then rotate your object by this.

This example uses the normal of the first face, assumes object

import bpy
from mathutils import Matrix, Vector

obj = bpy.context.object
matrix_orig = obj.matrix_world.copy()

# for this example just pick the first face.
axis_src = matrix_orig.to_3x3() * obj.data.polygons[0].normal
# z-axis, could be any direction
axis_dst = Vector((0, 0, 1))

matrix_rotate = matrix_orig.to_3x3()
matrix_rotate = matrix_rotate * axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = Matrix.Translation(matrix_orig.to_translation())

obj.matrix_world = matrix_translation * matrix_rotate.to_4x4()
added 12 characters in body
Source Link
ideasman42
  • 48k
  • 10
  • 144
  • 226

ABlender doesn't have a tool built-in to perform this operation currently.

If you would write your own tool, a method you can use to achieve this using Python.

  • Define the source vector (face normal in this case).
  • Define the destination vector (the axis vector).
  • Use the rotation between these vectors to define a 3D rotation
    (see Vector.rotation_difference).
  • Then rotate your object by this.

This example uses the normal of the first face, assumes object

import bpy
from mathutils import Matrix, Vector

obj = bpy.context.object
matrix_prevmatrix_orig = obj.matrix_world.copy() 

# for this example just pick the first face.
axis_src = matrix_prevmatrix_orig.to_3x3() * obj.data.polygons[0].normal
# z-axis, could be any direction
axis_dst = Vector((0, 0, 1))
matrix_3x3
matrix_rotate = matrix_prev.to_3x3()
matrix_3x3matrix_rotate = matrix_3x3matrix_rotate * axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = Matrix.Translation(matrix_prevmatrix_orig.to_translation())

obj.matrix_world = matrix_translation * matrix_3x3matrix_rotate.to_4x4()

A method you can use to achieve this using Python.

  • Define the source vector (face normal in this case).
  • Define the destination vector (the axis vector).
  • Use the rotation between these vectors to define a 3D rotation
    (see Vector.rotation_difference).
  • Then rotate your object by this.

This example uses the normal of the first face, assumes object

import bpy
from mathutils import Matrix, Vector

obj = bpy.context.object
matrix_prev = obj.matrix_world.copy()
# for this example just pick the first face.
axis_src = matrix_prev.to_3x3() * obj.data.polygons[0].normal
axis_dst = Vector((0, 0, 1))
matrix_3x3 = matrix_prev.to_3x3()
matrix_3x3 = matrix_3x3 * axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = Matrix.Translation(matrix_prev.to_translation())

obj.matrix_world = matrix_translation * matrix_3x3.to_4x4()

Blender doesn't have a tool built-in to perform this operation currently.

If you would write your own tool, a method you can use to achieve this using Python.

  • Define the source vector (face normal in this case).
  • Define the destination vector (the axis vector).
  • Use the rotation between these vectors to define a 3D rotation
    (see Vector.rotation_difference).
  • Then rotate your object by this.

This example uses the normal of the first face, assumes object

import bpy
from mathutils import Matrix, Vector

obj = bpy.context.object
matrix_orig = obj.matrix_world.copy() 

# for this example just pick the first face.
axis_src = matrix_orig.to_3x3() * obj.data.polygons[0].normal
# z-axis, could be any direction
axis_dst = Vector((0, 0, 1))

matrix_rotate = matrix_prev.to_3x3()
matrix_rotate = matrix_rotate * axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = Matrix.Translation(matrix_orig.to_translation())

obj.matrix_world = matrix_translation * matrix_rotate.to_4x4()
Source Link
ideasman42
  • 48k
  • 10
  • 144
  • 226

A method you can use to achieve this using Python.

  • Define the source vector (face normal in this case).
  • Define the destination vector (the axis vector).
  • Use the rotation between these vectors to define a 3D rotation
    (see Vector.rotation_difference).
  • Then rotate your object by this.

This example uses the normal of the first face, assumes object

import bpy
from mathutils import Matrix, Vector

obj = bpy.context.object
matrix_prev = obj.matrix_world.copy()
# for this example just pick the first face.
axis_src = matrix_prev.to_3x3() * obj.data.polygons[0].normal
axis_dst = Vector((0, 0, 1))
matrix_3x3 = matrix_prev.to_3x3()
matrix_3x3 = matrix_3x3 * axis_src.rotation_difference(axis_dst).to_matrix()
matrix_translation = Matrix.Translation(matrix_prev.to_translation())

obj.matrix_world = matrix_translation * matrix_3x3.to_4x4()