| 215 | } |
| 216 | |
| 217 | bool Model::Init(const Span<int32>& meshesCountPerLod) |
| 218 | { |
| 219 | if (meshesCountPerLod.IsInvalid() || meshesCountPerLod.Length() > MODEL_MAX_LODS) |
| 220 | { |
| 221 | Log::ArgumentOutOfRangeException(); |
| 222 | return true; |
| 223 | } |
| 224 | PROFILE_MEM(GraphicsMeshes); |
| 225 | |
| 226 | // Dispose previous data and disable streaming (will start data uploading tasks manually) |
| 227 | StopStreaming(); |
| 228 | |
| 229 | // Setup |
| 230 | MaterialSlots.Resize(1); |
| 231 | MinScreenSize = 0.0f; |
| 232 | SAFE_DELETE_GPU_RESOURCE(SDF.Texture); |
| 233 | |
| 234 | // Setup LODs |
| 235 | LODs.Resize(meshesCountPerLod.Length()); |
| 236 | _initialized = true; |
| 237 | |
| 238 | // Setup meshes |
| 239 | for (int32 lodIndex = 0; lodIndex < meshesCountPerLod.Length(); lodIndex++) |
| 240 | { |
| 241 | auto& lod = LODs[lodIndex]; |
| 242 | lod.Link(this, lodIndex); |
| 243 | lod.ScreenSize = 1.0f; |
| 244 | const int32 meshesCount = meshesCountPerLod[lodIndex]; |
| 245 | if (meshesCount < 0 || meshesCount > MODEL_MAX_MESHES) |
| 246 | return true; |
| 247 | |
| 248 | lod.Meshes.Resize(meshesCount); |
| 249 | for (int32 meshIndex = 0; meshIndex < meshesCount; meshIndex++) |
| 250 | { |
| 251 | lod.Meshes[meshIndex].Link(this, lodIndex, meshIndex); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // Update resource residency |
| 256 | _loadedLODs = meshesCountPerLod.Length(); |
| 257 | ResidencyChanged(); |
| 258 | |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | bool Model::LoadHeader(ReadStream& stream, byte& headerVersion) |
| 263 | { |