Sign in to follow this  
trecool

Imported meshes workflow

Recommended Posts

Hey! 

I'm struggling really hard trying to get anything to work - I checked to Playgrounds, forums and documentation but I can not find anything helpful about working with imported meshes. Am I blind? Most of the playground examples I can find work with simple meshes like cubes and spheres, but that is not helpful for me. 

var frame = new BABYLON.Mesh.CreateBox("box", 100, scene);
frame.isVisible = false;           
               
           
var loader = new BABYLON.AssetsManager(scene);
           
var meshTask = loader.addMeshTask("FW", "", "assets/", "groups.babylon");
meshTask.onSuccess = function (task) {                
     LIBRARY['kubus'] = task.loadedMeshes[0];
     LIBRARY['kubus'].parent = frame;
}           

And then I can scale the frame without destroying my object. This seems rather complex for such a simple task, is there a better way? 

But how do I access the object now? Anything outside the onSuccess function happens before so everytime I try to reference LIBRARY['kubus'] outside this function, I just get an "undefined" error. I tried it with onFinish and put it after loader.load(). 

Next big problem: How do I access groups I set up in 3dsmax - is it even possible? Is there a better way than looking at the parent object of every mesh and comparing them? For example, this imported object consists of 70 meshes but I have models with up to 200 meshes and this approach seems rather counter intuitive. 

And for further reading, are there any further ressources I could check out? I don't find the Playground search to be too helpful and the documentation is great when needing assistance in rendering and other engine stuff but I find it lacking in the "importing and working with meshes and objects"-department.

And what exactly is the difference between the name of an object and the name of the variable? I really don't understand this approach, is the name used internally for reference? Can I access the objects like this? Is there a way to get an overview of all objects in a scene? 

Thanks for all the help! :)

Share this post


Link to post
Share on other sites

Hi @trecool the assetsManager is a great tool to have,

You can achieve what you're trying to do with several methods,

you are correct trying to use LIBRARY['kubus'] before it has loaded will end in a error,

but you could "delay" your code which uses it, until it has loaded.

example:

loader.onFinish = function (tasks) {
  //All AssetsManager tasks are loaded & ready.
    loadingComplete();
};

function loadingComplete(){
  //The loader is finished, continue building your scene, LIBRARY['kubus'] should no longer return a undefined error.
}

 

As for 3ds max groups, i'm not sure actually.. try doing some console.logs of meshes and see if you can figure out whats going on compared to your 3ds max setup :) 


The name of a variable for an object/mesh is your javascript reference to that object.

e.g LIBRARY['kudus'] is your reference to the mesh(es) you have imported, but i assume you know that already^^

the babylon mesh.name & mesh.id (which are usually the same) can also be used to find a mesh using;

scene.getMeshByID(your id); //returns the first mesh with this id.

scene.getMeshesByID(your id); //returns an array of all meshes with this id.

scene.getMeshByName(your name); // returns the first mesh with this name.

scene.getActiveMeshes(); //returns a list of all active meshes in your scene

you can see all methods at: http://doc.babylonjs.com/classes/2.4/Scene

Share this post


Link to post
Share on other sites

Ah, thanks! That actually gets me a little closer... :)

However, when I try the following.... 

 function loadingComplete() {
                LIBRARY['kubus'].actionManager = new BABYLON.ActionManager(scene);
                LIBRARY['kubus'].actionManager.registerAction(new BABYLON.ExecuteCodeAction(BABYLON.ActionManager.OnPickTrigger, function () { LIBRARY['kubus'].material.diffuseColor = new BABYLON.Color3(1.00, 0.00, 1.00); console.log("test"); }));
                console.log("wow");
            }

it logs the "wow" but click events are not registered. I take it that the registerAction() function has to be outside other funtions in order to work? But then I'm back to my original problem, that I can't add the registerAction() to an undefined object. 

I'm sorry if this is a really stupid question but my brain is mush at this point :/ 

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.