Geometry Nodes 'Bounding Box' Doesn't Update #118507

Open
opened 2024-02-20 14:33:58 +01:00 by Brady Johnston · 4 comments

System Information
Operating system: Windows-10-10.0.22000-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3090/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 551.52

Blender Version
Broken: version: 4.0.2, branch: blender-v4.0-release, commit date: 2023-12-05 07:41, hash: 9be62e85b727
Tested also in 4.2 Alpha in which it is also broken

Short description of error
When updating meshes via the python API, the Bounding Box node doesn't update despite the mesh updating and seemingly all other geometry nodes updating.

Exact steps for others to reproduce the error

As a reproducible example, you can create a mesh made of some random vertices. On each frame change, the mesh positions are scaled.

import bpy
from bpy.app.handlers import persistent
import numpy as np

# create a mesh made of some random points
points = np.random.rand(500, 3)
mesh = bpy.data.meshes.new('test')
mesh.from_pydata(vertices=points, edges=[], faces=[])
obj = bpy.data.objects.new('test', mesh)
bpy.data.collections['Collection'].objects.link(obj)

@persistent
def _update_points():
    def update_scene(scene):
        # get the mesh to be updated
        obj = bpy.data.objects['test']
        
        # init an array for the values, store the position values in it
        arr = np.zeros(500 * 3, dtype=float)
        obj.data.attributes['position'].data.foreach_get('vector', arr)
        
        # scale the positions by some amount, then set the new positions to these scaled
        # values and update the data so everything in Blender updates
        arr = arr * 1.01
        obj.data.attributes['position'].data.foreach_set('vector', arr.copy(order='c'))
        obj.data.update()
        
    return update_scene

# append this update function to the frame change handler
bpy.app.handlers.frame_change_post.append(_update_points())

With this mesh now scaling, add a Geometry Nodes modifier. From what I have tested, all of the nodes work up the updated mesh, except for the Bounding Box node, which doesn't register the updated mesh, except when changing into and out of edit mode.

You can temporarily get the Bounding Box node to register the updated mesh, by first putting a Separate Geometry node before it and having some non-zero selection, then the Bounding Box will work on the updated mesh. If you remove the node however, it works then on the original mesh again.

**System Information** Operating system: Windows-10-10.0.22000-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 3090/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 551.52 **Blender Version** Broken: version: 4.0.2, branch: blender-v4.0-release, commit date: 2023-12-05 07:41, hash: `9be62e85b727` Tested also in 4.2 Alpha in which it is also broken **Short description of error** When updating meshes via the python API, the `Bounding Box` node doesn't update despite the mesh updating and seemingly all other geometry nodes updating. **Exact steps for others to reproduce the error** As a reproducible example, you can create a mesh made of some random vertices. On each frame change, the mesh positions are scaled. ```python import bpy from bpy.app.handlers import persistent import numpy as np # create a mesh made of some random points points = np.random.rand(500, 3) mesh = bpy.data.meshes.new('test') mesh.from_pydata(vertices=points, edges=[], faces=[]) obj = bpy.data.objects.new('test', mesh) bpy.data.collections['Collection'].objects.link(obj) @persistent def _update_points(): def update_scene(scene): # get the mesh to be updated obj = bpy.data.objects['test'] # init an array for the values, store the position values in it arr = np.zeros(500 * 3, dtype=float) obj.data.attributes['position'].data.foreach_get('vector', arr) # scale the positions by some amount, then set the new positions to these scaled # values and update the data so everything in Blender updates arr = arr * 1.01 obj.data.attributes['position'].data.foreach_set('vector', arr.copy(order='c')) obj.data.update() return update_scene # append this update function to the frame change handler bpy.app.handlers.frame_change_post.append(_update_points()) ``` With this mesh now scaling, add a Geometry Nodes modifier. From what I have tested, all of the nodes work up the updated mesh, except for the `Bounding Box` node, which doesn't register the updated mesh, except when changing into and out of edit mode. You can _temporarily_ get the `Bounding Box` node to register the updated mesh, by first putting a `Separate Geometry` node before it and having some _non-zero_ selection, then the `Bounding Box` will work on the updated mesh. If you remove the node however, it works then on the original mesh again.
Brady Johnston added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2024-02-20 14:33:58 +01:00
Member

Didn't test it yet, but may be a missing update tag when using attribute.foreach_set vs. setting vertex.co manually (which calls rna_Mesh_update_positions_tag).
Maybe try setting on of the vertex positions manually after foreach_set.

Didn't test it yet, but may be a missing update tag when using `attribute.foreach_set` vs. setting `vertex.co` manually (which calls `rna_Mesh_update_positions_tag`). Maybe try setting on of the vertex positions manually after `foreach_set`.
Author

You are correct. If I change it to the code below and manually update each vertex then the bounding box node works.

        arr = arr * 1.01
        arr = arr.reshape((500, 3))
        for i, vert in enumerate(obj.data.vertices):
            vert.co = arr[i, :]
        obj.data.update()
You are correct. If I change it to the code below and manually update each vertex then the bounding box node works. ```python arr = arr * 1.01 arr = arr.reshape((500, 3)) for i, vert in enumerate(obj.data.vertices): vert.co = arr[i, :] obj.data.update() ```
Member

Not a fix yet, but it's likely also enough to only set a single vertex' position instead of all of them.

Not a fix yet, but it's likely also enough to only set a single vertex' position instead of all of them.
Author

Yep if I just add a single vertex update to the frame call that also fixes it. Thanks for the temporaray fix!

        obj.data.attributes['position'].data.foreach_set('vector', arr.copy(order='c'))
        obj.data.vertices[0].co = obj.data.vertices[0].co
        obj.data.update()
Yep if I just add a single vertex update to the frame call that also fixes it. Thanks for the temporaray fix! ```python obj.data.attributes['position'].data.foreach_set('vector', arr.copy(order='c')) obj.data.vertices[0].co = obj.data.vertices[0].co obj.data.update() ```
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
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#118507
No description provided.