How to update points of TriangleMesh more efficiently? - java

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.

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.

Related

How to add octree support in JBullet

I am making a voxel-based game where large structures made of voxels can collide with each other. The game runs smoothly until two structures get to close to each other where it quickly drops to about 3 updates/second.
My current solution to adding these colliders to JBullet is by using a compound shape and using a greedy-meshing algorithm to make larger colliders out of adjacent blocks. While this is a drastic improvement over each voxel having its own collider, it still isn't fast enough to simulate large structures colliding.
I did a bunch of research and it seems that octrees are the only way to make this run in real time, but can't figure out how to add support for them in JBullet.

How to reduce time to render large surface data in OpenGL

I am currently working on a project that renders large oil-wells and sub-surface data on to the android tablet using OpenGL ES 2.0.
The data comes in from a restful call made by the client (Tablet) to the server. I need to render two types of data. One being a set of vertices where I just join all the vertices (Well rendering) and the other is the subsurface rendering where each surface has huge triangle-data associated with them.
I was able to reduce the size of the well by approximating the next point and constructing the data that is to be sent to the client. But this cannot be done to the surface data as each and every triangle is important to get the triangles joined and form the surface.
I would appreciate if you guys suggest an approach to either reduce the data from the server or to reduce the time taken to render such a huge data effectively.
the way you can handle such complex mesh really depends on the scope of your project. Unfortunately there is no much we can say based on the provided inputs and the activity itself is not an easy task.
Usually when the mesh is very complex a typical approach to make the rendering process fast is to adopt dynamic Level Of Details (in programming terminology LOD).
The idea is to render "distant" meshes with a very low LOD (and therefore having a much lower number of vertices to be rendered) and there replace the mesh with an higher resolution every time the camera approaches the mesh's details.
This is a technique very used in computer games, for instance when a terrain needs to be rendered. When the player is in a particular sector of the MAP, the mesh of that sector is in High level of detail, the others are in low detail. As soon as the player moves, the different sectors become in "high resolution" (allow me the term).
It is not an easy way to do it but it works in many many situations.
In this gamasutra article, there are plenty of information on how this technique works:
http://www.gamasutra.com/view/feature/131596/realtime_dynamic_level_of_detail_.php?print=1
The idea, in your case, would be to take the mesh provided by the web service and handle it as the HD version of the mesh. Then (particularly if the mesh is composed by different objects), apply a triangular mesh simplification algorithm to create LD meshes of the same objects. An example on the way you could proceed is well described here:
http://herakles.zcu.cz/~skala/PUBL/PUBL_2002/2002_Mesh-Simplification-ICCS2002.pdf
I hope to have helped in some way.
Cheers
Maurizio

Where to start with voxel engine?

I have been working on a voxel game for some time now, but all that I have really accomplished was the main menu and an Item system. Now its time to make the voxel engine. I have been searching for a while now to find some tutorials or an ebook that will teach me such, but the best i could find were someones tutorials in c++, but I am making mine in Java. I have dabbled in c++ and c# in the past but it was too difficult to translate i.e. it relied on a class that java doesn't have. What I know is that there are different methods for voxel engines, they all begin with rendering a single cube, and Perlin and Simplex noise can be used to randomize terrain generation.
If anyone could point me in the correct direction, most appreciated.
I will be checking back at least once a hour incase someone feels this thread is dead.
I'm not entirely sure what you are asking, if you are asking how to make simplex noise, implement it in a voxel engine or how to start making a voxel engine.
If you are asking how to start making a voxel engine I would recommend practising with quads first (2D version) and focus on getting an understanding for the theory. Once you are happy with your understanding you should focus on the voxel class (one cube) - it is very important to learn as much as you can from it, and then add more so you can optimize rendering as much as you can, such that hidden faces are not rendered and even vertices are shared, voxel engines can be the most wasteful renderers if not optimized!
EDIT:
Optimization can be done through many methods, The first and most important is hidden face removal, this involves removing the faces of voxels that are touching which will mean you will need to check of a voxel exists on any given side of any voxel before rendering that face (e.g before rendering the left face, check if there isn't a block to the left). Next is the rendering method, do not render each face or each group individually, group them so they can be rendered faster, this can be done by using display-lists or the more technical VBOs, these ensure the data is in the GPU or the data can be given to the GPU faster, For example Minecraft groups them in chunks of huge 16x16x128 groups and uses display lists. If you really want to reduce every single vertex in memory you can also consider using strip drawing methods (in OpenGL), these will require you to define certain vertices at a certain time in rendering but allow you to reuse a vertex for multiple faces.
Next would be understanding simplex noise, I can relate to there not being much material online for noise generation algorithms, unfortunately I cannot link material that I used as that was years ago. You can implement your noise algorithm in the 2D version to prove it works in a simpler environment and then copy it to the voxel version. Typical usage would be to use the values as heights in the terrain (e.g white=255 = 255 high).
I would recommend using Unity. The engine is already made and you can add menus and titles with just a few lines of code. All of the game creation is either in C# or Javascript which shouldn't be any huge change from C++. Good luck!

Java game development. Making a tile-map faster. Advices on optimisations

I'm trying to make a fully-automated game engine which needs to be working based on the events. The problem I'm facing is that I've made a map class and it's initialized in the game class. It's almost static and only one map exists for a game. New maps are loaded by clearing the objects in the current map and adding new maps. You can see the source of the map class here.
http://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/map/Map.java
The main problems comes in the collision detection, where I'm using the brute-force collision detection where I should not. This slows down the game a lot and I wanna check the collisions only for objects which are nearer to the object. I've been using the MapLoader interface to construct the maps. I'm thinking that calling the collision() method of the objects in another thread might help. How-ever it all the map objects are updated in the Game class.
Here's the game class if in case it might help
http://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/core/Game.java
There's another problem that some-times, the objects aren't destroyed. I'm calling the map's removeObject() method but it takes a 1-second delay and some times wont remove at-all.
It gives me 48-64 fps in a platform game with 158 objects in the game. But in a space-invaders style game, it gives me only 20-30 fps. Any advice on optimization is greatly appreciated...
If anybody could get me a tutorial for binary spacing etc., I would be thankful.
Two suggestions by looking at your code: first thing is that you should try to minimize object allocation in collision detection, don't create new Rectangles, work on data you already have by writing directly the collision detection algorithm.
Second an more important thing: a collision detection engine should work by using two levels:
a coarse level of collision already excludes objects that are surely too far to collide (you can use many techniques here, like a binary spatial partition algorithm of big colliding blobs, or hierarchical structure of objects)
a fine level which will compute specific details for the collision that can occur, with more precise algorithms

Scraping data from Flash (Games)

I saw this video, and I am really curious how it was performed. Does anyone have any ideas? My intuition is that he scraped pixels from the screen (one per 'box'), and then fed that into some program to determine the next move.
Is scraping pixel-by-pixel the way to do this, or is there a better way? I am looking to do something similar with either Java or Python.
Thanks
Probably that's the most reliable way. There are ways to inspect what is happening inside a process - looking directly at its internal state and memory - but they are platform-specific and very prone to misbehaving because your dealing with a slightly different version of something - that includes a different flash version as well as a different version of the app. Those methods are more often used for "trainers" for exe games, where there's typically only one or two versions of the executable to worry about.
Lots of screen shots, comparing, figuring out reliable indicator pixels seems the way to go - plus keeping track of what you expect to happen, of course. When the app is running, it should work from a screenshot at a time (hopefully ensuring a consistent picture, with no half-updated views) and then test the minimum number of pixels needed using (perhaps) a decision tree.
There are ways to automate construction of efficient decision trees, but it's probably easier to do it manually based on comparing screen shots. In this case, since Tetris normally creates all new pieces at the same position, with a 1:1 relationship between colour and shape, you can probably determine the shape and position of a new piece from a single pixel colour - so "decision tree" is probably the wrong term, really, in this case - though there are other things the bot needs to read from the screen.
What's more interesting is the logic to actually make gameplay decisions, since that bot clearly isn't just slotting every piece into the most immediately obvious position, but deliberately aiming to create opportunities to clear 3 or 4 rows at a time.
Yes, i think he scanned the pixels. Actually it should be very simple because you only need to scan the new shape for each move. With that information you can locally calculate the grid and further use it for your AI calculations.

Categories