Jump to content

Feeling lost loading models.


Recommended Posts

My workflow seems pretty basic to me. 

Load/Cache Meshes from a 3 js files (now working with babylon files)  The meshes are complete models with UV textures already mapped. 

Dynamically create a new mesh by cloning the originally loaded mesh,  position and scale based on incoming data. 

Continue updating position information over time based on incoming information.

Remove and add meshes as needed.  


In my adventure so far I first validated that I could created a SolidParticleSystem system as large as I needed. 

Friday last week I started on phase two and am totally stuck. 

Loading my models from file. 

The issue is  BABYLON.SceneLoader.Load("/mb/CargoContainer/", "CargoContainer.babylon",engine, function (OnLoaded)

This does load a file but I have no idea how to access the mesh that was loaded in the OnLoaded function.
The online documentation includes little information as to whats available in the OnLoaded function. 

ImportMesh automatically loads the mesh into the scene and if you pass a null into the scene parameter the import call fails. 

BABYLON.SceneLoader.ImportMesh("Cargo_container_01", "/mb/CargoContainer/", "CargoContainer.babylon", scene, function (newMeshes)

I read the docs http://doc.babylonjs.com/classes/2.4/SceneLoader but they were a bit sparse on this subject. 

The number of replies have been stellar so I am hoping someone can point out what I am nor understanding. 


Link to comment
Share on other sites

Hi @chicagobob123

Using the ImportMesh method, 

i think i made a post explaining this already but i'll try again with a bit more details :)


The scene parameter is the babylon scene you are loading your container into,


var scene = new BABYLON.Scene(engine);

//the scene parameter should be scene.

var myScene = new BABYLON.Scene(engine);

//the scene parameter should be myScene .

it cannot be null, as you need a scene in order to display anything :P


In the following example, i'll be using a for..loop as i haven't really worked with the SPS.

aswell as a triggering a function at the end of loading the model (instead of a callback) just because i'm that lazy :P.

Please see the following PG using the skull PG example, everything you need is commented:



Edit: In #4 below i also included very basic movement of the smallest skull from side to side.



I hope some of this helps, if you still feel like something is confusing, let us know :)


Link to comment
Share on other sites

We are talking past each other. I understood the prior example. Maybe I didn't make that clear. 

The reason I have an issue with the ImportMesh is because it loads the Mesh directly into the scene.

Auto loading into the scene works against my flow and works against using it as a particle. 

In my current web app I created three stages.

1) load models - wait until all textures and meshes are loaded before turning on the async server creation requests

2) start server feed, create and position models add to scene

3) Position control models

Using import mesh you are adding the mesh to the scene instantly. I have 20 complete models that I do not know where they go until I get the async information from server. The server position data is a continuous stream that is kind of heavy. I want the models and textures loaded before I turn the server stream on. I do not know where that model will go until I get the server information. The data I get is random real-time data. 

In addition attempting to use the SolidParticleSystem I REALLY don't want to add a mesh to the scene.

I want to load the mesh, add it as a shape. Apply the material.. Build the mesh apply the material. 

var sps=new BABYLON.SolidParticleSystem("sps",scene);

sps.addShape(container, nb);  Its not just added to the scene.

If I used ImportMesh I guess I could delete it from the scene before its displayed. 

So in short I am trying to load a mesh get the mesh, get the material loaded to the mesh and not have it auto loaded into the scene. 

I am going to put together a quick demo. 


Link to comment
Share on other sites

mmh... maybe just :

import and reference the imported mesh : var mymesh = tthisImportedStuff in the scene

add it to the SPS as a model : sps.addShape(mymesh, nb);

then delete it : mymesh.dispose()

then play with the sps : sps.buildMesh() and next fun things

Link to comment
Share on other sites


If you comment out the this part 

        var box = BABYLON.MeshBuilder.CreateBox("b", {}, scene);        
        sps.addShape(box, nb);
        sps1.addShape(box, nb);
        sps2.addShape(box, nb)

and un-comment and try to use the mesh it blows up.

    //   var box = BABYLON.MeshBuilder.CreateBox("b", {}, scene);        
     //   sps.addShape(box, nb);
     //   sps1.addShape(box, nb);
     //   sps2.addShape(box, nb);
        sps.addShape(cargoCont01, nb);
        sps1.addShape(cargoCont01, nb);
        sps2.addShape(cargoCont01, nb);

In the function     function loaded() 

It just blows up.  Any ideas?


Link to comment
Share on other sites

nope, I guess it's related to the number of vertices : the skull model is, in my memory, still 20K vertices or so and you're attempting to create 8000 skulls !


if I set the number to 1, this works

I suppose that your containers will be something like 25-30 vertices each, so the SPS should be able to manage them like it can for the current boxes. Just remember that the SPS number of vertices will be its model number of vertices times the number of wanted particles.

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.

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.


  • Recently Browsing   0 members

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