Python mesh.from_pydata() without faces won't show mesh until in/out edit mode #57366

Closed
opened 2018-10-24 00:49:32 +02:00 by Dalai Felinto · 7 comments

Blender Version
Broken: ed7f6b511f81 (blender2.8 HEAD)
Worked: 2.79a

Short description of error
Meshes created with Python, and the mesh.from_pydata() function are "invisible" until we go in and out of edit mode.
The data seems valid though, since the object Dimensions is correct even when the mesh is invisible.

Exact steps for others to reproduce the error
Run the following script in the Text editor. In 2.79 it works fine. In 2.8 you have to toggle in and out of edit mode to see the mesh.

Maybe the issue is only that the API changed. If that's the case we need to update the release notes .

import bpy

# Create mesh object
mesh = bpy.data.meshes.new("Malha")
obj = bpy.data.objects.new("Objeto", mesh)

if hasattr(bpy.context, "collection"):
    # Blender 2.8
    bpy.context.collection.objects.link(obj)
    bpy.context.view_layer.objects.active = obj
    obj.select_set('SELECT')
else:
    # Blender 2.7x
    bpy.context.scene.objects.link(obj)
    bpy.context.scene.objects.active = obj
    obj.select = True

verts = [(0.8, 0.2, 0.0), (0.5, 0.6, 0.0), (0.3, 0.3, 0.0)]
edges = [(0, 1), (1, 2), (2, 0)]
faces = []
#faces = [(0, 1, 2)]

mesh = obj.data
mesh.from_pydata(verts, edges, faces)
mesh.update()

For a more interesting mesh use:

verts = [(0.7071067690849304, 0.7071067690849304, 0.0), (0.7071067690849304, -0.7071067690849304, 0.0), (-0.7071067690849304, 0.7071067690849304, 0.0), (-0.7071067690849304, -0.7071067690849304, 0.0), (0.8314696550369263, 0.5555701851844788, 0.0), (0.8314696550369263, -0.5555701851844788, 0.0), (-0.8314696550369263, 0.5555701851844788, 0.0), (-0.8314696550369263, -0.5555701851844788, 0.0), (0.9238795042037964, 0.3826834261417389, 0.0), (0.9238795042037964, -0.3826834261417389, 0.0), (-0.9238795042037964, 0.3826834261417389, 0.0), (-0.9238795042037964, -0.3826834261417389, 0.0), (0.9807852506637573, 0.19509035348892212, 0.0), (0.9807852506637573, -0.19509035348892212, 0.0), (-0.9807852506637573, 0.19509035348892212, 0.0), (-0.9807852506637573, -0.19509035348892212, 0.0), (0.19509197771549225, 0.9807849526405334, 0.0), (0.19509197771549225, -0.9807849526405334, 0.0), (-0.19509197771549225, 0.9807849526405334, 0.0), (-0.19509197771549225, -0.9807849526405334, 0.0), (0.3826850652694702, 0.9238788485527039, 0.0), (0.3826850652694702, -0.9238788485527039, 0.0), (-0.3826850652694702, 0.9238788485527039, 0.0), (-0.3826850652694702, -0.9238788485527039, 0.0), (0.5555717945098877, 0.8314685821533203, 0.0), (0.5555717945098877, -0.8314685821533203, 0.0), (-0.5555717945098877, 0.8314685821533203, 0.0), (-0.5555717945098877, -0.8314685821533203, 0.0), (0.19509197771549225, 1.2807848453521729, 0.0), (0.19509197771549225, -1.2807848453521729, 0.0), (-0.19509197771549225, 1.2807848453521729, 0.0), (-0.19509197771549225, -1.2807848453521729, 0.0), (1.280785322189331, 0.19509035348892212, 0.0), (1.280785322189331, -0.19509035348892212, 0.0), (-1.280785322189331, 0.19509035348892212, 0.0), (-1.280785322189331, -0.19509035348892212, 0.0), (0.3950919806957245, 1.2807848453521729, 0.0), (0.3950919806957245, -1.2807848453521729, 0.0), (-0.3950919806957245, 1.2807848453521729, 0.0), (-0.3950919806957245, -1.2807848453521729, 0.0), (1.280785322189331, 0.39509034156799316, 0.0), (1.280785322189331, -0.39509034156799316, 0.0), (-1.280785322189331, 0.39509034156799316, 0.0), (-1.280785322189331, -0.39509034156799316, 0.0), (0.0, 1.5807849168777466, 0.0), (0.0, -1.5807849168777466, 0.0), (1.5807852745056152, 0.0, 0.0), (-1.5807852745056152, 0.0, 0.0)]

edges = [(0, 4), (1, 5), (2, 6), (3, 7), (4, 8), (5, 9), (6, 10), (7, 11), (8, 12), (9, 13), (10, 14), (11, 15), (16, 20), (17, 21), (18, 22), (19, 23), (20, 24), (21, 25), (22, 26), (23, 27), (0, 24), (1, 25), (2, 26), (3, 27), (16, 28), (17, 29), (18, 30), (19, 31), (12, 32), (13, 33), (14, 34), (15, 35), (28, 36), (29, 37), (30, 38), (31, 39), (32, 40), (33, 41), (34, 42), (35, 43), (36, 44), (37, 45), (38, 44), (39, 45), (40, 46), (41, 46), (42, 47), (43, 47)]
**Blender Version** Broken: ed7f6b511f81 (blender2.8 HEAD) Worked: 2.79a **Short description of error** Meshes created with Python, and the `mesh.from_pydata()` function are "invisible" until we go in and out of edit mode. The data seems valid though, since the object Dimensions is correct even when the mesh is invisible. **Exact steps for others to reproduce the error** Run the following script in the Text editor. In 2.79 it works fine. In 2.8 you have to toggle in and out of edit mode to see the mesh. Maybe the issue is only that the API changed. If that's the case we need to update the [release notes ](https://wiki.blender.org/wiki/Reference/Release_Notes/2.80/Python_API). ``` import bpy # Create mesh object mesh = bpy.data.meshes.new("Malha") obj = bpy.data.objects.new("Objeto", mesh) if hasattr(bpy.context, "collection"): # Blender 2.8 bpy.context.collection.objects.link(obj) bpy.context.view_layer.objects.active = obj obj.select_set('SELECT') else: # Blender 2.7x bpy.context.scene.objects.link(obj) bpy.context.scene.objects.active = obj obj.select = True verts = [(0.8, 0.2, 0.0), (0.5, 0.6, 0.0), (0.3, 0.3, 0.0)] edges = [(0, 1), (1, 2), (2, 0)] faces = [] #faces = [(0, 1, 2)] mesh = obj.data mesh.from_pydata(verts, edges, faces) mesh.update() ``` For a more interesting mesh use: ``` verts = [(0.7071067690849304, 0.7071067690849304, 0.0), (0.7071067690849304, -0.7071067690849304, 0.0), (-0.7071067690849304, 0.7071067690849304, 0.0), (-0.7071067690849304, -0.7071067690849304, 0.0), (0.8314696550369263, 0.5555701851844788, 0.0), (0.8314696550369263, -0.5555701851844788, 0.0), (-0.8314696550369263, 0.5555701851844788, 0.0), (-0.8314696550369263, -0.5555701851844788, 0.0), (0.9238795042037964, 0.3826834261417389, 0.0), (0.9238795042037964, -0.3826834261417389, 0.0), (-0.9238795042037964, 0.3826834261417389, 0.0), (-0.9238795042037964, -0.3826834261417389, 0.0), (0.9807852506637573, 0.19509035348892212, 0.0), (0.9807852506637573, -0.19509035348892212, 0.0), (-0.9807852506637573, 0.19509035348892212, 0.0), (-0.9807852506637573, -0.19509035348892212, 0.0), (0.19509197771549225, 0.9807849526405334, 0.0), (0.19509197771549225, -0.9807849526405334, 0.0), (-0.19509197771549225, 0.9807849526405334, 0.0), (-0.19509197771549225, -0.9807849526405334, 0.0), (0.3826850652694702, 0.9238788485527039, 0.0), (0.3826850652694702, -0.9238788485527039, 0.0), (-0.3826850652694702, 0.9238788485527039, 0.0), (-0.3826850652694702, -0.9238788485527039, 0.0), (0.5555717945098877, 0.8314685821533203, 0.0), (0.5555717945098877, -0.8314685821533203, 0.0), (-0.5555717945098877, 0.8314685821533203, 0.0), (-0.5555717945098877, -0.8314685821533203, 0.0), (0.19509197771549225, 1.2807848453521729, 0.0), (0.19509197771549225, -1.2807848453521729, 0.0), (-0.19509197771549225, 1.2807848453521729, 0.0), (-0.19509197771549225, -1.2807848453521729, 0.0), (1.280785322189331, 0.19509035348892212, 0.0), (1.280785322189331, -0.19509035348892212, 0.0), (-1.280785322189331, 0.19509035348892212, 0.0), (-1.280785322189331, -0.19509035348892212, 0.0), (0.3950919806957245, 1.2807848453521729, 0.0), (0.3950919806957245, -1.2807848453521729, 0.0), (-0.3950919806957245, 1.2807848453521729, 0.0), (-0.3950919806957245, -1.2807848453521729, 0.0), (1.280785322189331, 0.39509034156799316, 0.0), (1.280785322189331, -0.39509034156799316, 0.0), (-1.280785322189331, 0.39509034156799316, 0.0), (-1.280785322189331, -0.39509034156799316, 0.0), (0.0, 1.5807849168777466, 0.0), (0.0, -1.5807849168777466, 0.0), (1.5807852745056152, 0.0, 0.0), (-1.5807852745056152, 0.0, 0.0)] edges = [(0, 4), (1, 5), (2, 6), (3, 7), (4, 8), (5, 9), (6, 10), (7, 11), (8, 12), (9, 13), (10, 14), (11, 15), (16, 20), (17, 21), (18, 22), (19, 23), (20, 24), (21, 25), (22, 26), (23, 27), (0, 24), (1, 25), (2, 26), (3, 27), (16, 28), (17, 29), (18, 30), (19, 31), (12, 32), (13, 33), (14, 34), (15, 35), (28, 36), (29, 37), (30, 38), (31, 39), (32, 40), (33, 41), (34, 42), (35, 43), (36, 44), (37, 45), (38, 44), (39, 45), (40, 46), (41, 46), (42, 47), (43, 47)] ```
Author
Owner

Added subscriber: @dfelinto

Added subscriber: @dfelinto
Campbell Barton was assigned by Dalai Felinto 2018-10-24 00:51:02 +02:00
Author
Owner

Added subscribers: @fclem, @ideasman42

Added subscribers: @fclem, @ideasman42
Author
Owner

Assigning to @ideasman42 but I suspect the issue may be the drawing caches, so poking @fclem as well.

Assigning to @ideasman42 but I suspect the issue may be the drawing caches, so poking @fclem as well.
Author
Owner

And if you want a "production" example of this:

  • Enable the Rigify addon.
  • Add > Armature > Human (Meta-Rig).
  • In the Armature tab > Generate Rig (and wait, it takes some time).

To fix the file turn the Widgets collection visible, select all objects and toggle in and out of edit mesh mode (multi-objects never came so handy).

And if you want a "production" example of this: * Enable the Rigify addon. * Add > Armature > Human (Meta-Rig). * In the Armature tab > Generate Rig (and wait, it takes some time). To fix the file turn the Widgets collection visible, select all objects and toggle in and out of edit mesh mode (multi-objects never came so handy).

This issue was referenced by blender/blender@901ccfab52

This issue was referenced by blender/blender@901ccfab52ada8e46a61c1dce56fa43c291fb935

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Author
Owner

Thank you, rigify working fine now, assign from some:
//source/blender/blenkernel/intern/cdderivedmesh.c:157:2: runtime error: null pointer passed as argument 1, which is declared to never be null

Thank you, rigify working fine now, assign from some: `//source/blender/blenkernel/intern/cdderivedmesh.c:157:2: runtime error: null pointer passed as argument 1, which is declared to never be null`
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 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-addons#57366
No description provided.