[SOLVED] Viewing frustum

I fixed it, but there is probably a bug in the constructor of the WireFrustum class.
To understand where I was placing the camera’s visual cone, I attached the geometry to a node and saved it as a .j3o file. If I build the Mesh with the constructor new WireFrustum(points), when I open the .j3o file in the Editor I get the following error message:

binary-frustum

If I use the static method WireFrustum.makeFrustum(points) to build the Mesh of the cone, everything works.

This code does not work:

public static Node createCameraFrustum(Camera cam) {
            
	Vector3f[] points = new Vector3f[8];
	for (int i = 0; i < 8; i++) {
		points[i] = new Vector3f();
	}
	
	Camera frustumCam = cam.clone();
	ShadowUtil.updateFrustumPoints2(frustumCam, points);
	WireFrustum mesh = new WireFrustum(points); /** error */
	
	Geometry frustumGeo = new Geometry("Viewing.Frustum", mesh);
	Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
	mat.setColor("Color", ColorRGBA.White);
	frustumGeo.setMaterial(mat);
	frustumGeo.setCullHint(Spatial.CullHint.Never);
	frustumGeo.setShadowMode(RenderQueue.ShadowMode.Off);
	
	Node node = new Node("WireFrustum");
	node.attachChild(frustumGeo);
        
	/**
	 * Save a Node to a .j3o file.
	 */
	String userHome = System.getProperty("user.dir");
	BinaryExporter exporter = BinaryExporter.getInstance();
	File file = new File(userHome + "/assets/Models/wire-frustum.j3o");
	try {
		System.out.println(file.getAbsolutePath());
		exporter.save(node, file);
		
	} catch (IOException ex) {
		System.err.println("Failed to save node!");
		ex.printStackTrace();
	}
	
	return node;
}

This code works:

public static Node createCameraFrustum(Camera cam) {
            
	Vector3f[] points = new Vector3f[8];
	for (int i = 0; i < 8; i++) {
		points[i] = new Vector3f();
	}
	
	Camera frustumCam = cam.clone();
	ShadowUtil.updateFrustumPoints2(frustumCam, points);
	Mesh mesh = WireFrustum.makeFrustum(points); /** works */
	
	Geometry frustumGeo = new Geometry("Viewing.Frustum", mesh);
	Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
	mat.setColor("Color", ColorRGBA.White);
	frustumGeo.setMaterial(mat);
	frustumGeo.setCullHint(Spatial.CullHint.Never);
	frustumGeo.setShadowMode(RenderQueue.ShadowMode.Off);
	
	Node node = new Node("WireFrustum");
	node.attachChild(frustumGeo);
        
	/**
	 * Save a Node to a .j3o file.
	 */
	String userHome = System.getProperty("user.dir");
	BinaryExporter exporter = BinaryExporter.getInstance();
	File file = new File(userHome + "/assets/Models/wire-frustum.j3o");
	try {
		System.out.println(file.getAbsolutePath());
		exporter.save(node, file);
		
	} catch (IOException ex) {
		System.err.println("Failed to save node!");
		ex.printStackTrace();
	}
	
	return node;
}

After several attempts, I found the right code to center the origin of the visual cone in the origin of the axes and to orient it correctly with the z axis. (see figure):

camera-scenegraph