Jump to content

Load file without webserver


ovmihai
 Share

Recommended Posts

What exactly do you want to do? Like an upload field where you select a file from you PC and the instead of uploading you use it in the local client with babylon... something like that?

 

What have you read so far? I think we had that topic for textures at least somewhere in the forum... but I can't find it at the moment and don't have time to search. I don't remember anything like this for models, but should work the same way, I guess.

 

I think it was something like that: http://www.html5rocks.com/en/tutorials/file/dndfiles/

 

Edit: think I found it: http://www.html5gamedevs.com/topic/17653-how-to-load-textures-dynamically/?hl=readasdataurl

Example: http://www.babylonjs-playground.com/#VNVOU

Link to comment
Share on other sites

Well the github hasn't been updated. The up to date version is on http://www.babylonjs.com/sandbox and simply view the source with your favorite browser.

 

The implementation is fairly simple. I'm just taking the blob via the HTML5 File API, storing the texture as blog into an array and I've slightly modified the Babylon.js loader to load the texture from my blob array rather than using XHR to load them from the server.

 

You'll find the main parts in our code here:

 

- https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.filesInput.ts

- https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.tools.ts -> look at LoadImage function and I'm filtering on the "file:" moniker.

Link to comment
Share on other sites

You know... couldn't this be expanded to make "install" packages for users? So if you dont want to keep several gigs of data in your cache and also don't want to have to download it everytime to render the scene.... the server could keep track of "install point" on the users machine and direct the data pull from there instead of relying on downloading it again.

 

Any possibility of making a dedicated load function for local files that you feed it the root folder path and file names like loadMesh? This would be insanely useful for massive projects like mine where some players may not have great internet access to stream all the content, but they could play reasonably well if they could pre-download all the raw files.

Link to comment
Share on other sites

In fact, the meshes and textures loading system alteady put everything in the local indexDB browser cache by default (need to add the manifest file alongside the .babylon files), so people coming back later does not need to reload everything. Is this not enough ?

Link to comment
Share on other sites

Link to comment
Share on other sites

Because if they clear their cache, it's all gone. In some instances where you have exceptially large files, it can be more benificial to be able to download the packages and load them locally. With that I can provide them a compressed archive option if they have a poor internet connection to be able to get the files they need instead of waiting on the browser to pull down and cache everything.

 

I think the cache is great for dynamic content that will change regularly, or quick model swapping for events, or small demo's or games, but I'm expecting to be generating several gigs worth of map file data, player character data, and monster / NPC data. I'm converting an entire MMO world (failed game that didnt leave beta) into babylon a piece at a time. The original game is close to 6GB of compressed UT2k4 files, and we'll be expanding it further than where the beta left off. That's way too much to expect a player (especially with a weaker internet conection) to wait for the cache to pick up while sitting on a black / loading screne for hours. To me, this is better suited to an "install" type process. It can still use a manifest type file itself as well to make sure that their files are in sync with the server, but this would be easier to manage with a larger project.

 

I'm not being critical of what we have, just suggesting more options to handle huge projects in the future. I hope you can understand my thought process on this.

Link to comment
Share on other sites

In fact, no, if people clear their cache meshes and textures are still there. The indexedDB is not browser cache, it's browser "application data cache". To empty this special cache, in most browsers you need to do more sophisticated operations than just clear cache (that's even usually a problem when developping because you are constantly in the need of emptying everything :D).

 

But I understand your point reddozen, a downloadable assets package that can be addressed afterward in the BJS application. Integrate this possibility directly in the engine could be a nice feature, but it's already possible to create that for now "outside of the engine" (since it is possible to specifiy the url of every assets you want to load, it's up to the dev to create such a package downloadable and set urls accordingly).

Link to comment
Share on other sites

Hi, I want to support ovmihai here a bit.

The problem we have is the following:

We have a (sub)component of a bigger project that uses babylon js to display 3D scenes. The component should not ask the server for resources itself, instead, it should provide an api to put in textures, models, etc. We are most likely going tor some kind of a theming object that contains all the data.

So, we cannot call new Texture(some url) or a loader that loads models but instead we have to put in binary image data and already loaded .babylon json objects into the component through the api using e. g. the mentioned theming container objects.

In the end, of course the subcomponent is in the same domain as the container and of course, theoretically it could call the server, but it's rather an architectural design choice to prevent that from happening.

You could now say "well, the parent component can use the loaders" but well, then the parent component becomes dependent to babylon while it shouldn't know anything about it.

I hope the problem is more clear now.

Link to comment
Share on other sites

There are multiple conversations going on in this thread.  2 thoughts:

 

Why not just make an application? The customer / user downloads it, using (XDK, CocoonJS, or BabylonHX).  All are both mobile & desktop.  An application can still get some of its stuff from net, but all the bulk was downloaded at install.

 

Or, if everything must be in a .babylon, then put everything in.  FileLoader.ts accepts inline textures.  Right now the only producer of a .babylon that packs textures in a .babylon is Blender, but if someone wants it in coming from another producer, then they should modify it to do so (PR it, if you are so inclined).

Link to comment
Share on other sites

Interesting discussions. Let me share my thoughts:

 

1 - IndexedDB has some limitations, you're right. Some browsers have quota (like IE11 at 250 Mo) and users can clear their cache but as they can also delete files themselves on the hard drive even if it's a bit different process

2 - I'm wondering if we're not reaching the limit of the web as a media to distribute a game with such a big size. Or maybe we don't have the proper web technologies to cover that. Let's imagine you're downloading your packed assets on the hard drive using whatever technology. How do you provide it to the game? You're asking to the user to drag'n'drop it into the game or using the File API to open the files explorer? The experience is not great. You have no garantee he will provide the proper files. And you can't access directly to the hard drive from your web app for obvious security reasons.

 

So, I perfectly understand your points here, it's exactly why I've been building the database layer trying to experiment with IDB. I know this is not perfect but I'm still trying to figure out if we have real better plan than that with today's available Web APIs.

 

Apart from that, service workers could also be a better approach to cover what some of the things you'd like to do. But it's currently Chrome only.  

Link to comment
Share on other sites

I was invisioning using file API, and having the player tell the website what their root "installed" directory is, and go from there using php to build dynamic load files from a database. All my scenes lately are dynamic PHP. I would know the file names and where they're located. if the file isnt found, notify them to update the directory location, and if it's not found, then either tell them to reinstall, or revert to indexDB. Could even present a new download file. All that handling is my own deal to handle. All we would really need is a method to read a given file. either by selection browse or known directory / file name (if it's even possible).

 

 

If RuneScape can go full HTML5 there's no reason we can't as well.

 

 

Example:

function readSingleFile(e) {var file = e.target.files[0];if (!file) {return;}var reader = new FileReader();reader.onload = function(e) {var contents = e.target.result;displayContents(contents);};reader.readAsText(file);}function displayContents(contents) {var element = document.getElementById('file-content');element.innerHTML = contents;}document.getElementById('file-input').addEventListener('change', readSingleFile, false); <input type="file" id="file-input" /><h3>Contents of the file:</h3><pre id="file-content"></pre>
Link to comment
Share on other sites

You can create meshes via .obj, .stl loaders, or by importing vertex data the way you want and injecting the data in an empty mesh. You then make materials by creating directly new babylon textures by specifying the images URL and assigning them to your materials.

Link to comment
Share on other sites

@jacquesr, wahts wrong with the way davrous suggested? This seems to work well with the sandbox application... or why dos that not fit your request?

 

Well the github hasn't been updated. The up to date version is on http://www.babylonjs.com/sandbox and simply view the source with your favorite browser.

 

The implementation is fairly simple. I'm just taking the blob via the HTML5 File API, storing the texture as blog into an array and I've slightly modified the Babylon.js loader to load the texture from my blob array rather than using XHR to load them from the server.

 

You'll find the main parts in our code here:

 

- https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.filesInput.ts

- https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.tools.ts -> look at LoadImage function and I'm filtering on the "file:" moniker.

Link to comment
Share on other sites

I'm pretty sure they don't want to have their users to drag'n drop files. They already have a data loading API and wanna create Babylon objects on top of that.

But it's completely feasible, since we can inject vertex data in a mesh, and create material and textures from scratch from images files URL.

Link to comment
Share on other sites

Yeah, it's not about the drag n drop. The point is storing the file as a blob thingy and using createObjectURL. That can be done completely independent from any Babylon calls. And if you need to create a mesh or a texture from a file, you just reference that ObjectURL... at least if I understood the idea right. :P

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...