from_pydata function can not process numpy lists of faces #51585

Closed
opened 2017-05-22 11:46:11 +02:00 by toony hollawolla · 5 comments

when using bpy.data.meshes like the following code with numpy arrays, it will throw:

Traceback (most recent call last):
(...)
  File "/home/tom/Dropbox/promotion/adcsdesigner/genutils.py", line 77, in genobjfrompydata
    me = genmeshfrompydata(verts, edges, faces) # create a new mesh
  File "/home/tom/Dropbox/promotion/adcsdesigner/genutils.py", line 72, in genmeshfrompydata
    me.from_pydata(verts,edges,faces)
  File "/usr/share/blender/2.78/scripts/modules/bpy_types.py", line 440, in from_pydata
    if faces and (not edges):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Error: Python script fail, look in the console for now...

I need to use numpy arrays because of speed requirements, it would be nice, if from_pydata could be
rewritten, so that it accepts those arrays... (I would also do it myself, if someone could point me to the correct location ;))

    scale_x = self.scale.x
    scale_y = self.scale.y

    verts = np.array([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 = np.array([[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)

when using bpy.data.meshes like the following code with numpy arrays, it will throw: ``` Traceback (most recent call last): (...) File "/home/tom/Dropbox/promotion/adcsdesigner/genutils.py", line 77, in genobjfrompydata me = genmeshfrompydata(verts, edges, faces) # create a new mesh File "/home/tom/Dropbox/promotion/adcsdesigner/genutils.py", line 72, in genmeshfrompydata me.from_pydata(verts,edges,faces) File "/usr/share/blender/2.78/scripts/modules/bpy_types.py", line 440, in from_pydata if faces and (not edges): ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() Error: Python script fail, look in the console for now... ``` I need to use numpy arrays because of speed requirements, it would be nice, if from_pydata could be rewritten, so that it accepts those arrays... (I would also do it myself, if someone could point me to the correct location ;)) ``` scale_x = self.scale.x scale_y = self.scale.y verts = np.array([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 = np.array([[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) ```

Changed status to: 'Open'

Changed status to: 'Open'

Added subscriber: @ThomasMeschede

Added subscriber: @ThomasMeschede

Added subscriber: @Sergey

Added subscriber: @Sergey

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Sergey Sharybin self-assigned this 2017-05-22 14:59:34 +02:00

Surely it will be nice to support, but it is more a feature request than a bug, which we don't accept in the bug tracker.

Just write some wrapper to convert numpy array to list.

Thanks for the report, but it's not really a bug.

Surely it will be nice to support, but it is more a feature request than a bug, which we don't accept in the bug tracker. Just write some wrapper to convert numpy array to list. Thanks for the report, but it's not really a bug.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 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#51585
No description provided.