MehdiZagouri Posted November 4, 2017 Share Posted November 4, 2017 Hello , It's my first post in the forum. I need your help. When i click in a mesh , i need the camera get in front of the Mesh. Thanks for your answers. Quote Link to comment Share on other sites More sharing options...
Raggar Posted November 4, 2017 Share Posted November 4, 2017 Maybe you could create a playground example to show us what you want? Here's a simple example: http://playground.babylonjs.com/#GSPKL6 But that doesn't take camera rotation into account, and only changes the camera's X-position. MehdiZagouri 1 Quote Link to comment Share on other sites More sharing options...
MehdiZagouri Posted November 4, 2017 Author Share Posted November 4, 2017 This is my scene , it's a musuem ! with meshes (Pictures) When i click into a mesh , i need the camera move in front of the picture , in order to see it " like a visitor " Quote Link to comment Share on other sites More sharing options...
Arte Posted November 4, 2017 Share Posted November 4, 2017 Hi @MehdiZagouri move camera to you position: camera.setPosition(new BABYLON.Vector3(x,y,z)); and camera.target = picture.position; MehdiZagouri 1 Quote Link to comment Share on other sites More sharing options...
MehdiZagouri Posted November 4, 2017 Author Share Posted November 4, 2017 Hi @Arte I really appreciate your help ! I tried this solution before , the issue is that , when i click in mesh "picture"' , the camera get the position of the mesh , that's not what i need , i need the camera just in front of the picture with a distance. so when camera.position = picture.position ; i cannot see the picture , but i'm in the picture if you know what i mean ! Thank you so much. Quote Link to comment Share on other sites More sharing options...
adam Posted November 5, 2017 Share Posted November 5, 2017 Something like this should work: var dir = pictureMesh.getDirection(pictureLocalForwardAxis); camera.setPosition(dir.scale(distInFront).add(picture.position)); MehdiZagouri and Arte 1 1 Quote Link to comment Share on other sites More sharing options...
jerome Posted November 5, 2017 Share Posted November 5, 2017 or by using FacetData : http://doc.babylonjs.com/how_to/how_to_use_facetdata#facet-normal Arte, MehdiZagouri and adam 2 1 Quote Link to comment Share on other sites More sharing options...
Arte Posted November 5, 2017 Share Posted November 5, 2017 Or predefined visitor position like: picture.metadata.visitorPosition = x,y,z; MehdiZagouri and adam 1 1 Quote Link to comment Share on other sites More sharing options...
MehdiZagouri Posted November 5, 2017 Author Share Posted November 5, 2017 Thanks for all your answers ! I tried your solutions, but sometimes i don't know how to use them ,so i get a lot of unknown errors ! I tried this solution ! so i get next to the mesh, know i need only to focus the direction of the camera in to the mesh " picture '" wich is Tableau[t] in my code : if (pickResult.pickedMesh==Tableau[t]) { console.log("Coucou"); while (BABYLON.Vector3.Distance(camera.position,Tableau[t].position) > 5) { console.log(BABYLON.Vector3.Distance(camera.position,Tableau[t].position)); if (camera.position.x >Tableau[t].position.x + 2 ) { camera.position.x -= 0.5; } else if (camera.position.x <Tableau[t].position.x + 2 ) { camera.position.x += 0.5; } if (camera.position.z >Tableau[t].position.z +2) { camera.position.z -= 0.5; } else if (camera.position.z <Tableau[t].position.z +2 ) { camera.position.z += 0.5; } } //camera.setTarget = Tableau[t].position; } Quote Link to comment Share on other sites More sharing options...
Arte Posted November 5, 2017 Share Posted November 5, 2017 @MehdiZagouri My working option PG. I hope this will help you. ************* Edited: Sorry i forgot line camera.target=pickInfo.pickedMesh.position; playground.babylonjs.com/#DG8ETH#1 MehdiZagouri 1 Quote Link to comment Share on other sites More sharing options...
MehdiZagouri Posted November 5, 2017 Author Share Posted November 5, 2017 Thank you very much @Arte, Your solution is great, it works properly , without bugs I really appreciate your help. Arte 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.