Alex10 Posted March 25, 2016 Share Posted March 25, 2016 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 pagehttp://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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 25, 2016 Share Posted March 25, 2016 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); Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 29, 2016 Author Share Posted March 29, 2016 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 29, 2016 Share Posted March 29, 2016 To go further, can you please create a playground. This way I will be able to fix the code for you Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 29, 2016 Author Share Posted March 29, 2016 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 29, 2016 Share Posted March 29, 2016 Are you looking to the real center of your object? then use: mesh.getBoundinfo().boundingSphere.centerWorld as your vector3 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 29, 2016 Author Share Posted March 29, 2016 That it will give me? In this case (mesh.getBoundingInfo().boundingSphere.centerWorld), the coordinates {x: 0, y: 0, z: -0.000014999999997655777}. What to do with these coordinates? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 29, 2016 Share Posted March 29, 2016 Ok perhaps I misunderstood. What does ( 216, 93, -17 ) represent? Alex10 1 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 30, 2016 Author Share Posted March 30, 2016 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. Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted March 30, 2016 Share Posted March 30, 2016 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); Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 30, 2016 Author Share Posted March 30, 2016 @aWeirdo Yes I am using arcRotateCamera. I wrote cam.target = mesh.position; but the model does not fit into the screen. For example:http://178.62.253.28/test2 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted March 30, 2016 Share Posted March 30, 2016 Your mesh is very large, there are two options, scaling it down, or zooming the camera out(see the edit on my previous post) Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 30, 2016 Author Share Posted March 30, 2016 @aWeirdo Ok, When I scaled the model, the model becomes unmanageable fine. for example: http://178.62.253.28/test How to calculate a zoom on the camera? I need zoom to set automatically. Or to set automatically camera.setPosition() Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 30, 2016 Share Posted March 30, 2016 You can evaluate the zoom (radius) by getting mesh.getBoundingInfo().boundingSphere.radiusWorld * 1.1 (or a bigger constant) Alex10 1 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted March 30, 2016 Author Share Posted March 30, 2016 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted March 31, 2016 Share Posted March 31, 2016 What I suggest is to set arcRotateCamera.radius to mesh.getBoundingInfo().boundingSphere.radiusWorld * 1.1 Look: http://www.babylonjs-playground.com/#I7U4M#4 Alex10 1 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted April 1, 2016 Author Share Posted April 1, 2016 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 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 1, 2016 Share Posted April 1, 2016 Like this: http://www.babylonjs-playground.com/#I7U4M#6 Alex10 1 Quote Link to comment Share on other sites More sharing options...
Alex10 Posted April 2, 2016 Author Share Posted April 2, 2016 Yes this is what I needed, thank you very much. 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.