I’m having some trouble troubleshooting why the FPS drops when a specific location of a large mesh is shown on screen.
So in the past I had 2 meshes, around 6 million vertices in total but realised I was using wrong calculations to position said vertices so I have switched methods of calculating the Cartesian coordinates. Back then I wasn’t getting lots of FPS and some areas in particular (high vertex density ones) obviously gave lower FPS which was understandable.
Cut to present day - I am testing everything with one mesh that has around 2.6 million vertices and one area in particular (the centre coordinates at 0,0,0) massively drops FPS for no reason. I can have 50% of vertices shown on screen right in front of my eyes and have reasonable FPS but as soon as I move the camera to look at the centre coordinates where only 1%-5% of the vertices are located - the FPS drops.
Now I’ve changed the data files to have only 100k entries (100k vertices to be created) and noticed something which I can’t seem to grasp. If when creating the mesh I define that the number of vertices this mesh will have is 100,000 everything is fine. If I leave the original value (2.6 million) from testing previous data but still only draw 100 thousand vertices on screen - same thing - FPS drop at centre coordinates.
I’ll upload a couple of pictures for you to better understand the issue I’m facing.
Bare in mind that the answer “you have too many vertices on screen” shouldn’t be the case here because before I had 6 million vertices and it was fine.
This is how I’m creating the mesh:
Calling constructor from a state:
galaxyUniverse = new UniverseMesh(rootNode, assetManager, 100000);
If I replace the 100000 by let’s say 1million and initialise only 100k vertices - centre still causes lag, if I leave it at 100k and initialise 100k vertices then everything is alright. I need at least 2.6 million vertices like it was before.
Constructor itself:
public UniverseMesh(Node rootNode, AssetManager assetManager, int objectSize){
rNod = rootNode;
aMan = assetManager;
vertices = new Vector3f[objectSize];
}
Adding Vertices:
public void AddVertex(double cx, double cy, double cz, double redshift){
float x = (float) (getDistance(redshift) * cx), y = (float) (getDistance(redshift) * cy), z = (float) (getDistance(redshift) * cz);
vertices[vertexCount] = new Vector3f(x,y,z);
vertexCount++;
}
I understand I’m calling getDistance 3 times, I know, all of this is beta, please don’t be mean on stuff like that.
Actually creating the mesh after all the vertices have been set:
public void createMesh(ColorRGBA color){
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.updateBound();
geom = new Geometry("OurMesh", mesh);
mesh.setMode(Mesh.Mode.Points);
mesh.updateBound();
mesh.setStatic();
Material mat = new Material(aMan, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", color);
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
geom.setMaterial(mat);
rNod.attachChild(geom);
}