Last active
March 18, 2024 22:06
-
-
Save lucasassisrosa/ee4205d5f16cfdd955555172c8a7ae40 to your computer and use it in GitHub Desktop.
Convert 3D model in three-js scene to png image -- saving the animation frames using `canvas.toBlob`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
/** | |
* On browser load | |
* if using https://github.com/vasturiano/globe.gl#globe-layer | |
* call inside `animate()` function or `onGlobeReady`, or a react wrapper `onLoad` callback | |
*/ | |
// after globe is loaded and animation started | |
const canvasElement = document.querySelector( | |
`canvas#canvas-id` | |
); | |
canvasElement?.toBlob((blob) => { | |
const imgEl = document.createElement('img'); | |
imgEl.src = URL.createObjectURL(blob); | |
document.body.appendChild(imgEl); | |
}); | |
// reference: https://discourse.threejs.org/t/convert-3d-model-in-threejs-scene-to-png-image/20742/2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment