Spankied Posted October 18, 2017 Share Posted October 18, 2017 How do I setup express server with bablyon? Any demo repos? Perhaps this isnt feasible. If so, what are my options for dynamically serving bablyon scenes? The goal is to design scenes, then run them on schedule. Quote Link to comment Share on other sites More sharing options...
RaananW Posted October 18, 2017 Share Posted October 18, 2017 Babylon is a frontend framework (thou deltakosh just released the nullEngine for server-side usage, but I don't think this is what you wanted). You need to simply serve the js and .babylon scenes (or whatever format you want to use), and produce an html file for your visitors. Quote Link to comment Share on other sites More sharing options...
fort Posted October 18, 2017 Share Posted October 18, 2017 I'm building something similar at the moment. Here's the basic setup: import express from 'express'; import { json, urlencoded } from 'body-parser'; import cors from 'cors'; const app = express(); // this allows us to accept big JSON objects via POST request: app.use(json({ limit: '50mb', parameterLimit: 1000000 })); app.use(urlencoded({ extended: true, limit: '50mb', parameterLimit: 1000000 })); app.use(cors({ origin: '*' })); // this is optional, but I need it for my specific setup app.use('/', express.static('public')); // I'm serving static html/js/css here, which renders the bjs scene app.post('/scene', async (req, res) => { // in your front-end JS, do the following: // 1. Serialize your scene. ex: let sceneAsJSON = BABYLON.SceneSerializer.Serialize(scene); // 2. make a POST request to 'http://[host ip:port]/scene' that includes the serialized JSON you created in step #1 in the body of the request. // // That JSON object (your serialized scene) will show up here in req.body.[your post variable name]. Now you can do whatever you want with it—save to a database, cram it in a .babylon file, etc. // don't forget something to reply to the browser's request res.json({ whatever: 'bacon' }); }); app.listen(3000, function () { console.log('app is listening on port 3000.'); }); Quote Link to comment Share on other sites More sharing options...
Spankied Posted October 18, 2017 Author Share Posted October 18, 2017 Thanks fort, this gives me an idea of things would work. fort 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.