What does assetManager.loadModel(); return?

Hi,

I think I have a rather simple question, but I somehow don’t find a solution.
I want to check which object the user clicked on so I’m using part of the HelloPicking code from the tutorial section.

Now the problem is, that I’m loading a model via assetManager.loadModel(); Usually it should return a Spatial object but after
some debugging I found out, that it sometimes returns a Spatial, a Geometry or even a Node object.
But I need a Geometry or Spatial (I could cast it down to a Geometry) to check with geom.getName() which object was hit (because

So how can I make sure that the assetManager gives me an Spatial or Geometry object and not a Node?
Or is there a way to handle the check process with a node?

and why do u need that?

The way I handle it when I need to fetch an entity’s models for whatever reason is to do a search and return the results as a list.

The structure I keep is something along these lines

Entity (Node)
– Visuals (Node)
---- Model (Node)
---- Billboard stuff (Node)

Then for fetching the model geometries I use

[java]
public Geometry getModelGeometry() {
final List<Geometry> geometries = getModelGeometries();
return geometries.size() < 1 ? null : geometries.get(0);
}

public List&lt;Geometry&gt; getModelGeometries() {
	return model.descendantMatches(Geometry.class);
}

[/java]

I’m with eraslt on this one. If you think you need this then you are doing something else wrong.

A Geometry is a Spatial and a Node is a Spatial. You always (always always) get a Spatial back. It may also be either a Geometry or a Node.

I feel like this is one of those cases for my "learning to ride a bike and learning to shave at the same time’ speech but I’ll leave that off for now.

Btw it is possible to let it only return gemotrys, but that includes modifing all models to only use one mesh internally and will break sooner or later, so dont do it that way, really.

@eraslt: I need it to check the geometry’s name. Like they do in the Hello Picking tutorial to determine which geometry was hit.

@perfecticus: Your approche works fine for me, but only if assetManager.loadModel() returns a Node. Then I can acces the geometry with the code you posted.

But this is exactly my Problem. Some of my models that are loaded with assetManager.loadModel() are returned as Geometry, some as Spatial and some as Node.
Even when I do this:

[java]
Node model = (Node) assetManager.loadModel(“Path”);
[/java]

I know now several methods to get the geometry of a model when it’s a Node or Spatial, but I am never certain of what type it is.

I hope I expressed my problem understandble…

@pspeed:
sorry I didn’t read your post. I think I need this, because I want to check which model the user clicked. To determin this I am using the code in the tutorial section. And there they use the geometry’s name.

Edit: OK I understand that it is always a Spatial, but how do I get the Geometry from a Spatial then?

@monsterbit said: @pspeed: sorry I didn't read your post. I think I need this, because I want to check which model the user clicked. To determin this I am using the code in the tutorial section. And there they use the geometry's name.

A Geometry is a Spatial. A Node is a Spatial. They all have names.

However, names are not a good way to do this… the tutorial just shows it because it’s easy.

Anyway, i you are doing picking then there is no problem. I’m not sure why you care what model was loaded at that point. You get a Geometry from the picking and from there you can trivially traverse all the way up as far as you need, checking names or whatever.

Your questions and understanding indicate that you may want to study up on Java a little bit more before jumping into the deep end of the pool that is 3D game development.

Ah ok, I understand now.

So if checking with name is not perfect, which method would be best then?

@monsterbit said: Ah ok, I understand now.

So if checking with name is not perfect, which method would be best then?

That depends on what you are going to do with the name.

<cite>@monsterbit said:</cite> @perfecticus: Your approche works fine for me, but only if assetManager.loadModel() returns a Node. Then I can acces the geometry with the code you posted.

Dont think you got my point.

You load the model as
Spatial model = am.loadModel();

Then you wrap it into the modelNode which is attached to the entity.
Then you use the modelNode to fetch the geometries you have loaded.

So essentially…

[java]
Node entity = new Node(“entity”);
Node modelNode = new Node(“modelNode”);
entity.attachChild(modelNode);

Spatial model = am.loadModel();
modelNode.attachChild(model);
[/java]

When you have that, you can use the methods I use up there to fetch whatever geometries your model consists of.

@perfecticus said: Dont think you got my point.

You load the model as
Spatial model = am.loadModel();

Then you wrap it into the modelNode which is attached to the entity.
Then you use the modelNode to fetch the geometries you have loaded.

So essentially…

[java]
Node entity = new Node(“entity”);
Node modelNode = new Node(“modelNode”);
entity.attachChild(modelNode);

Spatial model = am.loadModel();
modelNode.attachChild(model);
[/java]

When you have that, you can use the methods I use up there to fetch whatever geometries your model consists of.

…wait… you add a whole layer of transforms to the scene graph just to avoid doing instanceof?

<cite>@pspeed said:</cite> ...wait... you add a whole layer of transforms to the scene graph just to avoid doing instanceof?

No, I do it for structure, havnt seen any particular impacts of it.