Does anybody has already gained some experiences about picking animated models on android?
When I used the inputManager.getCursorPosition() method the results were quite disappointing.
After switching to the coordinates that I receive via onTouchEvent, the results at least came close to what i’d expect, but it’s still not really accurate.
So here’s my code:
[java]
public void onTouchEvent(int x, int y){
Vector2f cursorPosition = new Vector2f(x, y); // inputManager.getCursorPosition();
Log.d("###JME###", “Cursor position: " + cursorPosition);
Vector3f origin = cam.getWorldCoordinates(cursorPosition, 0.0f);
Vector3f direction = cam.getWorldCoordinates(cursorPosition, 0.3f);
direction.subtractLocal(origin).normalizeLocal();
Ray ray = new Ray(origin, direction);
CollisionResults results = new CollisionResults();
rootNode.collideWith(ray, results);
if (results.size() > 0) {
Log.d(”###JME###", "collisions detected: " + results.size());
}
}
@Override
public void simpleInitApp() {
BinaryImporter imp = new BinaryImporter();
imp.setAssetManager(assetManager);
try {
Node ogreModel = (Node) imp.load(activity.getResources().openRawResource(R.raw.oto), null, null);
ogreModel.setLocalTranslation(0, 60, 0); // 0, 20, 0
ogreModel.setLocalScale(.25f, .25f, .25f);
ogreModel.updateGeometricState();
ogreModel.updateModelBound();
AnimControl control = ogreModel.getControl(AnimControl.class);
AnimChannel chan = control.createChannel();
chan.setAnim(“walk”);
spheresContainer.attachChild(ogreModel);
rootNode.attachChild(spheresContainer);
} catch (NotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
[/java]
In JME2 https://wiki.jmonkeyengine.org/legacy/doku.php/jme2:picking?s[]=picking the developer has to call updateCollisionTree() but this method is not available in JME3-Android.
Yes, animated models dont update the geometry collision information. You could use the ragdoll control and the physics collision shapes of it to do per-part picking of a character.