splash27 Posted December 25, 2017 Share Posted December 25, 2017 I want to implement a switch inside scene world. https://www.babylonjs-playground.com/#SSXJEN (Scene uses WASD controls and mouse-look) The switch is represented by the red face of the mesh. I want to launch a custom code, when the switch is activated (when user presses "e" near the switch). I thought to use an actionManager. However, I don't know how to determine that I'm standing in front of the red face near the mesh. At this point the custom code runs every time I press "e". How to find out that I am near the switch and I am actually looking at it? Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 25, 2017 Share Posted December 25, 2017 Hiya splash and everyone. Hairy Krishmas! https://www.babylonjs-playground.com/#SSXJEN#2 There's one way of many. Lines 44-47 establish a "sensor" plane... glued to the box. (later invisible, likely) Lines 63-68 check that the sensor-plane is in-view of the camera, and 2 units or less away-from camera. If all that is satisfied, 'e' keypress will work. I tried it using the box itself and not a 'sensor', but that allows 'e' presses from the OTHER sides of the box. The sensor worked better. Others might have better ideas, so stay tuned. PS-aside: Does anyone else see the playground app... do a screen-scroll... when camera/keyboard down-arrow is used? White "bar" appears on bottom of PG screen, removed by pressing up-arrow? (Wingnut using Firefox). It's been happening for a few months now, and it sure is annoying when using freecams, eh? Maybe I'm the only one that sees it. Something in the CSS needs overflow: none;, or something. splash27 1 Quote Link to comment Share on other sites More sharing options...
splash27 Posted December 25, 2017 Author Share Posted December 25, 2017 Hi, Wingnut! Happy Christmas! Great idea! I thought that I can use facets data in similar way, but decided that it will be hard to determine where each facet is on complex mesh. So, the sensor's approach is much more easy and predictable. By the way, can you clarify what scene._frustumPlanes contains? At this moment it works like magic for me. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 25, 2017 Share Posted December 25, 2017 hehe. I stole it from here... https://www.babylonjs-playground.com/#DGTY21#1 I think others better explain it. It's magic stuff, to me. I guess... at camera.minZ and camera.maxZ... there are some magical invisible non-mesh planes. They delineate the start and end of the camera's field of view (fov) frustum/cone. isInFrustum() uses this scene.activeCamera FOV cone, for testing. That's all the further I want to explain. It can be read-about, mostly on the web. Or, study BJS source code. I'm pretty stupid on that subject, sorry. NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
splash27 Posted December 25, 2017 Author Share Posted December 25, 2017 @Wingnut, are you sure that the link you shared is correct? I didn't find _frustumPlanes there. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 25, 2017 Share Posted December 25, 2017 Line 96. It is this._frustumPlanes... but it is inside-of an "overload-the-scene-object" add-on function, so I know this means scene. Why the interest in the camera frustum? Do you have some mad scientist ideas? I think some folks use it to rotate/position the camera so that ALL mesh in the scene, are in-view. *shrug* Quote Link to comment Share on other sites More sharing options...
splash27 Posted December 26, 2017 Author Share Posted December 26, 2017 @Wingnut, the most interactibles in most of the games requires to be inside field of view of the camera before activating. I think it's pretty common question: "How to detect that I'm looking at something?" After your suggestion I wonder how `scene._frustumPlanes` helps me with it. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 28, 2017 Share Posted December 28, 2017 Hi again. You could also parent an invisible mesh to the front of the player/camera. Then use intersectsMesh(). If the invisible mesh is not intersecting with the interaction device/mesh, no interaction allowed. Perhaps worth some tests. 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.