Skip to main content
deleted 4 characters in body
Source Link
tetii
  • 1.8k
  • 1
  • 10
  • 16

Script:

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2

Settings:

Turn on in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45

enter image description hereenter image description here

Additions:
Original script has two mistakes.

  1. Transformation matrix for converting to world space is

    object.matrix_world @ pose_bone.matrix

  2. Vector myvec needs to be normalized.

Script:

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2

Settings:

Turn on in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45

enter image description here

Additions:
Original script has two mistakes.

  1. Transformation matrix for converting to world space is

    object.matrix_world @ pose_bone.matrix

  2. Vector myvec needs to be normalized.

Script:

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2

Settings:

Turn on in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45

enter image description here

Additions:
Original script has two mistakes.

  1. Transformation matrix for converting to world space is

    object.matrix_world @ pose_bone.matrix

  2. Vector myvec needs to be normalized.

added 204 characters in body
Source Link
tetii
  • 1.8k
  • 1
  • 10
  • 16

Script:
 

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2

Settings:
 

Turn on in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45

enter image description here

Additions:
Original script has two mistakes.

  1. Transformation matrix for converting to world space is

    object.matrix_world @ pose_bone.matrix

  2. Vector myvec needs to be normalized.

Script:
 

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2

Settings:
 

Turn on in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45

enter image description here

Script:

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2

Settings:

Turn on in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45

enter image description here

Additions:
Original script has two mistakes.

  1. Transformation matrix for converting to world space is

    object.matrix_world @ pose_bone.matrix

  2. Vector myvec needs to be normalized.

Source Link
tetii
  • 1.8k
  • 1
  • 10
  • 16

Script:

import bpy
import math

def test_fn2(pose_bone):
    rig = pose_bone.id_data
    mat = rig.matrix_world @ pose_bone.matrix
    vec = mat.col[1].normalized()
    angle = math.degrees(math.acos(vec[2]))
    return angle

bpy.app.driver_namespace["test_fn2"] = test_fn2

Settings:

Turn on in Text Editor. And Auto Run Python Scripts in User Preferences if you need.

Expression: test_fn2(bones["Bone"])/45

enter image description here