Jump to content

Cant see imported mesh


br4tp1t
 Share

Recommended Posts

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=0

https://www.dropbox.com/s/wsgq88rxmejg75w/rack_hp.obj?dl=0

https://www.dropbox.com/s/llhw5zahezuu9rm/rack_intrapp.babylon?dl=0

 

Regards,

Piotr

Link to comment
Share on other sites

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 :)

 

 

post-7026-0-39550100-1433164110.png

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 mesh

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

2. Move the camera so that its Z position is is perhaps ~ -150 to -200 units

3. And possibly set the maxZ value of the camera to perhaps 500

 

cheers, gryff :)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :)

post-7026-0-57602600-1433167053.png

Link to comment
Share on other sites

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 :)

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