0

So I am working on creating a 3D modeling toolkit in javafx. In this toolkit people will be able to load in model files and try out animations on said models.

Currently I split up each model in groups of TriangleMesh objects, where each Mesh in the group uses the same material. Then I have an AnimationTimer that sequences frames of the loaded animation and for each next frame updates all changed points in each TriangleMesh. However performing frequent updates on the points lists is reducing the performance of the program considerably.

I am wondering whether this can be optimized?

I had some ideas, for one I thought it might help to have a single TriangleMesh for each model (though this is problematic because I cannot set the material of individual faces) but this still leaves me with the overhead of updating the observable points list so frequently.

1 Answers1

1

Having lots of separate TriangleMeshes is indeed very inefficient. Why do you think you need that? If it is just different textures that you want to apply to different parts of your model then you could create a texture atlas. This would allow you to use one TriangleMesh per model and that should make things more efficient. How large the influence of your coordinate modifications is remains to be tested.

mipa
  • 10,369
  • 2
  • 16
  • 35
  • Hi, thanks for the reply. I don't really need that for the animation viewer. Though I do need it to implement listener for individual triangles in the editing part of my program. However, I could switch to a single mesh in the animation viewer. I stumbled upon this: https://stackoverflow.com/questions/47793288/javafx-3d-colouring-faces-again?noredirect=1&lq=1 Which said something similar to you, but I found the API mentioned (https://github.com/FXyz/FXyz) a bit hard to understand. This is mainly because I am not very well versed into the math nor the relevant terminology. – Stan van der Bend Sep 19 '19 at 18:17
  • would you have any advice of where to start looking how I could convert a list of colors for each triangle to a texture atlas? Though I do remember there being something like this in the FXyz library I mentioned earlier. I will have to dig into it a little more, I am not well versed in how (u, v) coords work. – Stan van der Bend Sep 19 '19 at 18:18
  • This is trivial. Just create a WritableImage, set this in your material and define a single pixel for each color. Then use the center u,v coordinate of the corresponding pixel for the texture coordinates of your triangle. I use this scheeme on a regular basis and it works great. – mipa Sep 19 '19 at 22:14
  • thanks a lot, I managed to do exactly as you said. And the performance is butter smooth, I have one more problem left. Not all colors are correct mapped on the right triangle. Currently I make a set of (unique) colors and from this create an atlas of dimensions {unique_color_size)x1 image. Then I create uv coordinates where the {color_index} divided by the {unique_color_size) to get the u coordinate and as y coordinate I put 0.5f. Which I then store in the texcoords array and the indices of which I add (3 times) to the faces list. Is the way I derive my uv coordinates correct? – Stan van der Bend Sep 20 '19 at 01:17
  • Moved this to a new question: https://stackoverflow.com/questions/58021812/colouring-individual-triangles-in-a-trianglemesh-through-texture-map-is-inaccura – Stan van der Bend Sep 20 '19 at 04:35