Home > Software engineering >  .glb file doesn't show in express server
.glb file doesn't show in express server

Time:07-18

I want to run a simple webserver that shows a .glb file in VR using a-frame.

When I use the "Open in Default Browser" extension in vs code the html below shows without problems, both box and file.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Hello, WebVR! • A-Frame</title>
    <meta name="description" content="Hello, WebVR! • A-Frame">
    <script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
  </head>
  <body>
    <a-scene background="color: #ECECEC">
      <a-gltf-model position="4 -10 -100" rotation="210 0 0" src="/EPE_4.glb" shadow="receive: true"></a-gltf-model>
      <a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9" shadow></a-box>
      <a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4" shadow></a-plane>
    </a-scene>
  </body>
</html>

However, when I run a server providing the html using Express, with the node command, only the box and plane is visible. Note that the .glb is somewhat large at 200 MB.

Below is my app.js and package.js file.

Thank you in advance for any help.

app.js

const app = express();
const path = require('path');
const router = express.Router();

router.get('/',function(req,res){
  res.sendFile(path.join(__dirname '/index.html'));
});

app.use('/', router);
app.listen(process.env.port || 3000);

console.log('Running at Port 3000');

package.js

{
  "name": "vr_test2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node ./bin/www",
    "devstart": "SET DEBUG=vr_test:* & nodemon ./bin/www"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  }
}

CodePudding user response:

If someone has a similar problem. Check the browser's console log, mine showed that the webpage couldn't find the .glb file. I solved this by adding a public folder and serving it to the client by using:

app.use(express.static('public'))
  • Related