This is a noob question: how do I make a model perpendicular to the terrain? I am creating a world editor, where I can choose a model that follows my mouse. Now I tried to use lookAt() using the contactNormal() (from raycasting), mult quaternions with contact points, but with no results.

Ah. the problem that you have is that lookAt() is to make the “Z” axis of the tree look at the terrain.

You have two easy solutions:

Rotate the tree model mesh so that the Z axis is parallel to the tree, not the Y axis (rotate 90 degrees on X axis).

make the tree a child of an empty node that has the Z axis parallel to the tree (rotate the tree spatial locally 90 degrees on X) and use the look at on the empty node.

you also need the negative contact normal, or you can rotate -90 degrees instead.

A Quaternion is a rotation… but so is a 3x3 matrix… and a 3x3 matrix is nicely the three orthogonal vectors representing the rotated coordinate axes x, y, and z. So if you can find those then you can make a rotation.

You already have up:
Vector3f up = contactNormal;

Now you just need the other two:
Vectof3f temp = tree.getLocalRotation().mult(Vector3f.Z); // forward rotation in its current view
Vector3f left = up.cross(temp); // should be left axis
Vector3f forward = left.cross(up);

Quaternion newRotation = new Quaternion().fromAxes(left, up, forward);

Edit: there is always the chance that I got the cross products backwards… if you see strange results then try printing the values.