Concepts to convert a high tris mesh in a low tris

Blitz3D Forums/Blitz3D Beginners Area/Concepts to convert a high tris mesh in a low tris

RemiD(Posted 2012) [#1]
Hi, :)

In my game, i use subdivided meshes for the walls of the rooms in order to have a beautiful lighting.

Each room is built with several parts of walls and then i use addmesh to have a single mesh.

An example of a high tris room :


I want to create a low tris mesh for each high tris mesh of each room so that i can use the low tris mesh as a collider.

An example of a low tris collider i want :


But i have no idea how i can code this, and i need to be able to code it because my program will generate the shape and the size of each room, and i also want it to generate a collider for each room.


If you have an idea on how to achieve this, can you explain ? Please?

Thanks,


Yasha(Posted 2012) [#2]
Can you rely on the rooms to always be arranged according to a grid? Do they have a particular maximum size? What are the general parameters for room design?

It's important when coming up with systems for simplifying something to know exactly which ways something can be simplified. For instance, in this case, if we know that rooms are always grid-aligned and grid-constricted, the task becomes ....well, doesn't look too hard, whereas doing it with arbitrarily-shaped rooms would be nightmarishly hard.

If we can assume that the rooms are built to a grid, the way I would probably do this would be:

-- start with one of the axis-aligned 'sides' to the room. This is simplest with the floor, but with a bit of splitting and tweaking to handle unconnected areas separately, could work with the walls as well.

-- assign each component quad a virtual grid location, as though you are projecting the floor over the largest square that can hold it.

-- pick a corner. Doesn't matter which one if the rooms are statistically likely to be symmetrical. Choosing one is probably more difficult than necessary; or if you're feeling generous with time, you could repeat this whole thing four times to choose the one that generates the fewest quads.

-- use a simple distance-search to find the floor-quad that is physically closest to the starting corner. Mark this floor quad; this is now your work area.

-- maintain an X-size and a Y-size measurement for your quad. For each in the X-range, check if the tiles X, Y+1 are all within the room and unclaimed. Do the same for the Y-range. Choose the side with the greater number of unclaimed tiles (the number is zero if any a claimed or outside the room), and expand the quad to cover those tiles. If neither side is available for expansion, the this quad is done.

-- go back to the search step to find the next nearest tile to the starting corner. Repeat...

-- eventually there will be no more tiles left. Every tile in the room will have been assigned to a quad. You now have enough information to build a collision mesh.


....all that said, however, you should:

1) seriously consider using collision boxes instead of a mesh, because a small group of box collisions may be significantly faster than one complex mesh collision (experiment and see which is better).

2) simplify things further for large constants like the floor: if several rooms share a floor or a single side wall, have them share one extended collision box. If all the rooms are on one flat plane, have an actual plane; even get rid of the collision element and use a simple "If Y < 0 Then Y = 0" approach.

3) consider generating the simple room mesh first, and producing the complex lighting mesh out of it, rather the the other way around; or have your procedural room-generator output both at the same time. Either of these is likely much simpler than generating a collision mesh from a rendering mesh.

There's always room for further simplification!

Last edited 2012


RemiD(Posted 2012) [#3]

Can you rely on the rooms to always be arranged according to a grid?



Yes, each wall part is a tile of 1x1 unit


Do they have a particular maximum size?



Yes, each room can measure up to 20x20 tiles (or units)


What are the general parameters for room design?



I am not sure i understand what you mean by that...
Each room can have irregular shapes as illustrated on the screenshots but each room will always use a maximum of 20x20 units and be flat.

There will be several levels linked by rooms with stairs, but otherwise, all rooms of each level will have the same flat ground


consider generating the simple room mesh first, and producing the complex lighting mesh out of it, rather the the other way around



Yeah this is an interesting idea, i can try to code something like this.


even get rid of the collision element and use a simple "If Y < 0 Then Y = 0" approach.



Well, this will probably work for a room with a flat ground but not for a room with stairs or others irregular shapes (on the Y axis)

I have not understood your others explanations yet, but i will reread later.

Thanks!

Last edited 2012


Kryzon(Posted 2012) [#4]
Those collection of tiles amount to concave polygons. The floor, the ceiling and each individual wall are polygons.

You can "see" these polygons if you ignore the tiles in the middle, and only consider the edge tiles:



Once you can extract the polygon shapes these tiles form, all you need to do is triangulate them.

http://blitzbasic.com/codearcs/codearcs.php?code=2259 - by Warpy
http://blitzbasic.com/codearcs/codearcs.php?code=2508 - by Warner
http://blitzbasic.com/codearcs/codearcs.php?code=816 - by Pepsi
http://en.nicoptere.net/?p=16


RemiD(Posted 2012) [#5]
Thanks for these explanations Kryzon, i will study it if i need it later.



I have done some tests on 3 pcs and even on my weakest config (EEE 900, Celeron 900Mhz, 1go DDR, Intel GMA 900 64mo) the collisions calculations take only 1 to 2 ms for :
->A static collider mesh of around 9000 tris. (for the walls of the room)
->50 static colliders meshes (cube, cylinder, or low tris colliders) (for the furnitures)
->10 moving colliders spheres (for the characters)

I use a routine to unset/set the colliders and the collisions groups before moving the characters, in order to calculate the collisions only on the characters in the same room of the player and on the furnitures around the characters and the player in this room.

So i think i don't need to optimize the collider mesh of the room even if it has far too many tris. Maybe later.

Last edited 2012


_PJ_(Posted 2012) [#6]
Sety some linepicks to identify where the distance from any face to the opposite one changes - This will mean there's a corner. At each corner, place a collider vertex and build up a collider mesh this way.