One Object Two Meshes on Import Makes Picking Difficult

First of all let us agree that there are now better ways to deal with dragging using behaviors. However the main issue is that when importing from a .babylon file picking is a problem since there seems to be two meshes to choose from. This has me very confused.

In the following PG I import the rabbit using SceneLoader.importMesh twice. On the first load I assign the rabbit to meshes[0] and in the second to meshes[1]. On the right is rabbit0 and rabbit1 is on the left. For both I set isPickable to false but it only applies to rabbit1.???

https://playground.babylonjs.com/#279FW9#56

In the next PG I import once and assign to meshes[0] and meshes[1]. Only one rabbit is visible so attempt to split them by assigning to each a different position. Changing the position of rabbit1 and rabbit0 independently makes no difference the viewable rabbit moves as one. Again setting ‘rabbit0.isPickable = false’ does not stop it being picked whilst changing (line 30) to ‘rabbit1.isPickable = false’ does have an affect.

https://playground.babylonjs.com/#279FW9#57

Finally in the following PG I try using clones as a means of further exploration

The imported rabbit (0 and 1) is front left, rabbit2 (a clone) is far to the back and rabbit3 (another clone) is mid distance and on the right. Interestingly (but strangely) the position of rabbit3 is tied to the imported rabbit - see what happens when you change values on lines 31 or 32. The usual business of isPickable applies to rabbit0 and rabbit1 but seemingly to rabbit2 and rabbit3 (change line 42 to rabbit3).

https://playground.babylonjs.com/#279FW9#58

Having (to some extent) solved some of the issues the last question of the topic stumped me because of the above issue.

So :slight_smile:

  1. https://playground.babylonjs.com/#279FW9#59 Both rabbits have to be set to meshes[0] as meshes is not scene.meshes but the list of meshes loaded by the current ImportMesh

  2. This could not work as there is only one rabbit. You can clone meshes[0] if you want: https://playground.babylonjs.com/#279FW9#60

  3. same issue: rabbit is meshes[0]

So what is in meshes[1] and why does the the following PG only work if you put (line 23) ‘rabbit = meshes[1]’ and not ‘rabbit = meshes[0]’.

The intended result is rabbit is not ‘pickable’ until worker button is clicked then remains ‘pickable’ until worker button clicked again and repeat.
rabbit = meshes[0] then rabbit always pickable
rabbit = meshes[1] then rabbit works as described.

meshes[1] is the child of meshes[0]:

The geometry is hosted by meshes[1} aka “/0” so it is ok to flag him as pickable or not as the parent (aka rabbit or meshes[0] is only a TransformNode)

But for cloning you need to clone from the parent to get the correct transforms

Fine for one mesh as it was easy to see which to set to pickable (ie I now know in the above case meshes[1] contains the geometry). Suppose I now want to load all the meshes stored, for example, in the playground scenes folder. How do I know which is parent, which has the geometry, ie which to assign isPickable to. What if I am loading models created elsewhere?

TransformNode won’t get geometry so you can look for all the meshes when loaded.
Something like:

meshes.forEach(m => {
if (m.getClassName() === "Mesh") {
 m.isPickable = false;
}
});
1 Like

Thank you. Further experimentation shows that as sebavan suggested in his post to the original questioner behaviors are the way to go

https://playground.babylonjs.com/#279FW9#61

my pleasure!