dav74

problem with BABYLON.SceneLoader.ImportMesh

Recommended Posts

Hello (again ;-)),

I've a problem with the code (see the bottom of this post)

if i "comment" the line : "singe.position.x=3", all is ok (i've Suzanne from blender on screen)

if i "uncomment" this line, i've an error "singe is undefined", why "singe=newMeshes[0];" doesn't work ? i don't understand !!

Thank for your help

var canvas = document.getElementById("renderCanvas");var engine = new BABYLON.Engine(canvas, true);var scene = new BABYLON.Scene(engine); var singe;var camera = new BABYLON.ArcRotateCamera("Camera",0,0, 10, new BABYLON.Vector3(0, 0, 0), scene);var light0 = new BABYLON.PointLight("Omnidir", new BABYLON.Vector3(0, 0,60), scene);BABYLON.SceneLoader.ImportMesh("Suzanne", "asset/", "head1.babylon", scene, function (newMeshes, particleSystems) {	singe=newMeshes[0];});//singe.position.x=3;camera.attachControl(canvas);engine.runRenderLoop(function () {    scene.render();});

Share this post


Link to post
Share on other sites

Hi Dav74 !

 

I don't think there is a way to make otherwise. The model import is asynchronous, and thus will be executed in a new thread. There's no way to execute actions after the import other than a callback function.

A proper way to initialize your model position (among many other thing I guess) would be to do it like this: 

BABYLON.SceneLoader.ImportMesh("Suzanne", "asset/", "head1.babylon", scene, function (newMeshes, particleSystems) {    setup(newMeshes[0]);});

where the setup(mesh) function would be all actions related to your imported model, for example : 

function setup(mesh) {    mesh.position.x = 3    //...}

Share this post


Link to post
Share on other sites

Hi,

@ melaugui thank you for your answer, 1 question again : do you think that i can put the render loop in the callback function ? do you think that is the good solution ?

Share this post


Link to post
Share on other sites

 

Hi Dav74 !

 

I don't think there is a way to make otherwise. The model import is asynchronous, and thus will be executed in a new thread. There's no way to execute actions after the import other than a callback function.

A proper way to initialize your model position (among many other thing I guess) would be to do it like this: 

BABYLON.SceneLoader.ImportMesh("Suzanne", "asset/", "head1.babylon", scene, function (newMeshes, particleSystems) {    setup(newMeshes[0]);});

where the setup(mesh) function would be all actions related to your imported model, for example : 

function setup(mesh) {    mesh.position.x = 3    //...}

 

Hi Guy's - when I try this i get error - cannot set property 'position' of undefined'   in console

 

BABYLON.SceneLoader.ImportMesh("bench", "GalleryAssets/room/", "office_chair.babylon", scene, function (newMeshes, particleSystems) {
            setup(newMeshes[0]);
        });

 

function setup(mesh) {
            function setup(mesh) {
            mesh.position.x = 10;
            mesh.position.y = 1;
            mesh.position.z = -10;
 
            mesh.scaling.x = 5;
            mesh.scaling.y = 5;
            mesh.scaling.z = 5;
        }

 

any ideas to help?

 

thanks

Share this post


Link to post
Share on other sites

Also i'm not sure why you need the setup file. Assigning new variables etc just uses more memory.

BABYLON.SceneLoader.ImportMesh("bench", "GalleryAssets/room/", "office_chair.babylon", scene, function (newMeshes, particleSystems) {            newMeshes[0].position = new Babylon.vector3(10,1,-10);            newMeshes[0].scaling = new Babylon.vector3(5,5,5);});

Share this post


Link to post
Share on other sites

Hi guys' thanks for responses...

 

I've removed "bench" and tried the code above from reddozen...

 

var LoadChairs = function () {
        
        BABYLON.SceneLoader.ImportMesh("", "GalleryAssets/room/", "office_chair.babylon", scene, function (newMeshes, particleSystems) {
            newMeshes[0].position = new Babylon.vector3(10, 1, -10);
            newMeshes[0].scaling = new Babylon.vector3(5, 5, 5);
        });
}

 

BUT - I still get this i get error - cannot set property 'position' of undefined'   in console  

 

I've even tried to resize and position in the office_chair.babylon file with no results....

 

is there something i should do with my blender file before exporting?

Share this post


Link to post
Share on other sites

Your problem is due to newMeshes[0] not defined : nothing should be loaded.

 

If you remove the two lines, can you see something on the screen ?

newMeshes[0].position = new Babylon.vector3(10, 1, -10);newMeshes[0].scaling = new Babylon.vector3(5, 5, 5);

Share this post


Link to post
Share on other sites

Hi guys' thanks for responses...

 

I've removed "bench" and tried the code above from reddozen...

 

var LoadChairs = function () {
        
        BABYLON.SceneLoader.ImportMesh("", "GalleryAssets/room/", "office_chair.babylon", scene, function (newMeshes, particleSystems) {
            newMeshes[0].position = new Babylon.vector3(10, 1, -10);
            newMeshes[0].scaling = new Babylon.vector3(5, 5, 5);
        });
}

 

BUT - I still get this i get error - cannot set property 'position' of undefined'   in console  

 

thanks for looking!  -  I had already removed 'bench' from the sceneloader - so thats not the issue....

Share this post


Link to post
Share on other sites

ok found the answer to my issue - I needed to parent all the meshes to one parent in blender before exporting to Babylon.... then above codes are working!!!

http://www.html5gamedevs.com/topic/8146-babylonsceneloader-positioning-and-scaling-issues-the-saga-continues/

 

then scaling and positioning is working with Temechons code above...

thank you!

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

  • Recently Browsing   0 members

    No registered users viewing this page.