As topic.
You can still get at the normal by getting the triangle of the collision and get the normal of that, but the more direct method of getting the contact normal seems to always return null.
Crude sample test below:
package com.flah.playground;
import com.jme3.app.SimpleApplication;
import com.jme3.collision.CollisionResult;
import com.jme3.collision.CollisionResults;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Ray;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
public class RayNormal extends SimpleApplication {
private CollisionResult cr;
private CollisionResults results;
private Ray pewPew;
@Override
public void simpleInitApp() {
Box b = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry g = new Geometry("OrangeBox", b);
Material m = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
m.setColor("m_Color", ColorRGBA.Orange);
g.setMaterial(m);
rootNode.attachChild(g);
pewPew = new Ray(new Vector3f(-5, 0, 0), Vector3f.UNIT_X);
results = new CollisionResults();
rootNode.updateGeometricState();
}
@Override
public void simpleUpdate(float tpf) {
super.simpleUpdate(tpf);
results.clear();
rootNode.collideWith(pewPew, results);
cr = results.getClosestCollision();
System.out.println("Number of Collisions(2): " + results.size());
System.out.println("Name of Object: " + cr.getGeometry().getName());
System.out.println("Normal of Closest Collision: " + cr.getContactNormal());
System.out.println("Normal of Triangle: " + cr.getTriangle(null).getNormal());
}
public static void main(String[] args) {
RayNormal app = new RayNormal();
app.start();
}
}