Terrain Editor

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
lastlinkx
Posts: 7
Joined: Mon Jan 16, 2012 3:37 pm

Terrain Editor

Post by lastlinkx »

So, I've made a terrain editor to help me make my game.
Every time I apply a transformation, I set TerrainEntity.Shape.Heights[x, y] equal to the vertical position of my Vertex array.
Now I need to get the Terrain to call OnShapeChanged after updating the Heights[], but I can't find a publicly exposed way to call it.
So what I've done is just add the function TerrainEntity.Shape.RefreshShape(); which simply call OnShapeChaned() from within the Terrain shape.
Now this works wonderfully, but I'm wondering if indeed there was some method to do the equivalent without modifying Bepu - although it was only a three line modification.
-Thanks in Advance
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain Editor

Post by Norbo »

Setting the TerrainShape's Heights property to itself will force the event to occur. However, for a Terrain, that event just calls the Terrain.UpdateBoundingBox() method which is publicly exposed.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain Editor

Post by Norbo »

By the way, since the bounding box calculation is a little expensive, running it only when needed would be a good idea. For example, in an editor, it could be deferred until saving or until some simulation is needed. Another option would be to defer any recalculation until after a full brushstroke is completed (rather than doing it very each individual frame during the brushstroke).
lastlinkx
Posts: 7
Joined: Mon Jan 16, 2012 3:37 pm

Re: Terrain Editor

Post by lastlinkx »

Well, I was actually just Calling my RefreshShape function after every update to the terrain, and I still pull out a solid 60fps.

Code: Select all

void ApplyOperations(List<Operation> Operations)
        {
            for (int i = 0; i < Operations.Count; i++)
            {
                Operation op = Operations[i];
                int VertexIndex = op.VertexX + op.VertexY * Terrain.length;
                Terrain.vertices[VertexIndex].Position.Y += op.HeightTranform;
                Terrain.TerrainEntity.Shape.Heights[op.VertexX, op.VertexY] = Terrain.vertices[VertexIndex].Position.Y;
                
            }
            //Terrain.TerrainEntity.Shape.RefreshShape();
            Terrain.TerrainEntity.UpdateBoundingBox();
        }
I could, as you suggested, deffer the recalculation, but right now it doesn't seem like too much of an issue.
- Might be because I'm running an i7 2700k at 4.8 GHz :P

Thank you very much though, Bepu is great!

P.S. One more question, would there be any benefit to breaking my large terrain into smaller terrain entities?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain Editor

Post by Norbo »

P.S. One more question, would there be any benefit to breaking my large terrain into smaller terrain entities?
Not unless bounding box updates are getting too expensive. The collision detection routine for Terrains does not increase in cost with Terrain size. Splitting a Terrain into many Terrains would result in more BroadPhase pressure, harming performance. This could be fought by putting the mini-Terrains in a StaticGroup, but then you'd need to refit the StaticGroup hierarchy every time a Terrain's bounding box changes. Changes could still come out a bit faster, but it's probably not worth the effort (especially since it's already apparently fast enough! :)).
lastlinkx
Posts: 7
Joined: Mon Jan 16, 2012 3:37 pm

Re: Terrain Editor

Post by lastlinkx »

Lol, thanks :)
Here's a pic for all your help:
Image
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Terrain Editor

Post by Norbo »

Nice :)
Post Reply