br4tp1t Posted May 31, 2015 Share Posted May 31, 2015 Hi, im trying to show imported mesh but nothing appears, my code looks like this:canvas = document.getElementById("3dcanvas"); engine = new BABYLON.Engine(canvas, true); var createScene = function () { var scene = new BABYLON.Scene(engine); scene.clearColor = new BABYLON.Color3(0, 0, 0); var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene); camera.setTarget(BABYLON.Vector3.Zero()); camera.attachControl(canvas, false); var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene); light.intensity = .5; //var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene); //sphere.position.y = 1; var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene); BABYLON.SceneLoader.ImportMesh("rack_hp", "./", "rack_hp.babylon", scene, function (newMeshes) { alert(newMeshes[0].id); newMeshes[0].position = new BABYLON.Vector3(0,0,0); camera.target = newMeshes[0]; }); return scene; }; var scene = createScene(); engine.runRenderLoop(function () { scene.render(); });i can see that mine http server sended the rack_hp.babylon file, also the alert with "newMeshes[0].id" is showing, i was trying also to change position of this mesh and change camera.target but nothing helped here are mine files(im sending also obj file that ive converted with blender to babylon): https://www.dropbox.com/s/gkgh1m7o1jnmbsq/rack_hp.mtl?dl=0https://www.dropbox.com/s/wsgq88rxmejg75w/rack_hp.obj?dl=0https://www.dropbox.com/s/llhw5zahezuu9rm/rack_intrapp.babylon?dl=0 Regards,Piotr Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 1, 2015 Share Posted June 1, 2015 Hey, can you show us a demo of this scene somewhere? Will be easier to debug. Quote Link to comment Share on other sites More sharing options...
br4tp1t Posted June 1, 2015 Author Share Posted June 1, 2015 Hey, you mean how this mesh looks like in blender or what do you mean by demo of this scene? Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 1, 2015 Share Posted June 1, 2015 this javascript code running somewhere online. Will help us help you :-) Quote Link to comment Share on other sites More sharing options...
br4tp1t Posted June 1, 2015 Author Share Posted June 1, 2015 http://bcagroup.pl/babylon/ Quote Link to comment Share on other sites More sharing options...
gryff Posted June 1, 2015 Share Posted June 1, 2015 Hi Piotr, welcome to the babylon forum I think your problem lies with the object you are exporting. The object is huge and even though the origin of the object is at (0,0,0) (yellow dot, A in image below) the closest faces are a long way from that origin point (see B and C in image below). If you are making the camera look at the origin - probably does not see the actual mesh. cheers, gryff Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 1, 2015 Share Posted June 1, 2015 Hey, a quick look at your object - it is not centered at 0,0,0 , so setting its position at 0,0,0 is not going to work :-) Try doing that (after loading the mesh):newMeshes[0].position = newMeshes[0].getBoundingInfo().boundingBox.center.clone().negate()and back away a bit, you will see the object. Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 1, 2015 Share Posted June 1, 2015 And gryff explained how to fix it :-) perfect Quote Link to comment Share on other sites More sharing options...
gryff Posted June 1, 2015 Share Posted June 1, 2015 And gryff explained how to fix it Well not really RaananW - just the problem ;-) One fix Piotr is : 1. In Object Mode in Blender, select the object, then go Object->Transform->Geometry To Origin.2. Now re-export the mesh3. Because the object is so large, and your camera settings are:var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);it means you are likely to be inside the object To fix this, will have to: 1. Scale down the object or2. Move the camera so that its Z position is is perhaps ~ -150 to -200 units3. And possibly set the maxZ value of the camera to perhaps 500 cheers, gryff Quote Link to comment Share on other sites More sharing options...
br4tp1t Posted June 1, 2015 Author Share Posted June 1, 2015 ok i can see mine mesh, but dont have any idea how to move it corectly to center view, or how to export it corectly, because im not familiar with bledner etc Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 1, 2015 Share Posted June 1, 2015 And NOW gryff explained how to fix it :-) Quote Link to comment Share on other sites More sharing options...
br4tp1t Posted June 1, 2015 Author Share Posted June 1, 2015 ok really thanks for help, ive exported once again the mesh but now ive scaled it down in blender and moved to center position it works like a charm Thanks guys but now ive got second question, what is the best way to clone mine mesh because i need to make like 200 of them in one scene, and all of them need its own unique id so i can identify them, is there a way to save custom variables to mesh? so when i click them ill get mine variable/variables? Quote Link to comment Share on other sites More sharing options...
gryff Posted June 1, 2015 Share Posted June 1, 2015 but dont have any idea how to move it corectly to center view As I said above Piotr, "In Object Mode in Blender, select the object, then go Object->Transform->Geometry To Origin." You can select an object by right clicking on it. Then see image below for the "Object->Transform->Geometry To Origin." part. cheers, gryff br4tp1t 1 Quote Link to comment Share on other sites More sharing options...
gryff Posted June 1, 2015 Share Posted June 1, 2015 best way to clone mine mesh because i need to make like 200 of them in one scene Piotr, I'm not sure using mesh.clone() will be the way to go as your mesh has 42,000+ tris. And that would leave you with 8 million+ tris in your scene. This might be an alternative: Instances However, with "Instances" you can only vary certain properties of the meshes (see the link) cheers, gryff Quote Link to comment Share on other sites More sharing options...
br4tp1t Posted June 1, 2015 Author Share Posted June 1, 2015 instances are perfect cheers again 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.