Hugo M Posted December 14, 2018 Share Posted December 14, 2018 I have this code: var tiledGround = new BABYLON.Mesh.CreateTiledGround("Tiled Ground", xmin, zmin, xmax, zmax, subdivisions, precision, scene); tiledGround.actionManager = new BABYLON.ActionManager(scene); tiledGround.actionManager.registerAction( new BABYLON.ExecuteCodeAction( BABYLON.ActionManager.OnPickTrigger, e => { // TODO: I need to know which submesh was clicked console.log(e); }, null )); var whiteMaterial = new BABYLON.StandardMaterial("White", scene); whiteMaterial.diffuseColor = new BABYLON.Color3(1, 1, 1); var blackMaterial = new BABYLON.StandardMaterial("Black", scene); blackMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0); var multimat = new BABYLON.MultiMaterial("multi", scene); multimat.subMaterials.push(whiteMaterial); multimat.subMaterials.push(blackMaterial); tiledGround.material = multimat; var verticesCount = tiledGround.getTotalVertices(); var tileIndicesLength = tiledGround.getIndices().length / (subdivisions.w * subdivisions.h); tiledGround.subMeshes = []; var base = 0; for (var row = 0; row < subdivisions.h; row++) { for (var col = 0; col < subdivisions.w; col++) { tiledGround.subMeshes.push(new BABYLON.SubMesh(row%2 ^ col%2, 0, verticesCount, base, tileIndicesLength, tiledGround)); base += tileIndicesLength; } } So basically I'm not sure how to know which submesh was clicked. The result for the event gives me some X and Y coordinates but they don't seem related at all with my mesh size. Ej the tiledGround size is 10x10 (I'm not sure which units are used by Babylon) but the pointer gives me something like x: 800, y: 200. Obviously they are not the same magnitudes. My point is that I'd be able to calculate to which tile correspond the click if the pointers were related to the actual position on the plane, but they don't seem to. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted December 14, 2018 Share Posted December 14, 2018 Hi Hugo, welcome to the (old) forum. Feel free to join us at the new forum: https://forum.babylonjs.com/ Post about your issue... over there, if you would. You don't need to paste your code again. Here's a testing playground with your code included... https://www.babylonjs-playground.com/#1OJ4YL#1 Apparently, no faceID values are available with tiledGround actionManager events. (like you stated) I believe you MIGHT need to "calculate" which face/cell was clicked... using some math. Anyway, c'mon over to the new forum... re-post your issue in the QUESTIONS sub-forum, if you like. (and include that playground URL listed earlier) PERHAPS others will comment, here. Not sure. There's a party happening at the new forum and I think almost everyone is over there, having fun with the new forum software. Come on-over to the party... we'll work-on your issue over there. Thx! Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted December 15, 2018 Share Posted December 15, 2018 @Hugo M If you're open to other solutions https://forum.babylonjs.com/t/tiled-ground-using-sps-and-spritesheet-textureatlas-updated/260?u=aweirdo Quote Link to comment Share on other sites More sharing options...
Hugo M Posted December 17, 2018 Author Share Posted December 17, 2018 @Wingnut Thanks! I'm already registered in the new forum and I will ask there. @aWeirdo that looks useful, thanks! 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.