Raycasting/picking problem

Hello, jmonkeys!

So, I’m trying to figure out, how to use picking code provided in tutorials with my own loaded models, but it doesn’t seem to work for me. Have any ideas?

Model loading code:

public void loadModel(AssetManager assetManager){
model = assetManager.loadModel(/“zuus_model.dmx.mesh.xml”/modelPath);

	Material material = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
	material.setBoolean("UseMaterialColors", true);
	material.setColor("Ambient", ColorRGBA.Blue);
	material.setColor("Diffuse", ColorRGBA.Blue);
	material.setColor("Specular", ColorRGBA.White);
	material.setFloat("Shininess", 12);


 public Spatial getModel(boolean copy) {
	if (getAssetManager() == null)
		throw new IllegalStateException("Asset manager is not defined");
	if (model == null)
	if (copy)
		return model.clone(false);
	return model;


The model itself loads and works just fine, by the way, is the ‘clone’ method is a proper way to render same model with different translations/rotations/animations?
Also I experience some wrong culling, at some camera angles, if model is very close to the edge of the screen, it doesn’t get rendered at all.

Ok, there’s my picking code:

List unitSpatials = battlePainter.getUnitSpatials();
for(UnitSpatial unitSpatial: unitSpatials){
int am = unitSpatial.getNode().collideWith(ray, results);
if (results.size() != 0){
return unitSpatial.getUnit().getPosition();

The node returned by unitSpatial.getNode() actually contains my loaded model. I’ve tried to use loaded spatial directly, but that also doesn’t seem to work, and shows some weird results.
Also, this picking code freezes the game for a second at the time of first use.
And there’s no mistake in getting cursor position model or something like this, the method above works fine with quads generated ‘on the fly’.

So, any ideas? Or maybe it’s a model issue?

Okay I’ve just tried this code with default jmonkey boxes. And it works perfectly. So how do I fix it for my model?

Okay, so I’ve accidentally found that picking works fine. But not with the animated models. It doesn’t take animations into an account.
So, the problem is in the initial pose of the character model

As you can see he is lying, so the bounding box is calculated for that pose.
Can I do something with this without changing the model?

Your animation should not change the location of your model.
Bounds are not recomputed according to the animation.
You can call geometry.updateBounds (or something like that ) manually once the animation is done though.

nehon, well it doesn’t change the location, just the rotation of the model. So you say calling updateBounds takes current animation pose into an account? Thanks, I’ll take a look into that.

Also, could you please answer my second question from the first post?

by the way, is the ‘clone’ method is a proper way to render same model with different translations/rotations/animations?

you can just load it again like assetManager.loadModel (), it will create a new instance for you. If its animated, it will create all new buffers, if its static, it will reuse the same mesh, but create a new material for you.