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:
[java]
public void loadModel(AssetManager assetManager){
model = assetManager.loadModel(/“zuus_model.dmx.mesh.xml”/modelPath);
model.setLocalScale(0.03f);
model.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
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);
model.setMaterial(material);
}
public Spatial getModel(boolean copy) {
if (getAssetManager() == null)
throw new IllegalStateException("Asset manager is not defined");
if (model == null)
loadModel(getAssetManager());
if (copy)
return model.clone(false);
return model;
}
[/java]
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:
[java]
List unitSpatials = battlePainter.getUnitSpatials();
for(UnitSpatial unitSpatial: unitSpatials){
int am = unitSpatial.getNode().collideWith(ray, results);
if (results.size() != 0){
return unitSpatial.getUnit().getPosition();
}
}
[/java]
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?