Highlighting an imported object with mouse over

Hi, I’m not far away here from getting it right but I can’t seem to trigger the highlight on the imported object.

It works on Babylon meshes as per this example: https://playground.babylonjs.com/#Y4VF2N#13

but the same doesn’t seem to want to work for my example: https://playground.babylonjs.com/#9Z476P#4

Any help would be greatly appreciated.

Looks like you accidentally passed the variable camera that doesn’t exist. It works if you pass scene.activeCamera that was created with createDefaultCameraOrLight() - or you can just let the param default to scene.activeCamera like below. :slight_smile: :beers:

3 Likes

@James1 Having the console open (F12 with Chrome) really helps a lot with debugging.
In your example there is even a hint at which line you did some mistake which is now corrected by @Blake :slight_smile:

3 Likes

Excellent! Thank you so much :slight_smile: I’m learning still

1 Like

Thanks for the tip! I didn’t know that one :smiley:

1 Like

I’ve added this into my big scene but it bulk selects every building with the same mesh. Can it be done by unique ID?

I’ve started testing some new code but I can’t seem to be able to define the uniqueId correctly. Any ideas?

Better to use mesh names.
I believe the problem is related to how your model is done.
Probably you’ll need to prepare it for the desired functionality in some 3D editor.
For example, rename meshes so they wouldn’t have identical names.

1 Like

Hi, it uses instances to so it duplicates the meshes across the map I have. Using meshes with this highlight method highlights 10 or so buildings when one mesh is selected.

Hi, I’m in blender and as they are instances - if I rename one, it renames them all unfortunately so I have to go for an alternative solution (UniqueId’s if possible).

This is an example. It does have different mesh names but seems to want to highlight the same ones still. I’m just having a playaround now

Well, I don’t know much about Blender but in C4D you can create instances and name them as you need to.
I believe that more experienced Blender users could help you.
Here is what I’ve got in Blender (please note that I don’t use it in my work so I don’t know much about it). Seems that all objects have different names now.

My new babylon example has all different names as far as I can see and it doesn’t seem to want to select each object individually. I will look into the blender option - there must be a way to rename but keep the instances the same, thanks.

The source points to it being the same Mesh but I would have thought stating the name would have been enough to make it unique.

As far as I know the uniqueId is the internal parameter which may change with every page reload.

1 Like

You’re right, it does seem to change on a refresh. I don’t think the code is working as it should as it still selects objects with the following

if (result.hit && result.pickedMesh != 10) {

I think the problem is that instances are all drawn together so either they’re all highlighted or none of them are highlighted, but if you use clones instead you can highlight just the one that’s hovered over since they’re drawn separately, one at a time.

Also you can check that the mesh isn’t named “someName” like this, you might want to make the mesh un-pickable or check the name in the pick predicate instead thou (if you don’t want the mesh to block the pick). :slight_smile:

if (result.pickedMesh && result.pickedMesh.name !== "someName")

I think you need to use in Blender not “Duplicate Linked” but “Duplicate Object” to get clones instead of instances.

Unfortunately I need them to be instanced. The model size exponentially increases if I use clones rather than instanced. I can’t change the object data in blender either unless i remove the relationship. I tested with just 10 buildings and it doubled the file size. I have over 500 buildings in the model and it’s already a 100mb file that has been repolyed to the max.

A common approach that works well IMO is to create a single clone of the building to use for highlighting and then on mouse over, disable the instance and enable the clone and copy the transform over…

Sorry, I’m not quite sure what you mean there but the buildings / map is already created. I’ll share a picture below

I mean you can use a separate, non instanced building for the highlighting. Then disable the selected instance that the mouse went over and enable the clone and copy its position, scaling, rotation from the instance.