Page 1 of 1

Unity3D Heightmap

Posted: Tue Sep 01, 2015 3:38 am
by absentmaverick
Are the Unity3D terrain and the BEPUPhysics terrain the same?

Re: Unity3D Heightmap

Posted: Tue Sep 01, 2015 4:04 pm
by Norbo
It depends on what details you're comparing, probably. On the other hand, I don't know anything about unity's terrain, so I'm guessing they're not the same :)

If you have a specific question about the nature of the BEPUphysics terrain, I could be of more help.

Re: Unity3D Heightmap

Posted: Tue Sep 01, 2015 5:41 pm
by absentmaverick
If I want to create an authoritative server that simulates a Unity game world, can I use the BEPU terrain class to mirror Unity's terrain class?

Re: Unity3D Heightmap

Posted: Tue Sep 01, 2015 6:39 pm
by Norbo
Maybe or even probably, but I don't know for sure. If unity's representation is a grid-based heightfield with two triangles per quad with uniform layout, it should be possible to line things up with little effort. If it's a more complicated representation, it could be more difficult. In the worst case, a custom triangle organization could be created for the BEPUphysics Terrain (this would require source changes).

Re: Unity3D Heightmap

Posted: Tue Sep 01, 2015 8:08 pm
by absentmaverick
How would I go about doing that?

Re: Unity3D Heightmap

Posted: Tue Sep 01, 2015 8:23 pm
by Norbo
First, you'd have to look into Unity's terrain representation to figure out what it's actually doing. Hopefully it's very similar and you won't have to do anything at all, and it would be as simple as the TerrainDemo in the BEPUphysicsDemos.

If you end up needing to make modifications, then main function that needs to be changed is TerrainShape.GetOverlaps. This selects a region of the grid using a bounding box and adds all triangles indices inhabiting the overlapped cells to a list. Depending on the changes made there, the TerrainShape.GetLocalIndices function will need to be updated as well to map between triangle index and vertex indices. Some secondary systems like CCD rely on TerrainShape.GetTriangle, too.