I’m wondering about something, I have a simple idea: implement mesh smoothing in Jmonkey. Now this shouldn’t be too hard, however I’m wondering if its any usefull. I was thinking it might be handy for beautifying low poly models (low downloadsize!) and ultimately a cool automatic lod system. Especially the latter I’m interested in: would this take up lots of resources? I guesst it will (thats why its mostly used on terrain right?) but comments are appreciated.
The function would work like this:
subdivision
Gaussian blur
If itll be a nice feature, I’ll try to create it the coming days.
Sounds like a nice idea… Though one would generate that data not “live” in the application but rather before, e.g. using a model importer / jMP plugin or similar. The terrain system does live LOD because in the future it will support “endless” terrain that might be procedurally generated, thus you cannot prepare the data in advance.
Why would one not be able to do this live? Would this be too heavy? Or because one cannot create/edit models in JME on the fly :s ? I see no other roadblocks…
Also, this very feature is usually implemented in a geometry shader. The low poly mesh data is sent to the geometry shader, that just tessellate the model on the GPU side.
But for now jME3 does not support geometry shaders.
Doing it on the cpu might be doable, but i guess, the issue would be the memory used to store the new vertices…
Also I don’t know if it would be fast enough to consider “on the fly” tessellation. Which would make this feature not worth the effort. (better pre compute lod levels).
But that just thoughts, i did not actually tried it so maybe i’m wrong. You seem motivated by this feature so why not give it a try?
Geometry shaders have limited use. Smoothing models doesn’t exactly make sense …
Hardware tessellation is a completely different feature from geometry shaders and requires your meshes to have a completely different data format, one which none of our current importers support.
Momoko_Fan said:
Smoothing models doesn't exactly make sense ...
I think its more efficient than mesh decimation, making automatic Lod using smoothing. Plus, high quality models can only go so far, untill you run out of memory right?
I guess you can call it regressive mesh? Dunno.
kajos said:
I think its more efficient than mesh decimation, making automatic Lod using smoothing. Plus, high quality models can only go so far, untill you run out of memory right?
I guess you can call it regressive mesh? Dunno.
Yeah, its not called regressive mesh… Tesselation is supported by opengl 4 on the gpu, however its apparently not uncommon to do it on the cpu, if I may believe wikipedia…
I’m trying to add it right now, using the Lodcalculator, however adding opengl support (gpu) is another thing (but jme wouldnt be in the way I assume).
EDIT: Using the LodCalculator is wrong I know, will replace that later.
Okay, so now I have the most pretty much worked out I think, but I’m getting index out of bound errors. Now I’m thinking this is because the way I do it now is, looping through all the indices < mesh.getVertexCount(), then looping through the indexbuffer to find a threesome with the vertex in it, if so I have found two neighbors. Then I try to get the positions of the vertices to do the calculation for the smoothing. The gatheringof the positions of the vertices is probably wrong in my code:
Ok, so I changed the code a little. Instead of vertexcount Im using indexbuffersize / 3 and some other stuff. Maybe you would be so kind to take a look at the code I have now?
EDIT: So I’m still getting an out of bounds exception at the first floatbuffer.
EDIT: The error was → mesh.getIndexBuffer().get((k+g))+1) etc…
This is the function to smooth right now:
pre type="java" public static Mesh smoothedMesh(Mesh mesh) {
long start = System.currentTimeMillis();
double sigma = 3;
Mesh smoothedMesh = mesh.clone();
for (int v = 0; v < mesh.getIndexBuffer().size()/3; v++) {
double totalWeight = 0;
// find neighbors with index key
double[] weights = new double[mesh.getIndexBuffer().size()];
for (int k = 0; k < mesh.getIndexBuffer().size(); k+:3) {
Okay, so I now some weak result with recreating the mesh looping through all the indices and stuff, however I cant get all indices to be added or ill run into a out of bounds exception:
pre type="java"
public static Mesh smoothedMesh(Mesh mesh) {
long start = System.currentTimeMillis();
double sigma = .003;
Mesh smoothedMesh = mesh.clone();
// mesh.getIndexBuffer().size() to mesh.vertexcount to display mesh else, out of bounds at floatbuffer put!!!111111
for (int v = 0; v < mesh.getIndexBuffer().size(); v++) {
double totalWeight = 0;
double[] weights = new double[mesh.getIndexBuffer().size()];
for (int k = 0; k < mesh.getIndexBuffer().size(); k+:3) {