Skip to main content
added 340 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 54.7 degrees about axis (-1, 1, 0).

Think of it like the rotation from 12 o'clock to 3 o'clock on a clockface, is 90 degrees about the axis of the hands. Applying to hand at 12 o'clock moves to 3 o'clock. Applying again from 3 to 6 o'clock and so on.

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8

To set the bone absolutely from the vector, can use Vector.track_to_quat(to, up)Vector.track_to_quat(to, up) For bones track to the 'Y' axis, along the bone. I have arbitrarily chosen 'Z" as up.

>>> v = Vector((1, 1, 1))
>>> q = v.to_track_quat('Y', 'Z')
>>> C.active_pose_bone.rotation_quaternion = q
>>> x = C.active_pose_bone.tail.x
>>> x * x
0.33333332136784577

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 54.7 degrees about axis (-1, 1, 0).

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8

To set the bone absolutely from the vector, can use Vector.track_to_quat(to, up) For bones track to the 'Y' axis, along the bone. I have arbitrarily chosen 'Z" as up.

>>> v = Vector((1, 1, 1))
>>> q = v.to_track_quat('Y', 'Z')
>>> C.active_pose_bone.rotation_quaternion = q
>>> x = C.active_pose_bone.tail.x
>>> x * x
0.33333332136784577

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 54.7 degrees about axis (-1, 1, 0).

Think of it like the rotation from 12 o'clock to 3 o'clock on a clockface, is 90 degrees about the axis of the hands. Applying to hand at 12 o'clock moves to 3 o'clock. Applying again from 3 to 6 o'clock and so on.

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8

To set the bone absolutely from the vector, can use Vector.track_to_quat(to, up) For bones track to the 'Y' axis, along the bone. I have arbitrarily chosen 'Z" as up.

>>> v = Vector((1, 1, 1))
>>> q = v.to_track_quat('Y', 'Z')
>>> C.active_pose_bone.rotation_quaternion = q
>>> x = C.active_pose_bone.tail.x
>>> x * x
0.33333332136784577
added 378 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 54.7 degrees about axis (-1, 1, 0).

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8

To set the bone absolutely from the vector, can use Vector.track_to_quat(to, up) For bones track to the 'Y' axis, along the bone. I have arbitrarily chosen 'Z" as up.

>>> v = Vector((1, 1, 1))
>>> q = v.to_track_quat('Y', 'Z')
>>> C.active_pose_bone.rotation_quaternion = q
>>> x = C.active_pose_bone.tail.x
>>> x * x
0.33333332136784577

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 54.7 degrees about axis (-1, 1, 0).

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 54.7 degrees about axis (-1, 1, 0).

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8

To set the bone absolutely from the vector, can use Vector.track_to_quat(to, up) For bones track to the 'Y' axis, along the bone. I have arbitrarily chosen 'Z" as up.

>>> v = Vector((1, 1, 1))
>>> q = v.to_track_quat('Y', 'Z')
>>> C.active_pose_bone.rotation_quaternion = q
>>> x = C.active_pose_bone.tail.x
>>> x * x
0.33333332136784577
added 3 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 4554.7 degrees about axis (-1, 1, 10).

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 45 degrees about axis (1, 1, 1).

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8

Apply the rotation

Apply the rotational difference between to vectors to the pose bone, rather than setting the pose bones rotation with it.

The rot diff has an axis and angle. Applying the rotation rotates the pose bone, which in this case is angle 54.7 degrees about axis (-1, 1, 0).

import bpy
from mathutils import Vector

up = Vector((0, 0, 1))
dest = Vector((1, 1, 1))

R = up.rotation_difference(dest).to_matrix().to_4x4()

pb = bpy.context.active_pose_bone
pb.matrix = R * pb.matrix
pb.matrix = R @ pb.matrix #  2.8
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244
Loading