Meshes vertex normals changed via Python API are not used by dupli vert instances #97018

Closed
opened 2022-04-04 08:18:51 +02:00 by Arnaud Couturier · 17 comments

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: cc66d1020c
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- [x].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.demo.blend

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

**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: `cc66d1020c` 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- [x].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.[demo.blend](https://archive.blender.org/developer/F12968327/demo.blend) This bug makes it impossible to place lots of instances objects in a scene using only vertices, I use it a lot.

Added subscriber: @piiichan

Added subscriber: @piiichan
Member

Added subscriber: @PratikPB2123

Added subscriber: @PratikPB2123
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

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?

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?

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

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- [x].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.

Here is a video that shows that for me assigning a normal does change its value, but not in the viewport. [demo.mp4](https://archive.blender.org/developer/F12968888/demo.mp4) 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- [x].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.
Member

Changed status from 'Needs User Info' to: 'Needs Developer To Reproduce'

Changed status from 'Needs User Info' to: 'Needs Developer To Reproduce'
Member

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.

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.

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.

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.
Member

Added subscribers: @HooglyBoogly, @EAW

Added subscribers: @HooglyBoogly, @EAW
Member

This was changed in 3.1 in the moving of normals out of MVert. See:
cfa53e0fbe

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

In b7fe27314b, there is the note:

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

@HooglyBoogly do you have a suggested workaround?

This was changed in 3.1 in the moving of normals out of MVert. See: cfa53e0fbe See the Python_API release notes here: https://wiki.blender.org/wiki/Reference/Release_Notes/3.1/Python_API In b7fe27314b, there is the note: >Defines a read-only vector type since normals should not be modified manually. @HooglyBoogly do you have a suggested workaround?
Member

Changed status from 'Needs Developer To Reproduce' to: 'Archived'

Changed status from 'Needs Developer To Reproduce' to: 'Archived'
Member

Added subscriber: @Hans-6

Added subscriber: @Hans-6
Member

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.

@Hans-6 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.

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. >@Hans-6 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.

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.

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.
Member

Thanks, good idea. I did that here: 891268aa82

Thanks, good idea. I did that here: 891268aa82

Great! :)

Great! :)
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
5 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#97018
No description provided.