benjydel Posted February 27, 2016 Share Posted February 27, 2016 Hi ! I have to create a room in babylon js. I have used 4 plane for the walls and a ground for the ground. With that, we can see all the time on the room because some side are visible and some not. I would like to know if we can do that with some other mesh like ligne. I have to do a grid on the wall and the ground. Tkanks ! Quote Link to comment Share on other sites More sharing options...
jerome Posted February 27, 2016 Share Posted February 27, 2016 to design a grid made with several lines, the LineSystem would be the right candidate : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#linesystem Quote Link to comment Share on other sites More sharing options...
benjydel Posted February 27, 2016 Author Share Posted February 27, 2016 29 minutes ago, jerome said: to design a grid made with several lines, the LineSystem would be the right candidate : http://doc.babylonjs.com/tutorials/Mesh_CreateXXX_Methods_With_Options_Parameter#linesystem Ho thank you but i can't find the documentation about this thing Quote Link to comment Share on other sites More sharing options...
adam Posted February 27, 2016 Share Posted February 27, 2016 If you need one side of the LineSystem to be invisible, you can do something like this: http://www.babylonjs-playground.com/#1DKDYG#3 The sideOrientation property doesn't work for LineSystem or LinesMesh. benjydel 1 Quote Link to comment Share on other sites More sharing options...
benjydel Posted February 28, 2016 Author Share Posted February 28, 2016 12 hours ago, adam said: If you need one side of the LineSystem to be invisible, you can do something like this: http://www.babylonjs-playground.com/#1DKDYG#3 The sideOrientation property doesn't work for LineSystem or LinesMesh. Thank you very much I try to understand how your solution works but i am blocked at this lines : var mat = camera.getWorldMatrix(); camVec.x = mat.m[8]; camVec.y = mat.m[9]; camVec.z = mat.m[10]; How do you know which coordonate is the "camVec" ? Because i need to repeat this on other planes An other question : Can i add several registerBeforeRender() ?? I mean, if y iterate this again won't it be erase ?? Thank you very much again Quote Link to comment Share on other sites More sharing options...
adam Posted February 28, 2016 Share Posted February 28, 2016 It appears as though you can add several registerBeforeRender functions. http://www.babylonjs-playground.com/#1DKDYG#4 1 hour ago, benjydel said: How do you know which coordonate is the "camVec" ? Because i need to repeat this on other planes You can do this instead: http://www.babylonjs-playground.com/#1DKDYG#6 If the dot product of the camera direction vector and the normal of the plane is negative, then the plane should be facing you. I'm not sure why it isn't working perfectly though if the plane is translated like this: http://www.babylonjs-playground.com/#1DKDYG#5 Maybe someone else here will know what the issue is. Quote Link to comment Share on other sites More sharing options...
benjydel Posted February 28, 2016 Author Share Posted February 28, 2016 Thank you @adam I finally found the issue. But i can't explain how it work, I have been inspired of your solution: var VecteurNormal; var camVec = BABYLON.Vector3.Zero(); VecteurNormal = BABYLON.Vector3.Cross(new BABYLON.Vector3(0,-1,0), new BABYLON.Vector3(0,0,-1)); scene.registerBeforeRender(function () { var mat = camera.getWorldMatrix(); camVec.x = mat.m[12]; camVec.y = mat.m[13]; camVec.z = mat.m[14]; var dot = BABYLON.Vector3.Dot(camVec, VecteurNormal); if (dot > 0) { ligne.visibility = 1; } else { ligne.visibility = 0; } }); And if there is a translation : camVec.x = mat.m[12]+xTranslation; camVec.y = mat.m[13]+yTranslation; camVec.z = mat.m[14]+zTranslation; Quote Link to comment Share on other sites More sharing options...
adam Posted February 29, 2016 Share Posted February 29, 2016 19 hours ago, benjydel said: And if there is a translation : camVec.x = mat.m[12]+xTranslation; camVec.y = mat.m[13]+yTranslation; camVec.z = mat.m[14]+zTranslation; You are going to need the dot product of normalized vectors. Quote Link to comment Share on other sites More sharing options...
adam Posted February 29, 2016 Share Posted February 29, 2016 I think I figured out what I was doing wrong: http://www.babylonjs-playground.com/#1DKDYG#7 https://en.wikipedia.org/wiki/Back-face_culling#Implementation GameMonetize and benjydel 2 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.