Skip to content

Conversation

@vincentfretin
Copy link

This PR is based on #37. Only the latest commit is new.

The changes are good if you want to use the AvatarEditorContainer component in a Dialog component that you can show and hide inside your react app.
The threejs renderer is created when the AvatarPreviewContainer mount and is disposed when the component unmount.

I created the functions window.gameState.initRenderer and window.gameState.disposeRenderer and refactored game.js to create only once the scene, and recreate the envmap and controls when the component is remounted.
Instead of setting material.envMap of each material, I just set it once with scene.environment.
I also added sky.geometry.dispose();sky.material.dispose(); to properly clean up sky geometry and material.
I'm using renderer.setAnimationLoop(tick) instead of handling the loop with window.requestAnimationFrame(tick);.
This way the loop is stopped automatically when disposing the renderer, so we don't need to handle a state ourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant