Jump to content

Bablyonjs & express


Spankied
 Share

Recommended Posts

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. 

 

Link to comment
Share on other sites

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.');
});

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...