Jump to content

Pick mesh in the Scene


shaharyar.ahmed
 Share

Recommended Posts

I'm not sure to understand what you need, but if you want to import specifics meshes from file, you can use BABYLON.SceneLoader.ImportMesh method.

BABYLON.SceneLoader.ImportMesh(meshesNames, rootUrl, sceneFilename, scene, then, progressCallBack)

meshesNames can be a simple string (to import only one mesh) or an array of string.

rootUrl is the path to the file.

sceneFilename is ... the file name.

scene is your existing BABYLON.Scene (you need to create it manually)

then(meshes, particleSystems, skeletons) 

then is the callback, where you will receive added meshes (always an array of meshes).

Link to comment
Share on other sites

I've already loaded the scene from the file. Here is the code:

 

if (BABYLON.Engine.isSupported()) {            var canvas = document.getElementById("renderCanvas");            var engine = new BABYLON.Engine(canvas, true);var newScene = new BABYLON.Scene(engine);             BABYLON.SceneLoader.Load("", "bui4.babylon", engine, function (newScene) {                newScene.executeWhenReady(function () {//now here I want to select some meshes from the active scene                    engine.runRenderLoop(function() {                        newScene.render();                    });                });            }, function (progress) {            });        }

I want to select some meshes from the active scene, for hide, unhide, change textures etc.

Link to comment
Share on other sites

Use : 

 

newScene.executeWhenReady(function () {

    

    newScene.meshes[0].position.x = 10; // Mesh 0

    newScene.meshes[1].position.z = -10; // Mesh 1

    newScene.meshes[2].isVisible = false; // Hide mesh

 

              engine.runRenderLoop(function() {
                        newScene.render();

                       //For move something while rendering

                        newScene.meshes[0].position.x += 1;         
             });

 

}

Link to comment
Share on other sites

This line is useless 

var newScene = new BABYLON.Scene(engine);

Your "newScene" variable is not linked to this line :

BABYLON.SceneLoader.Load("", "bui4.babylon", engine, function (newScene)

If you want to access to your scene outside the "Load" scope you need to do this, the "Load" method create a new scene with specified engine :

var scene;BABYLON.SceneLoader.Load("", "bui4.babylon", engine, function (newScene){    scene = newScene;    //Do what you want});
Link to comment
Share on other sites

  • 3 years later...
On 19/01/2014 at 4:18 PM, Nico said:

yourScene.getMeshByID(meshId);yourScene.getMeshByName(meshName);

 

Hello every one, I'd love to know the end of this topic regarding how to pick a mesh from an imported one

Here an example : http://babylonjs-playground.com/#1QJUDF

Now imagine that I want it to a parent of something or bind to a canvas2D

How do I do such thing?

Thx again

Link to comment
Share on other sites

It seams that all I can do is scaling rotating or position changing, anyway to get it call from outside that particular function?

like a simple box, first you create it and then  you call it 

in this PG, I cannot have a array of newMeshes in the console, or has it call outside the function

or do I have to write everything I want this mesh to interact with into that specific function?

Hope I'm clear, thx for your time, btw

Link to comment
Share on other sites

Well it seems I do

        BABYLON.SceneLoader.ImportMesh("", "Content/", "structura.babylon",
                 scene, function (newMeshes) {
                  var pipesLittleChimney = newMeshes[0];
                  var bigStructure = newMeshes[1];
                  var littleStructure = newMeshes[2];
                  var chimney = newMeshes[5];
                  var suflante = newMeshes[6];


// new Meshes match are found in console.log(newMeshes[i].name)             
                 });

Also I'm intrigued why one of my meshes keeps up side down but no way to have a look from it on sanbox even if I rotate it on 3DsMax

If I want to link those meshes to lines and planes, I'll have to do inside the callback function?

Thank you for your time

 

3DSmaxStructuraScreenshot.jpg

DemoStructuraScreenshot.jpg

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