| 65 | } |
| 66 | |
| 67 | bool SceneCSGData::TryGetSurfaceData(const Guid& brushId, int32 brushSurfaceIndex, SurfaceData& outData) |
| 68 | { |
| 69 | if (Data == nullptr || !Data->IsLoaded() || Data->Data.IsEmpty()) |
| 70 | { |
| 71 | // Missing data or not loaded |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | MemoryReadStream stream(Data->Data); |
| 76 | |
| 77 | // Check if has missing cache |
| 78 | if (DataBrushLocations.IsEmpty()) |
| 79 | { |
| 80 | int32 version; |
| 81 | stream.ReadInt32(&version); |
| 82 | if (version == 1) |
| 83 | { |
| 84 | int32 brushesCount; |
| 85 | stream.ReadInt32(&brushesCount); |
| 86 | if (brushesCount < 0) |
| 87 | { |
| 88 | // Invalid data |
| 89 | return false; |
| 90 | } |
| 91 | DataBrushLocations.EnsureCapacity(brushesCount); |
| 92 | for (int32 i = 0; i < brushesCount; i++) |
| 93 | { |
| 94 | Guid id; |
| 95 | int32 pos; |
| 96 | stream.Read(id); |
| 97 | stream.ReadInt32(&pos); |
| 98 | DataBrushLocations.Add(id, pos); |
| 99 | } |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | // Unknown version |
| 104 | LOG(Warning, "Unknwon version for scene CSG surface data (or corrupted file)."); |
| 105 | return false; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // Find brush data |
| 110 | int32 brushLocation; |
| 111 | if (!DataBrushLocations.TryGet(brushId, brushLocation)) |
| 112 | { |
| 113 | // Brush not found |
| 114 | return false; |
| 115 | } |
| 116 | |
| 117 | stream.SetPosition(brushLocation); |
| 118 | |
| 119 | // Skip leading surfaces data |
| 120 | int32 trianglesCount; |
| 121 | while (brushSurfaceIndex-- > 0) |
| 122 | { |
| 123 | stream.ReadInt32(&trianglesCount); |
| 124 | if (trianglesCount < 0 || trianglesCount > 100) |