| 2257 | #if TERRAIN_USE_PHYSICS_DEBUG |
| 2258 | |
| 2259 | void TerrainPatch::CacheDebugLines() |
| 2260 | { |
| 2261 | PROFILE_CPU(); |
| 2262 | PROFILE_MEM(LevelTerrain); |
| 2263 | ASSERT(_physicsHeightField); |
| 2264 | _debugLinesDirty = false; |
| 2265 | if (!_debugLines) |
| 2266 | _debugLines = GPUDevice::Instance->CreateBuffer(TEXT("Terrain.DebugLines")); |
| 2267 | |
| 2268 | int32 rows, cols; |
| 2269 | PhysicsBackend::GetHeightFieldSize(_physicsHeightField, rows, cols); |
| 2270 | const int32 count = (rows - 1) * (cols - 1) * 6 + (cols + rows - 2) * 2; |
| 2271 | typedef DebugDraw::Vertex Vertex; |
| 2272 | if (_debugLines->GetElementsCount() != count) |
| 2273 | { |
| 2274 | if (_debugLines->Init(GPUBufferDescription::Vertex(Vertex::GetLayout(), sizeof(Vertex), count))) |
| 2275 | return; |
| 2276 | } |
| 2277 | Array<Vertex> debugLines; |
| 2278 | debugLines.Resize(count); |
| 2279 | auto* data = debugLines.Get(); |
| 2280 | const Color32 color(Color::GreenYellow * 0.8f); |
| 2281 | |
| 2282 | #define GET_VERTEX(x, y) const Vertex v##x##y = { Float3((float)(row + (x)), PhysicsBackend::GetHeightFieldHeight(_physicsHeightField, row + (x), col + (y)) / TERRAIN_PATCH_COLLISION_QUANTIZATION, (float)(col + (y))), color } |
| 2283 | |
| 2284 | for (int32 row = 0; row < rows - 1; row++) |
| 2285 | { |
| 2286 | for (int32 col = 0; col < cols - 1; col++) |
| 2287 | { |
| 2288 | // Skip holes |
| 2289 | const auto sample = PhysicsBackend::GetHeightFieldSample(_physicsHeightField, row, col); |
| 2290 | if (sample.MaterialIndex0 == (uint8)PhysicsBackend::HeightFieldMaterial::Hole) |
| 2291 | { |
| 2292 | for (int32 i = 0; i < 6; i++) |
| 2293 | *data++ = Vertex { Float3::Zero, Color32::Black }; |
| 2294 | continue; |
| 2295 | } |
| 2296 | |
| 2297 | GET_VERTEX(0, 0); |
| 2298 | GET_VERTEX(0, 1); |
| 2299 | GET_VERTEX(1, 0); |
| 2300 | GET_VERTEX(1, 1); |
| 2301 | |
| 2302 | *data++ = v00; |
| 2303 | *data++ = v01; |
| 2304 | |
| 2305 | *data++ = v00; |
| 2306 | *data++ = v10; |
| 2307 | |
| 2308 | *data++ = v00; |
| 2309 | *data++ = v11; |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | for (int32 row = 0; row < rows - 1; row++) |
| 2314 | { |
| 2315 | const int32 col = cols - 1; |
| 2316 | GET_VERTEX(0, 0); |