Hi everyone,
I’m trying to convert an uploaded stl file into an image with png extension. I have written a code that only captures the scence, but the image is not showing. I don’t know why the image is not displayed.
Here is a piece of the codes:
var canvas = document.getElementsByTagName('canvas')[0];
var dataURL = canvas.toDataURL('image/png');
var imgSrc = dataURL.replace(/^data:image\/[^;]/, 'data:application/octet-stream');
console.log({dataURL});
var image = imgSrc;
The code above only captures the scene without showing the image.
If I use imgSrc.png, it gives me error.
To remove the background for rendering the image, change the scene.background color to an rgba value 0,0,0,0 before renderer.render(scene camera);
Make sure you set canvas to transparent to start with though:
Hello, Please check out my solution: this will be an effective way to capturing image. newPosition is the position of the camera.
export function captureAndUploadImages(newPosition) {
return new Promise((resolve, reject) => {
camera.position.set(newPosition.x, newPosition.y, newPosition.z);
requestAnimationFrame(() => {
renderer.render(scene, camera);
const imgDataUrl = renderer.domElement.toDataURL();
*// use the image data or upload it to the backend*
});
});
}
If you need more questions or have problems please contact me on mkafhb@gmail.com