Maniphest T97018

Meshes vertex normals changed via Python API are not used by dupli vert instances
Closed, Archived

Assigned To
None
Authored By
Arnaud Couturier (piiichan)
Apr 4 2022, 8:18 AM
Tags
  • BF Blender
  • Modeling
  • Python API
Subscribers
Arnaud Couturier (piiichan)
Evan Wilson (EAW)
Hans Goudey (HooglyBoogly)
Omar Emara (OmarSquircleArt)
Paiva (Hans)
Pratik Borhade (PratikPB2123)

Description

System Information
Operating system: Windows-10-10.0.19044-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1080/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 512.15

Blender Version
Broken: version: 3.1.2, branch: master, commit date: 2022-03-31 17:40, hash: rBcc66d1020c3b
Worked: 3.0.1

Short description of error
Changing the normals of a mesh via the Python API (with mesh.vertices[x].normal) does not modify the orientation of dupli vert instances placed on each vertex of that mesh. It assumed there are no edges nor faces, only verts for instances placement.

Exact steps for others to reproduce the error

  • create a monkey object/mesh
  • scale it down 2x or 3x to better see the results later
  • create a plane object/mesh
  • delete all edges and faces in the plane mesh, only keep its verts
  • make the plane the parent object of monkey
  • enable dupli vert instances on the plane object, vertices mode, and enable "Align to vertex normal"
  • make sure you are in object mode, open a python console panel, and type:

m = bpy.data.meshes['Plane']
m.vertices[0].normal = 1,0,0

  • Notice nothing changes in the viewport, despite vertex 0 has the new normal correctly affected. All verts point towards the local origin by default.

This bug makes it impossible to place lots of instances objects in a scene using only vertices, I use it a lot.

Related Objects

Mentioned In
T101059: Instancing Vertices, change normal of parent doesn't reflect on instances
Mentioned Here
rB891268aa824f: Mesh: Make vertex normal property read-only
rBcfa53e0fbeed: Refactor: Move normals out of MVert, lazy calculation
rBb7fe27314b25: Mesh RNA API: Expose contiguous normal arrays

Event Timeline

Arnaud Couturier (piiichan) created this task.Apr 4 2022, 8:18 AM
Pratik Borhade (PratikPB2123) added a subscriber: Pratik Borhade (PratikPB2123).Apr 4 2022, 9:09 AM
Omar Emara (OmarSquircleArt) changed the task status from Needs Triage to Needs Information from User.Apr 4 2022, 10:48 AM
Omar Emara (OmarSquircleArt) added a subscriber: Omar Emara (OmarSquircleArt).

This doesn't seem to be working either on 3.0 using the blend file you provided. No matter what I assign to the normal, it is always Vector((-0.7070833444595337, -0.7070833444595337, 0.0)). Should I have done something differently?

Arnaud Couturier (piiichan) added a comment.Apr 4 2022, 11:36 AM

Here is a video that shows that for me assigning a normal does change its value, but not in the viewport.

In Blender 3.0, true it is the same behavior using this method, but if you create a complete new mesh with Python, it works. Using the same demo .blend file, type in the Python console:

m = bpy.data.meshes.new("new_mesh")
m.from_pydata(vertices=[(1,0,0)], edges=[], faces=[])
m.vertices[0].normal = 0,0,1

Then swap the plane mesh with the newly created one, and the corresponding dupli vert instance will be rotated.

In the end, both ways should work.

Omar Emara (OmarSquircleArt) changed the task status from Needs Information from User to Needs Information from Developers.Apr 4 2022, 1:02 PM
Omar Emara (OmarSquircleArt) added projects: Modeling, Python API.

I can replicate a change in the behavior across versions. In 3.0, changes to vertex normals take effect but are overwritten later, when going to edit mode for instance. In 3.1, changes to normals are written, but do not take effect at all.
Tried BKE_mesh_vertex_normals_clear_dirty(mesh); in BKE_mesh_vertex_normals_clear_dirty(mesh);, but that didn't work. The original behavior is suspicious to me, so tagging the module for more information.

Arnaud Couturier (piiichan) added a comment.Apr 4 2022, 1:23 PM

Yes going to edit mode erases all vertex normals set via Python. This behavior goes way back to... I don't know... blender 2.49 at least. The best solution would be: custom vertex normals take effect AND going into edit mode doesn't erase them.

Evan Wilson (EAW) added subscribers: Hans Goudey (HooglyBoogly), Evan Wilson (EAW).Apr 4 2022, 3:01 PM

This was changed in 3.1 in the moving of normals out of MVert. See:
rBcfa53e0fbeed: Refactor: Move normals out of MVert, lazy calculation

See the Python_API release notes here:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.1/Python_API

In rBb7fe27314b25: Mesh RNA API: Expose contiguous normal arrays, there is the note:

Defines a read-only vector type since normals should not be modified manually.

@Hans Goudey (HooglyBoogly) do you have a suggested workaround?

Hans Goudey (HooglyBoogly) closed this task as Archived.Apr 4 2022, 3:22 PM
Hans Goudey (HooglyBoogly) added a subscriber: Paiva (Hans).

Setting the normal was always problematic and should never have been possible, since many operations would overwrite them anyway. Vertex normals are derived data, not something that's meant to be editable by the user.

@Paiva (Hans) Goudey (HooglyBoogly) do you have a suggested workaround?

I'd suggest using a vector attribute and the geometry nodes instance on points node for creating instances.

So, I don't think this is a bug, just a weird part of the Python API.

Arnaud Couturier (piiichan) added a comment.Apr 9 2022, 10:28 AM

I see, I'll try the geometry nodes alternative, thank you.

The vertex normal attribute should be made read-only in the Python API, to avoid confusion for users.

Hans Goudey (HooglyBoogly) added a comment.Apr 28 2022, 7:16 PM

Thanks, good idea. I did that here: rB891268aa824f0fcaf54f56b3a8640a78282552d8

Arnaud Couturier (piiichan) added a comment.Apr 29 2022, 10:41 AM

Great! :)