gkjohnson / three-gpu-pathtracer

Path tracing renderer and utilities for three.js built on top of three-mesh-bvh.
https://gkjohnson.github.io/three-gpu-pathtracer/example/bundle/index.html
MIT License
1.27k stars 125 forks source link

`setScene()` ignores `mesh.geometry` reassignment #646

Closed ycw closed 3 weeks ago

ycw commented 3 weeks ago

Describe the bug

setScene() ignores mesh.geometry reassignment in the following situation:

const mesh = new Mesh(new THREE.BoxGeometry(1,1,1), new THREE.MeshStandardMaterial())
pathTracer.setScene(scene, camera)

mesh.geometry = new THREE.BoxGeometry(2,1,1) // assigns new box geometry(2x1x1)
pathTracer.setScene(scene, camera) // old box geometry(1x1x1) gets rendered

Expected behavior

I expected that pathtracer honors mesh.geometry reassignment.

Workarounds

Renews mesh uuid right after assigning new geometry.

Screenshots and Demos

https://jsfiddle.net/0kyq5g7d/1

https://github.com/gkjohnson/three-gpu-pathtracer/assets/1063018/b9a5ab21-be92-4428-ab14-456cf163b534

Packages

three@0.165.0
three-gpu-pathtracer@0.0.22
gkjohnson commented 3 weeks ago

cc @dongho-shin - do you want to take a look at this?

dongho-shin commented 3 weeks ago

StaticGeometryGenerator compare mesh.uuid with cached so it(just change geometry inside of the mesh) may NO_CHANGE for now StaticGeometryGenerator.js near line 238

image

I think cache comparison method of StaticGeometryGenerator needs to be cleaned up or refactored once.

gkjohnson commented 3 weeks ago

I took a look at the cache a bit more and found a few issues. It should be fixed in #647. It would be great if you guys could try it to make sure it fixes the issue.

Hopefully in the future we won't have to rely on a full scene static geometry generator - which is a fairly complex to run quickly - but that might be a bit further out.

gkjohnson commented 2 weeks ago

@ycw I've just published v0.0.23 if you'd like to update the three.js editor. Thanks again for the report and repro.

ycw commented 2 weeks ago

Good.

https://github.com/mrdoob/three.js/pull/28587