olsibob Posted August 23, 2018 Share Posted August 23, 2018 I'm using express.js to serve a BabylonJS app statically. The dev server is ts-node running on localhost. Everything is going great except that it won't load .env files. If I try loading the .env file: const envTexture = BABYLON.CubeTexture.CreateFromPrefilteredData("assets/textures/mono_lake.env", scene); const skyBox = scene.createDefaultSkybox(envTexture, true, 128); I get the error "Cannot load cubemap because files were not defined" in the console. Elsewhere on the forum, I see that people using IIS servers need to explicitly allow .env file mimetypes in a web.config file, but I'm wondering if this is necessary in express running on locahost? What makes me think it is not a mime issue, is that I do seem to be able to load the .env as a binary file if I use the code below: Someone must be serving Babylon files over node, does anyone know how to get this working? const assetManager = new BABYLON.AssetsManager(scene); const skyboxTask = assetManager.addBinaryFileTask("skybox", "assets/textures/mono_lake.env"); skyboxTask.onError = (task, message, exception) => { console.log(message); } skyboxTask.onSuccess = task => { console.log("success, length: ", task.data.byteLength);// returns the correct length of the .env file } assetManager.load(); Quote Link to comment Share on other sites More sharing options...
Guest Posted August 23, 2018 Share Posted August 23, 2018 Can you check the network profiler to see if the file is actually loaded? Quote Link to comment Share on other sites More sharing options...
brianzinn Posted August 23, 2018 Share Posted August 23, 2018 I use expressjs and koa a lot for development. You may be having trouble with binary being sent as text. so, use res.send(..). If the static file path is different, you can overrride it like this: https://github.com/expressjs/express/blob/master/examples/downloads/index.js If your network profile shows the file being sent then you need to provide your expressjs config. (ie: static). Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 23, 2018 Author Share Posted August 23, 2018 (edited) Checking the network conditioner, when I run the "binaryFileTask" operation, these are the headers in for the .env file: Request URL: http://0.0.0.0:2657/assets/textures/mono_lake.env Request Method: GET Status Code: 200 OK Remote Address: 0.0.0.0:2657 Referrer Policy: no-referrer-when-downgrade Response Headersview source Connection: keep-alive Content-Length: 1067838 Content-Type: application/octet-stream Date: Thu, 23 Aug 2018 20:13:49 GMT ETag: W/"104b3e-UkXMdunGN93+cNYg5Su/4I5pzrg" X-Powered-By: Express Request Headersview source Accept: */* Accept-Encoding: gzip, deflate Accept-Language: en-GB,en-US;q=0.9,en;q=0.8 Cache-Control: no-cache Connection: keep-alive Host: 0.0.0.0:2657 Pragma: no-cache Referer: http://0.0.0.0:2657/ User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 Edited August 23, 2018 by olsibob Quote Link to comment Share on other sites More sharing options...
brianzinn Posted August 23, 2018 Share Posted August 23, 2018 you need to do ctrl-refresh to force the download again - 304 is telling you that you already have it cached in browser. you may need to force binary by using Buffer(). Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 23, 2018 Author Share Posted August 23, 2018 I disabled the cache in developer mode, so now it's a 200 Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 23, 2018 Author Share Posted August 23, 2018 But, when I use the CubeTexture.CreateFromPrefilteredData code, I don't see the file at all in the network conditioner. 6 minutes ago, brianzinn said: you may need to force binary by using Buffer(). Could you explain a little more how I would do this? Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 23, 2018 Author Share Posted August 23, 2018 In the node server, I try intercepting the request for the file, like this: app.get('/assets/textures/:file(*)', (req, res, next) => { console.log(req.url, req.params.file); const staticPath = path.join(__dirname, "..", "..", "client", "dist", req.path); fs.readFile(staticPath, (err, data) => { if (err) { console.log(err) res.send({ message: "oh no!", error: err }); } else { const file = path.basename(req.path); res.contentType(file); console.log("sending"); res.send(data); } res.end(); }); }); This gets called and the logging works for png files etc, but it doesn't get called at all for the .env file (this is when the console for the client errors with "Cannot load cubemap because files were not defined"). It's as if the request for the .env file isn't being made at all Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 23, 2018 Author Share Posted August 23, 2018 @brianzinn I think you're suggesting something like res.send(new Buffer(texData, 'binary')) though the problem is that the get path doesn't seem to get called for .env Quote Link to comment Share on other sites More sharing options...
brianzinn Posted August 23, 2018 Share Posted August 23, 2018 I was suggesting that, yes: res.send(new Buffer(data), 'binary')) Looks like you may need something more like this, but I have never used it: express.mime.type['env'] = '??/??'; Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 23, 2018 Author Share Posted August 23, 2018 Yeah, I've got this in there, express.static.mime.define({'application/octet-stream': ['env']}); doesn't make a difference though. I'll try it without the static Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 23, 2018 Author Share Posted August 23, 2018 If it is a mimetype issue though, how come I get a 200 network response for the .env file when I try loading it with assetManager.addBinaryFileTask? Quote Link to comment Share on other sites More sharing options...
Guest Posted August 23, 2018 Share Posted August 23, 2018 Can you host your code somewhere so we can see it live? Quote Link to comment Share on other sites More sharing options...
brianzinn Posted August 23, 2018 Share Posted August 23, 2018 i found the NPM link for define - you don't need 'static' I would guess: https://github.com/broofa/node-mime#mimedefinetypemap-force--false Not sure why the 200 then, so maybe mime doesn't make sense. Are you serving the right content? Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 23, 2018 Author Share Posted August 23, 2018 @Deltakosh sure, here's a version that falls down right away with the "cannot load cubemap" issue https://sky-explorer-birfeajogq.now.sh/ You can view the source here https://sky-explorer-birfeajogq.now.sh/_src Quote Link to comment Share on other sites More sharing options...
Guest Posted August 24, 2018 Share Posted August 24, 2018 Haha, yes but I need the non minified version please Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 24, 2018 Author Share Posted August 24, 2018 @Deltakosh sorry about that. I'm struggling actually to get npm/webpack to send babylon-max instead of the minified one. I upload the source and then the build happens on the server, so I can't just manually copy the max file across. edit: I think I've thought of a way to do this, I'll try again tomorrow. Quote Link to comment Share on other sites More sharing options...
brianzinn Posted August 25, 2018 Share Posted August 25, 2018 try with "externals" and include max <script ../> on your page. module.exports = { //... externals: { babylonjs: 'babylonjs' } }; Quote Link to comment Share on other sites More sharing options...
MarianG Posted August 28, 2018 Share Posted August 28, 2018 Any news with this? I'm affraid I'm haveing the same problem Later edit: For me work if I updated babylonjs from 3.2 to 3.3beta Quote Link to comment Share on other sites More sharing options...
Guest Posted August 28, 2018 Share Posted August 28, 2018 If you have a repro case online with a reference to non minified source I will be able to help Quote Link to comment Share on other sites More sharing options...
MarianG Posted August 28, 2018 Share Posted August 28, 2018 But now I'm getting this Quote Link to comment Share on other sites More sharing options...
Guest Posted August 28, 2018 Share Posted August 28, 2018 Ok so make sure to move to latest babylon.js and TS 3.0 Quote Link to comment Share on other sites More sharing options...
olsibob Posted August 28, 2018 Author Share Posted August 28, 2018 Oh wow, moving to TS 3 and BabylonJS 3.3.0 made it work! I had been on TS 2.9.2 before. Quote Link to comment Share on other sites More sharing options...
Guest Posted August 28, 2018 Share Posted August 28, 2018 Flagging as solved then Quote Link to comment Share on other sites More sharing options...
MarianG Posted August 28, 2018 Share Posted August 28, 2018 Confirm 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.