I need to get a scrrenshot….one for now to see if this is possible, but I will need to get several at some point.
Doing this in Babylon seems way overly complicated….
So I used a node server
onst express = require('express’);
const fs = require('fs’);
const cors = require('cors’);
const app = express();app.use(cors()); // Use cors middleware
app.use(express.json({ limit: ‘50mb’ })); // Increase limit to 50mbapp.post(‘/save-screenshot’, (req, res) => {
const base64Data = req.body.data.replace(/^data:image/png;base64,/, “”);fs.writeFile("./src/images/iteration.png", base64Data, 'base64', function(err) { if (err) { console.log(err); res.status(500).send(err); } else { res.status(200).send('Screenshot saved.’); } });
});
app.listen(3000, () => console.log('Server running on port 3000’));
And then this in the babylon scene:
Tools.CreateScreenshot(this.engine, camera, { width: 1024, height: 1024 }, function (data) {
// Send the screenshot data to the server
fetch(‘http://localhost:3000/save-screenshot’, {
method: ‘POST’,
headers: {
‘Content-Type’: 'application/json’
},
body: JSON.stringify({ data: data })
})
.then(response => response.text())
.then(data => console.log(data))
.catch((error) => {
console.error(‘Error:’, error);
});
});
Then wanted to use the image as the image in a v-btn in vuetify or at least just display it. I am geting some unstable side effects where the babylon scen just crashes which I think is because of the node server….I have never used a node server like this.
What I need to do is take snapshots save them to the root directory on the server when deployed and then in vue grab them and use them where I need them. I have done this with other platforms, but doing this in babylon is way different.
Howe can I do this the simpliest way?