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?
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.
<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.