Best way to pick 3D meshes imported by blender

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TobiLa

Hey,
I have many different 3d-meshes imported in scenes from blender.
Now I want to get the respective mesh object from a 2d viewport coordinate of my camera.

What is the best way to handle this?
I read this can be done by adding collision shapes to my meshes and using their input events. But for this I would need to create a new scene for each of my exported scenes, since they are not editable and add a collision shape there, afterwards replacing every loaded scene in my game by the inherited one. Doesn’t seem like a clean solution to me.

I know there is another method using a raycast from my camera, but I don’t know how to check the collision with a mesh then.

Thanks for your help,
Tobi

I can’t get why you aren’t generating collider based on given mesh. No need to create different scene for each mesh. You could attach project demo, maybe I don’t understand your problem and that will help me solve it.

Oen44 | 2018-09-18 11:29

Thanks for your comment, I try my best to explain it a little better. I’m not sure yet how a demo project explaining my issue could look like, I think it may be easier if I describe it this way:

I used blender to create a few 3D buildings, which I exported using the better-collada-exporter. I have a folder with all my materials and one .dae file for each building.

Imported in Godot each .dae file is one scene, which is not editable. Inside the scene is one node with one MeshInstance node. I can’t create a collision shape in that scene without creating a new inherited scene. That’s what I mean by “creating a new scene for each object”.

From my camera’s view I want to know which building is at a given screen position.

I managed to implement some other things without creating an inherited scene from each of my exported .dae’s, so I am looking for a solution that gets this task done without creating new inherited scenes either.

TobiLa | 2018-09-18 12:26

:bust_in_silhouette: Reply From: Oen44

In your Scene tree select models, right-click and select “Discard Instancing” - that way you can edit them in that scene.

Ah nice. Then I can go and generate a Collision-Shape, I see. Thanks.
One question building upon this:

Do I lose the connection to my exported scene when doing this?
When I update my mesh in blender and want to reimport it, do I have to delete the mesh and reimport it, making all my modifications again or is there another way to just update the mesh?

TobiLa | 2018-09-18 12:34

About importing, I’m not sure, but I think it won’t update. I just can’t think of a different way to achieve what you need without creating separate scenes.

Oen44 | 2018-09-18 12:52

So creating inherited scenes is the more common workflow in godot? If it makes more sense I would do that, it just didn’t sound like the clearest and easiest way to me. How do other users deal with imported meshes?

TobiLa | 2018-09-18 13:03

That’s how I do it. Separated scenes are good if you want to do more stuff. For example I have Sword in my RPG game, that Sword has Particle System, collision and all stuff. I can use that one scene as template for other weapons. It’s good because project structure is clean that way.

Oen44 | 2018-09-18 13:07

Thanks again, that sounds interesting. Can you give me a hint on where I can find more about the functionality for using scenes a templates?

TobiLa | 2018-09-18 13:11

By templates I meant that I have one scene that I’m duplicating and just changing some stuff. Then I’m using script to spawn that scene and so stuff with it.
Here is example of Player and Sword spawning (C#):

public override void _Ready()
{
    Node root = (Node)GetTree().GetRoot().GetNode("Spatial");

    PackedScene playerRes = (PackedScene)GD.Load("res://scenes/Player.tscn");
    player = (Player)playerRes.Instance();

    PackedScene swordRes = (PackedScene)GD.Load("res://scenes/Sword.tscn");
    Node sword = swordRes.Instance();
    player.SetTranslation(new Vector3(0, 5, 0));
    player.GetNode("Character/metarig/Skeleton/RightHand").AddChild(sword);
    root.AddChild(player);
}

Oen44 | 2018-09-18 13:16