Rodrico Posted April 13, 2017 Share Posted April 13, 2017 Hello folks. First of all sorry for duplicating this as I've already asked for same thing on StackOverflow but I've seen really strong audience in other posts on this forum so I'll do so. I've got grid of cylinder meshes created simply by var tile = BABYLON.MeshBuilder.CreateCylinder("tile-" + i, { tessellation: 6, height: 0.1 }, scene); then I have following event callback window.addEventListener("click", function (evt) { // try to pick an object var pickResult = scene.pick(evt.clientX, evt.clientY); if (pickResult.pickedMesh != null){ alert(pickResult.pickedMesh.name) }); Then `mouse-click` on one of `tiles` raises `message box` with correct tile name. When I add some new meshes (3D model inside `.babylon` file) by var house; BABYLON.SceneLoader.ImportMesh("", "../Content/" , "house.babylon" , scene , function (newMeshes) { house = newMeshes[0]; }); For better imagination it's texture of house created from four different meshes which is placed over `grid` of `cylinder` tiles. It's displayed fine but when `mouse-click` it too much often behave as it would totally ignore there is such a mesh and so `pickResult.pickedMesh` is either `null` or `pickResult.pickedMesh.name` points to tile underlaying my imported mesh in point I've clicked. Just approximately `5%` of mesh area corresponds properly to `mouse-clicks` (let's say in middle of roof, in middle of walls). I've tried playing with setting some virtual (hidden) `house.parent` `mesh` for that which would not be created by importing meshes but seems as dead end. Are you aware about some way how enforce that `scene.pick(evt.clientX, evt.clientY);` would respect mesh hierarchy and would consider all visible parts of overlaying texture please? Just for completeness I'm working with middle part of this 3D model (removed left and right house from that). Thanks in advance. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 13, 2017 Share Posted April 13, 2017 Hello and welcome, we may need a repro case in the playground to help you. I'm not sure to picture the issue correctly Quote Link to comment Share on other sites More sharing options...
Rodrico Posted April 13, 2017 Author Share Posted April 13, 2017 Would you have some tip how use my .babylon file along with .png textures in playground itself please or should I rather use some other website for sharing them? Thanks. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 13, 2017 Share Posted April 13, 2017 I suggest using rawgit: https://www.babylonjs-playground.com/#1F98JB#2 Rodrico 1 Quote Link to comment Share on other sites More sharing options...
Rodrico Posted April 13, 2017 Author Share Posted April 13, 2017 Thanks a lot for example My demo is here: http://babylonjs-playground.com/#V26CZB hope it will work. My goal is to be able recognize that house was clicked. Thanks Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 14, 2017 Share Posted April 14, 2017 And here is your fix: http://babylonjs-playground.com/#V26CZB#1 You were not using the right coordinates Rodrico 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 14, 2017 Share Posted April 14, 2017 Welcome, @Rodrico! Cool scene! I like it. GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Rodrico Posted April 14, 2017 Author Share Posted April 14, 2017 Awesome @Deltakosh, that made exactly what I needed, thanks. It was so small change needed and it learned me so much while walking through it, thanks for activity in this thread once more @Wingnut thanks for compliment 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.