Page 1 of 1
Terrain Editor
Posted: Thu Jun 21, 2012 3:49 pm
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
Re: Terrain Editor
Posted: Thu Jun 21, 2012 4:02 pm
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.
Re: Terrain Editor
Posted: Thu Jun 21, 2012 4:05 pm
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).
Re: Terrain Editor
Posted: Thu Jun 21, 2012 4:16 pm
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
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?
Re: Terrain Editor
Posted: Thu Jun 21, 2012 4:28 pm
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!

).
Re: Terrain Editor
Posted: Thu Jun 21, 2012 4:52 pm
by lastlinkx
Lol, thanks

Here's a pic for all your help:

Re: Terrain Editor
Posted: Thu Jun 21, 2012 4:55 pm
by Norbo
Nice
