Always trigger material needsUpdate in scene .material()#5983
Always trigger material needsUpdate in scene .material()#5983Jepson2k wants to merge 1 commit intozauberzeug:mainfrom
Conversation
The condition `material.needsUpdate = material.vertexColors != vertexColors`
only marked the material dirty when the vertex-color flag flipped, but the
same call also writes `color`, `opacity`, and `side`. Calling
`.material('red')` followed by `.material('blue')` left the material with
`needsUpdate=false` for the second call, so the color change was silently
dropped on the next render.
Set `needsUpdate = true` unconditionally so all property changes take
effect on the next frame.
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
|
Hi Jake, thanks for slicing this out. Before signing off I'd like to nail down what's actually being fixed, because I can't reproduce the described symptom. The repro in the description — calling with ui.scene() as scene:
box = scene.box().material('red', side='front')
ui.button('red', on_click=lambda: box.material('red'))
ui.button('green', on_click=lambda: box.material('green'))
ui.button('side=front', on_click=lambda: box.material('red', side='front'))
ui.button('side=back', on_click=lambda: box.material('red', side='back'))
ui.button('50% transparent', on_click=lambda: box.material('red', opacity=0.5))
ui.button('0% transparent', on_click=lambda: box.material('red', opacity=1.0))The only mutations in this function that could genuinely need a shader recompile are:
There's also a separate, clearer problem with the old line: Could you share the exact scenario where you saw the problem? A minimal script we can run on |
Motivation
The condition in
scene.material(...)waswhich only marked the material dirty when the vertex-color flag flipped.
But the same call also writes
color,opacity, andside, so calling.material('red')followed by.material('blue')leftneedsUpdate=falsefor the second call and the color change was silently dropped on the next render.Implementation
Set
material.needsUpdate = trueunconditionally so all property changes take effect on the next frame.One-line change in
nicegui/elements/scene/scene.js. No public API change.This is one of several small slices being carved out of #5964 — opening it as a standalone PR per the splitting discussion on that thread.
Progress