Entity:PhysicsFromMesh Question for Mass terrain generation

I have been working on a gmod minecraft type gamemode. So far i have blocks rendering at extreamly high speeds using Meshes to draw them as triangles. In my last test I was able to render 204800 blocks at 40 FPS.

My problem is when trying to use entity:PhysicsFromMesh to create a physics mesh for the chunks it causes gmod to crash instantly. Can anyone give me a description of how to use PhysicsFromMesh or an alternate method for my physics simulation. Are there any other ways of possibly adding physics planes or setting up entity physics? (Or maybe even physics without an entity)

when I get home ill post some screen shots so you guys can see what I have done so far. I plan to make this a public release right now.

http://cloud-2.steampowered.com/ugc/885234237011294523/63BC3443A9AD664E3AEDF963F2E4F9F1607F4B9C/

A new screen shot of the progress I have made on it, though im still waiting on a solution to the physics problem.

[SPOILER]

http://cloud-2.steampowered.com/ugc/885234237023380936/7429F5F5993BC7DB14898F374507742337E59951/

To give a better idea of the scale of what i’m working with here:

I’ve tried doing something very similar and ended up with the same problem “when trying to use entity:PhysicsFromMesh to create a physics mesh for the chunks it causes gmod to crash instantly.”

I second this request

I found something that talks about EnablingCustomCollisions and disabling motion on the entity which worked with smaller structures but continues to cause crashes with my generated terrain meshes. Does anyone know if having triangles possibly intersect one another is a problem for such meshes?

For gmDoom Maps, I used Entity:PhysicsInitMultiConvex() to create the collision hulls for the maps. To use it, you have to pass the function an array of convexes. A convex can be defined as an array of Vectors. The resulting collision hull of a convex is a shape that tightly “wraps around” the points in the array. So, to create a convex for a cube, you simply need to create an array containing the vertices of that cube.

There are a few quirks with custom physics meshes. I’ve only gotten them to work properly after calling Entity:PhysicsInit() with a valid model. For prediction, you will have to create the collision hull client-side as well. The only crashes I experienced happened when the points didn’t form a 3d shape, or when the entity was created (or moved) outside of the map.

Just to confirm, it would then also be possible to pass this algorithm multiple “convexes” defining multiple cubes into a single mesh? Also can this accept a plane (4 pts rather than 8) to save memory?

Thanks for the help with this :slight_smile: I imagine there are very few people in the community who are actually able to answer this so its much appreciated, and your GM Doom module looks amazing. I hope that, with more work done in the field of dynamic map generation, we will be able to see more ability to create new and dynamic content.

Just to clarify, gmDoom is an addon made by Ghor, and gmDoom Maps is my addon.

Entity:PhysicsInitMultiConvex() uses an array of convexes, so you can use one entity and have multiple convexes (in your case, cubes). If you only need 1 convex for an entity, you would use Entity:PhysicsInitConvex() instead.

I’m pretty sure that using 4 co-planar points will crash the game.

Now that I have finished multiplayer support I finally was able to turn my attention to physics but have been unable to figure out how ent:PhysicsInitMultiConvex() works. are the points local to the entity or global positions? How is the vertex table ordered?

The most helpful thing would be a rather simple example that creates an entity with the physics hull of two cubes or something along those lines.

Here’s a snippet of code from my addon that creates a single convex for a wall in Doom.



local convex = {}
convex[1] = Vector(v1.x, v1.y, wall.top)
convex[2] = Vector(v1.x, v1.y, wall.bottom)
convex[3] = Vector(v2.x, v2.y, wall.top)
convex[4] = Vector(v2.x, v2.y, wall.bottom)
-- convex needs to be a 3d shape, so find the midpoint and subtract normal
convex[5] = Vector((v1.x + v2.x)/2, (v1.y + v2.y)/2, wall.top) - wall.normal*4
convex[6] = Vector(convex[5].x, convex[5].y, wall.bottom)
local target = wall.top_pegged and self.CeilPhys or self.FloorPhys
table.insert(target[thissector.id], convex)


The points don’t have to be in any particular order. This convex gets stored in an array, the points are eventually converted to local coordinates, and that array gets passed to Entity:PhysicsInitMultiConvex().

Since my last post, I’ve discovered that Entity:PhysicsInitMultiConvex() appears to have a limit of around 256 convexes. Any more will crash vphysics.