dav74 Posted October 30, 2013 Share Posted October 30, 2013 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 helpvar 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();}); Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 30, 2013 Share Posted October 30, 2013 This is because the code inside the ImportMesh (singe=newMeshes[0]) is a callback that will be executed AFTER singe.position.x=3 CGinSeattle 1 Quote Link to comment Share on other sites More sharing options...
dav74 Posted October 30, 2013 Author Share Posted October 30, 2013 OK, I understood.So we have to put the code that handles "singe" in the callback function, no way to make otherwise ? Quote Link to comment Share on other sites More sharing options...
Temechon Posted October 30, 2013 Share Posted October 30, 2013 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 //...} Quote Link to comment Share on other sites More sharing options...
dav74 Posted October 30, 2013 Author Share Posted October 30, 2013 Hi Temechon,Thank you for your answer, you're right, I also think it is the right solution ! Quote Link to comment Share on other sites More sharing options...
melaugui Posted October 31, 2013 Share Posted October 31, 2013 Hi, And pay attention if you want to move your mesh in the render loop, be sure to check if your "singe" is loaded by:if (scene.isReady()){ //move singe}or to check this mesh only :if (singe){ ..//move.. } CGinSeattle 1 Quote Link to comment Share on other sites More sharing options...
dav74 Posted October 31, 2013 Author Share Posted October 31, 2013 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 ? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted October 31, 2013 Share Posted October 31, 2013 You can there is no problem:) Quote Link to comment Share on other sites More sharing options...
Zimbofly Posted July 25, 2014 Share Posted July 25, 2014 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 Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 25, 2014 Share Posted July 25, 2014 Hey, Are you sure there is an object called "bench" in your babylon file ? Quote Link to comment Share on other sites More sharing options...
reddozen Posted July 25, 2014 Share Posted July 25, 2014 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);}); Quote Link to comment Share on other sites More sharing options...
Zimbofly Posted July 25, 2014 Share Posted July 25, 2014 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? Quote Link to comment Share on other sites More sharing options...
Temechon Posted July 25, 2014 Share Posted July 25, 2014 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); Quote Link to comment Share on other sites More sharing options...
Zimbofly Posted July 25, 2014 Share Posted July 25, 2014 Yes - I can see the file - even with / without those 2 lines - it comes in fine. my problem is that I need to resize and position the chair Quote Link to comment Share on other sites More sharing options...
reddozen Posted July 25, 2014 Share Posted July 25, 2014 Do you have a link to your actual babylon file? Quote Link to comment Share on other sites More sharing options...
Zimbofly Posted July 25, 2014 Share Posted July 25, 2014 I've zipped it and attached.... no link as it's just running on localhost cheers!office_chair.zip Quote Link to comment Share on other sites More sharing options...
reddozen Posted July 25, 2014 Share Posted July 25, 2014 That file looks a little crazy. I dont see any object named "bench" in your file. the office chair appears to be made of multiple pieces and a lot of instances, but no single object named "bench" Quote Link to comment Share on other sites More sharing options...
Zimbofly Posted July 25, 2014 Share Posted July 25, 2014 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.... Quote Link to comment Share on other sites More sharing options...
Zimbofly Posted July 29, 2014 Share Posted July 29, 2014 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! GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.