Shape key 008 has wrong frame time when created from python script #63326

Closed
opened 2019-04-06 00:19:53 +02:00 by Arno Mayrhofer · 7 comments

System Information
Operating system: Ubuntu 18.04
Graphics card: Built in Intel GP

Blender Version
Broken: version: 2.80 (sub 53), branch: blender2.7, commit date: 2019-04-03 23:27, hash: 0e78e3038d, type: Release
Worked: unknown

Short description of error
When creating a mesh from a python script and adding shape keys in a loop Key.008 has frame = 70 instead of 80. (all others are correct)

Exact steps for others to reproduce the error
Based on the default startup run the following script. The script is the default template to add an object and only has a few minor changes marked in a commented block.

bl_info = {
    "name": "New Object",
    "author": "Your Name Here",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "View3D > Add > Mesh > New Object",
    "description": "Adds a new Mesh Object",
    "warning": "",
    "wiki_url": "",
    "category": "Add Mesh",
}


import bpy
from bpy.types import Operator
from bpy.props import FloatVectorProperty
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector


def add_object(self, context):
    scale_x = self.scale.x
    scale_y = self.scale.y

    verts = [
        Vector((-1 * scale_x, 1 * scale_y, 0)),
        Vector((1 * scale_x, 1 * scale_y, 0)),
        Vector((1 * scale_x, -1 * scale_y, 0)),
        Vector((-1 * scale_x, -1 * scale_y, 0)),
    ]

    edges = []
    faces = [[0, 1, 2, 3]]

    mesh = bpy.data.meshes.new(name="New Object Mesh")
    mesh.from_pydata(verts, edges, faces)
    - useful for development when the mesh may be invalid.
    - mesh.validate(verbose=True)
    object_data_add(context, mesh, operator=self)

    ##########
    - added code to generate shape keys

    ob = bpy.context.object
    ob.shape_key_add()
    ob.data.shape_keys.use_relative = False
    for i in range(10):
        ob.shape_key_add()
        ob.active_shape_key_index = i+1
        ob.data.shape_keys.eval_time = 10*(i+1)

    - end added code
    ##########


class OBJECT_OT_add_object(Operator, AddObjectHelper):
    """Create a new Mesh Object"""
    bl_idname = "mesh.add_object"
    bl_label = "Add Mesh Object"
    bl_options = {'REGISTER', 'UNDO'}

    scale: FloatVectorProperty(
        name="scale",
        default=(1.0, 1.0, 1.0),
        subtype='TRANSLATION',
        description="scaling",
    )

    def execute(self, context):

        add_object(self, context)

        return {'FINISHED'}


# Registration

def add_object_button(self, context):
    self.layout.operator(
        OBJECT_OT_add_object.bl_idname,
        text="Add Object",
        icon='PLUGIN')


# This allows you to right click on a button and link to the manual
def add_object_manual_map():
    url_manual_prefix = "https://docs.blender.org/manual/en/dev/"
    url_manual_mapping = (
        ("bpy.ops.mesh.add_object", "editors/3dview/object"),
    )
    return url_manual_prefix, url_manual_mapping


def register():
    bpy.utils.register_class(OBJECT_OT_add_object)
    bpy.utils.register_manual_map(add_object_manual_map)
    bpy.types.VIEW3D_MT_mesh_add.append(add_object_button)


def unregister():
    bpy.utils.unregister_class(OBJECT_OT_add_object)
    bpy.utils.unregister_manual_map(add_object_manual_map)
    bpy.types.VIEW3D_MT_mesh_add.remove(add_object_button)


if __name__ == "__main__":
    register()


Once the script was run, perform the adding of the object (Add->Mesh->Add Object) and investigate the shape keys. The output I get is the following:

Screenshot from 2019-04-06 00-14-36.png

Clearly, Key.008 should have a frame value of 80 instead of 70. All the other keys are fine.

I actually have a more complicated script that actually modifies the mesh across those keys and the animation really is broken at this frame.

**System Information** Operating system: Ubuntu 18.04 Graphics card: Built in Intel GP **Blender Version** Broken: version: 2.80 (sub 53), branch: blender2.7, commit date: 2019-04-03 23:27, hash: 0e78e3038d02, type: Release Worked: unknown **Short description of error** When creating a mesh from a python script and adding shape keys in a loop Key.008 has frame = 70 instead of 80. (all others are correct) **Exact steps for others to reproduce the error** Based on the default startup run the following script. The script is the default template to add an object and only has a few minor changes marked in a commented block. ``` bl_info = { "name": "New Object", "author": "Your Name Here", "version": (1, 0), "blender": (2, 80, 0), "location": "View3D > Add > Mesh > New Object", "description": "Adds a new Mesh Object", "warning": "", "wiki_url": "", "category": "Add Mesh", } import bpy from bpy.types import Operator from bpy.props import FloatVectorProperty from bpy_extras.object_utils import AddObjectHelper, object_data_add from mathutils import Vector def add_object(self, context): scale_x = self.scale.x scale_y = self.scale.y verts = [ Vector((-1 * scale_x, 1 * scale_y, 0)), Vector((1 * scale_x, 1 * scale_y, 0)), Vector((1 * scale_x, -1 * scale_y, 0)), Vector((-1 * scale_x, -1 * scale_y, 0)), ] edges = [] faces = [[0, 1, 2, 3]] mesh = bpy.data.meshes.new(name="New Object Mesh") mesh.from_pydata(verts, edges, faces) - useful for development when the mesh may be invalid. - mesh.validate(verbose=True) object_data_add(context, mesh, operator=self) ########## - added code to generate shape keys ob = bpy.context.object ob.shape_key_add() ob.data.shape_keys.use_relative = False for i in range(10): ob.shape_key_add() ob.active_shape_key_index = i+1 ob.data.shape_keys.eval_time = 10*(i+1) - end added code ########## class OBJECT_OT_add_object(Operator, AddObjectHelper): """Create a new Mesh Object""" bl_idname = "mesh.add_object" bl_label = "Add Mesh Object" bl_options = {'REGISTER', 'UNDO'} scale: FloatVectorProperty( name="scale", default=(1.0, 1.0, 1.0), subtype='TRANSLATION', description="scaling", ) def execute(self, context): add_object(self, context) return {'FINISHED'} # Registration def add_object_button(self, context): self.layout.operator( OBJECT_OT_add_object.bl_idname, text="Add Object", icon='PLUGIN') # This allows you to right click on a button and link to the manual def add_object_manual_map(): url_manual_prefix = "https://docs.blender.org/manual/en/dev/" url_manual_mapping = ( ("bpy.ops.mesh.add_object", "editors/3dview/object"), ) return url_manual_prefix, url_manual_mapping def register(): bpy.utils.register_class(OBJECT_OT_add_object) bpy.utils.register_manual_map(add_object_manual_map) bpy.types.VIEW3D_MT_mesh_add.append(add_object_button) def unregister(): bpy.utils.unregister_class(OBJECT_OT_add_object) bpy.utils.unregister_manual_map(add_object_manual_map) bpy.types.VIEW3D_MT_mesh_add.remove(add_object_button) if __name__ == "__main__": register() ``` Once the script was run, perform the adding of the object (Add->Mesh->Add Object) and investigate the shape keys. The output I get is the following: ![Screenshot from 2019-04-06 00-14-36.png](https://archive.blender.org/developer/F6914321/Screenshot_from_2019-04-06_00-14-36.png) Clearly, Key.008 should have a frame value of 80 instead of 70. All the other keys are fine. I actually have a more complicated script that actually modifies the mesh across those keys and the animation really is broken at this frame.
Author

Added subscriber: @azrael3000

Added subscriber: @azrael3000
Author

Fix for this issue can be found in D4656. Cause was a floating point comparison and associated precision issues.

Fix for this issue can be found in [D4656](https://archive.blender.org/developer/D4656). Cause was a floating point comparison and associated precision issues.

Added subscriber: @ZedDB

Added subscriber: @ZedDB
Arno Mayrhofer was assigned by Sebastian Parborg 2019-04-07 18:07:45 +02:00

I'll assign this to you are you already have come up with a solution. Good job!

I'll assign this to you are you already have come up with a solution. Good job!
Author

That's fine. Thanks.

That's fine. Thanks.

This issue was referenced by 2a79e34631

This issue was referenced by 2a79e34631303edbf1853c5cdf81a04333d094a0

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser Project (Legacy)
Interest
Asset System
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#63326
No description provided.