Python: setting editbone length flips bone Z axis #88581

Closed
opened 2021-05-25 22:40:55 +02:00 by Scurest · 9 comments
Contributor

System Information
Operating system: Linux
Graphics card: Intel HD

Blender Version
Broken: 3.0 (specifically I'm testing with f9567f6c63), also 2.83 (latest release fd30365201)
Worked: don't know

Short description of error

Setting editbone.length with Python to a specific value causes the bone's Z axis to flip.

Exact steps for others to reproduce the error
Open an empty .blend. Add an Armature. Turn on Armature > Viewport Display > Axes so you can see the bone axes. Switch to Edit mode.

Run this script

import bpy
ebone = bpy.data.armatures[0].edit_bones['Bone']

ebone.head = [0.0, 0.3999999761581421, 0.35000017285346985]
ebone.tail = [0.0, -0.6000005006790161, 0.34999972581863403]
ebone.align_roll( [1.509958593715055e-07, 1.7881393432617188e-07, 1.0000004768371582] )

The bone's Z axis is pointing up, as expected.

Now run

ebone.length =  0.11045359214368487

The bone's Z axis has flipped and is now pointing down! Now run the same line again. The Z axis flipped again, despite no change to the head/tail/roll! You can keep repeating this.

The pose position is also affected (so it isn't just a Viewport Display issue).

Other length values (eg. 0.11) do not trigger the issue.

flipping_z.png

Context

Discovered while investigating https://devtalk.blender.org/t/gltf-export-issue-upd-import-issue/18970. The magic numbers here are just the values the importer ends up with when importing that .glb file.

**System Information** Operating system: Linux Graphics card: Intel HD **Blender Version** Broken: 3.0 (specifically I'm testing with f9567f6c63), also 2.83 (latest release fd3036520101) Worked: don't know **Short description of error** Setting `editbone.length` with Python to a specific value causes the bone's Z axis to flip. **Exact steps for others to reproduce the error** Open an empty .blend. Add an Armature. Turn on Armature > Viewport Display > Axes so you can see the bone axes. Switch to Edit mode. Run this script ``` import bpy ebone = bpy.data.armatures[0].edit_bones['Bone'] ebone.head = [0.0, 0.3999999761581421, 0.35000017285346985] ebone.tail = [0.0, -0.6000005006790161, 0.34999972581863403] ebone.align_roll( [1.509958593715055e-07, 1.7881393432617188e-07, 1.0000004768371582] ) ``` The bone's Z axis is pointing up, as expected. Now run ``` ebone.length = 0.11045359214368487 ``` The bone's Z axis has flipped and is now pointing down! Now run the same line again. The Z axis flipped *again*, despite no change to the head/tail/roll! You can keep repeating this. The pose position is also affected (so it isn't just a Viewport Display issue). Other length values (eg. `0.11`) do not trigger the issue. ![flipping_z.png](https://archive.blender.org/developer/F10141842/flipping_z.png) **Context** Discovered while investigating https://devtalk.blender.org/t/gltf-export-issue-upd-import-issue/18970. The magic numbers here are just the values the importer ends up with when importing that .glb file.
Author
Contributor

Added subscriber: @scurest

Added subscriber: @scurest
Member

Added subscriber: @JulienDuroure

Added subscriber: @JulienDuroure
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Changed status from 'Needs Triage' to: 'Confirmed'

Changed status from 'Needs Triage' to: 'Confirmed'
Member

Can confirm this particular example (also the fact that other bone lengths dont give the same issues).

Can confirm this particular example (also the fact that other bone lengths dont give the same issues).

Added subscriber: @Azrael69

Added subscriber: @Azrael69
Author
Contributor

I tracked this down to the function vec_roll_to_mat3_normalized .

The formula for the matrix is poorly conditioned when nor is close to the -Y axis, so the code branches and the numbers in this issue are close to the branching threshold. Assigning to ebone.length slightly bumps the values so they cross the threshold.

So I'm now confident this is a dupe of #82455. The suggestion there (testing x*x+z*z>THETA_CRITICAL) fixes this issue.

(For some reason I can't get the "Close as Duplicate" widget to work. Sorry, can someone do it for me?)

I tracked this down to the function [vec_roll_to_mat3_normalized ](https://git.blender.org/gitweb/gitweb.cgi/blender.git/blob/9225fe933ae9904ea7bb646110308a921b37fc86:/source/blender/blenkernel/intern/armature.c#l2155). The formula for the matrix is poorly conditioned when nor is close to the -Y axis, so the code branches and the numbers in this issue are close to the branching threshold. Assigning to `ebone.length` slightly bumps the values so they cross the threshold. So I'm now confident this is a dupe of #82455. The suggestion there (testing `x*x+z*z>THETA_CRITICAL`) fixes this issue. (For some reason I can't get the "Close as Duplicate" widget to work. Sorry, can someone do it for me?)
Member

Thx for investigating, @scurest!

Thx for investigating, @scurest!
Member

Closed as duplicate of #82455

Closed as duplicate of #82455
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#88581
No description provided.