Use child mesh in SplatMesh
to auto-inject SparkRenderer
instead of monkey-patching
#158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current monkey-patching of
THREE.Scene
to auto-inject aSparkRenderer
has many limitations and can easily break. The following setups cause issues that aren't immediately clear to the user:THREE.Scene
(<SparkRenderer> is optional but removing makes the splat disappear (R3F) #78 (comment))SparkRenderer
orSplatMesh
using.attach()
instead of.add()
SplatMesh
as an indirect descendant of the scene, if one of the ancestors has already been added to the scene.SparkRenderer
as an indirect descendant of the scenescene.onBeforeRenderer
This PR introduces an alternative approach. Each
SplatMesh
adds an empty mesh to itself. During rendering it checks if the scene contains aSparkRenderer
and if not injects one. Regardless of the outcome it will remove itself, ensuring the check is a one-time cost perSplatMesh
.This does mean that the following pattern is no longer allowed:
Though, personally I think that's for the better. A few examples used this pattern, though it's unclear to me if this was intentional or not.