Jump to content

Loading babylon scene from already loaded file


joshcamas
 Share

Recommended Posts

AYEEE IM BACK

I have a little project idea that I'm working on, but dang I've forgotten things.

Specifically, I have my own file uploader that loads babylon files onto the browser. Now what? How do I add this stuff to my scene? (I don't want to create a new scene, I want to loop through the meshes and add certain ones and all sorts of fun junk)

 

Thanks!

Link to comment
Share on other sites

Never mind, I figured it out! It's amazing what you forget!

 

/* Loading scene from uploaded file */

/* HTML: */ 
<input type="file" id="fileupload" onchange="SpriteGen.handleFileInput(event)">

/* JS */
SpriteGen.handleFileInput = function(event) {
    var uploader = event.srcElement || event.currentTarget;
    var files = uploader.files;
    var reader = new FileReader();
    reader.onload = function(event) {
        SpriteGen.uploadedData = event.target.result;
        SpriteGen.onSceneLoad(event)
    };
    reader.readAsDataURL(files[0]);
}

SpriteGen.onSceneLoad = function(event) {
    var result = event.target.result;
    BABYLON.SceneLoader.ImportMesh(null, event.target.result, '', Game.scene, function(newMeshes, particleSystems, skeletons) {
        var mesh = newMeshes[0];
        mesh.position = new BABYLON.Vector3(0, 0, 0);
    });
}

Thanks for the reply dude!

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