Jump to content

Imported .obj mesh when changing positions becomes unmanageable


Alex10
 Share

Recommended Posts

After I import the mesh, if I don't change his position and if I don't change the camera's position, all is well.
But I want after loading the mesh entirely intermeddle in screen, without zooming with the mouse wheel.
If I change the mesh position it becomes impossible to twist the mouse.

 

mesh.onSuccess = function (task) {
   m = task.loadedMeshes;
   for(var i = 1; i < m.length; i++) {
      m.position = new BABYLON.Vector3(25, -250, -40);
   }

If I change the camera position also becomes impossible to twist the mouse.


var cam = new BABYLON.ArcRotateCamera("ArcRotateCamera", 0, 1.8, 5, new BABYLON.Vector3(170, -50, 10), scene);

Working option but the mesh won't fit in the screen.
http://178.62.253.28/  test page
 

After the change of position of the mesh loaded it does not work normally turn the mouse.
http://178.62.253.28/pos_mesh  test page
http://178.62.253.28/st/z_pm.js

If you change the camera's position is also that the mesh can't be controlled.
http://178.62.253.28/pos_cam   test page

http://178.62.253.28/st/z_pc.js

 

 

Link to comment
Share on other sites

Hey I guess there is a misunderstanding here: the camera does NOT control the mesh. It rotates around a center. 

 

In your case if you move the mesh then the camera does not rotate around it because the mesh is not on the center of the camera

 

i suggest just taking your first example and increment the radius of your arcrotatecamera: 

var cam = new BABYLON.ArcRotateCamera("ArcRotateCamera", 0, 1.8, 30, new BABYLON.Vector3(170, -50, 10), scene);

 

Link to comment
Share on other sites

Work with this option:
 

camera.setPosition( new BABYLON.Vector3( 216, 93, -17 ));


http://178.62.253.28/  test page

But for me this is not an option. Because I need to automatically calculate these values BABYLON.Vector3(216, 93, -17). And I don't know how to do it.

I need to boot the entire model got into the screen.

I can easily calculate how much to scale the model, but then I can't do it normally to turn the model with the mouse.

http://178.62.253.28/test test page

Which method is to automatically set the position of the camera so that when load the model is fully intermeddle in the frame?
Or maybe there is a way to force the model to turn normal mouse after scaling?

 

 

 

 

Link to comment
Share on other sites

Ok, But I did not succeed in the playground I need to load a model in format .obj. Probably this limitation of the playground.
Model and texture normally given for this:
http://178.62.253.28/f/mesh.obj

http://178.62.253.28/f/dif.png

This is the code with the set manual in the camera position:

http://www.babylonjs-playground.com/#1BU3RZ#1

This is the code with scaling of the model:

http://www.babylonjs-playground.com/#1RDKDQ

Link to comment
Share on other sites

camera.setPosition( new BABYLON.Vector3( 216, 93, -17 ));

@Deltakosh This manually set position of the camera in which this model got into the screen. And I need to automatically calculate this position.

I need to page load any model got into the screen. Like sketchfab.com. For this I need to automatically calculate the camera's position. How to do I don't know.

Link to comment
Share on other sites

If you are using arcRotateCamera, and i understood you correctly, simply setting the camera target to the mesh position would keep the the center of your mesh as your camera's target even if the mesh is moved.

Example:(after mesh have loaded)

yourCam.target = yourMesh.position;  

 

Edit:

You also wrote that the mesh doesn't 'fit' in the screen, increase camera view distance.

//the field set to 50 is the "view distance" field.

BABYLON.ArcRotateCamera("ArcRotateCamera", 0, 1.8, 50, new BABYLON.Vector3(0, 0, 0), scene);

Link to comment
Share on other sites

If I multiply these coordinates:
{ 0*1.1, 0*1.1, -0.000014999999997655777*1.1 }  
Then I'll have the following coordinates for "setPosition"
cam.setPosition( 0, 0, -0.000016499999997421355 )
and get this result:
http://178.62.253.28/test    -  model not got completely into the viewport

and I need to get around these coordinates
cam.setPosition( new BABYLON.Vector3(216, 93, -17) );
http://178.62.253.28/     -    model got completely into the viewport

How do I get the coordinates of the camera in which the model will got completely into the viewport?

Link to comment
Share on other sites

Exactly, I think this is what I need. How I can the model change color or texture when I click on button?
Event occurs but the error occurs.

$('#button').on('click', function(){
   console.warn('Yes');
   m[i].material = new BABYLON.StandardMaterial("texture1", scene);
   m[i].material.diffuseColor = new BABYLON.Color3(1, 0, 0);
});

For example:

http://www.babylonjs-playground.com/#I7U4M#5

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