Sorry for asking this question, but: How can I show normals as little lines during graphical debugging? I can not find the forum post of the user who showed that feature and the according lines of code.
When I need it I usually do it by myself by generating mesh for normals based on original mesh. Not very effective but it’s for debug needs anyway. Just go though all vertices, take corresponding normal and make a new mesh with double the vertex count and lines display mode where first vertex in every pair is at position of original vertex and second one is first one plus scaled normal vector. Geometry shader approach should be more flexible but it’s out of my knowledge yet.
Unfortunately I can’t share any code as it’s usually very messy - just a bunch of debug code put together in a hurry.
//mesh is the mesh for which you wan to see tbn
Geometry debug = new Geometry("Debug normals", TangentBinormalGenerator.genTbnLines(mesh, 0.08f)
);
Material debugMat = assetManager.loadMaterial("Common/Materials/VertexColor.j3m");
debug.setMaterial(debugMat);
debug.setCullHint(Spatial.CullHint.Never);
debug.getLocalTranslation().set(translation);
rootNode.attachChild(debug);
I used this in the past to investigate my normals :
public void showNormals(Geometry geometry, ColorRGBA color) {
VertexBuffer position = geometry.getMesh().getBuffer(Type.Position);
Vector3f[] positionVertexes = BufferUtils.getVector3Array((FloatBuffer) position.getData());
VertexBuffer normal = geometry.getMesh().getBuffer(Type.Normal);
Vector3f[] normalsVectors = BufferUtils.getVector3Array((FloatBuffer) normal.getData());
for (int arrow = 0; arrow < normalsVectors.length; arrow++) {
createArrow(positionVertexes[arrow], normalsVectors[arrow] , color);
}
}
private void createArrow(Vector3f location, Vector3f direction, ColorRGBA color) {
Arrow arrow = new Arrow(direction);
Geometry g = new Geometry("arrow", arrow);
Material mat = new Material(application.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", color);
g.setMaterial(mat);
g.setLocalTranslation(location);
application.getRootNode().attachChild(g);
}
You could ofc batch the arrows for way better performances.
If you have a level editor or something, you could bind a key to toggle showing them. In my case, each geometry is displayed in the editor as a record in a table so it’s pretty easy to choose which to toggle the showing… for some reason, it got shafted during a refactoring :D.
NB: old code; maybe needs to be adapted for 3.1… no idea, haven’t tested.
Ok, thanks for that too.
The batching was the first thing I thought too.
For the whole normals debugging in general:
I don’t know yet if the normals could easily be updated for animated models.
On the other hand - who needs that feature on a regular basis?
Maybe I just deactivate normals debugging for every Spatial that has an AnimControl.
For the bounding volumes:
I found out that there is already a WireSphere and a WireBox.
Implemented that the same way I did for normals, hope it works.
+
I’ve seen there is an unused type ‘Capsule’ - I wonder,
will there be a BoundingCapsule / WireCapsule in jME 3.1?