| 455 | } |
| 456 | |
| 457 | static void InitMorphSlots(RigInstance* instance) |
| 458 | { |
| 459 | const dmRigDDF::MeshSet* mesh_set = instance->m_MeshSet; |
| 460 | if (!mesh_set) |
| 461 | { |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | uint32_t slot_count = 0; |
| 466 | uint32_t total_floats = 0; |
| 467 | uint32_t max_morph = 0; |
| 468 | |
| 469 | // Pass 1: count the number of morph slots and total number of floats |
| 470 | for (uint32_t mi = 0; mi < mesh_set->m_Models.m_Count; ++mi) |
| 471 | { |
| 472 | const dmRigDDF::Model* model = &mesh_set->m_Models[mi]; |
| 473 | uint32_t mcount = GetModelMaxMorphTargetCount(model); |
| 474 | if (mcount == 0) |
| 475 | { |
| 476 | continue; |
| 477 | } |
| 478 | slot_count++; |
| 479 | total_floats += mcount; |
| 480 | max_morph = dmMath::Max(max_morph, mcount); |
| 481 | } |
| 482 | |
| 483 | if (slot_count == 0 || total_floats == 0) |
| 484 | { |
| 485 | return; |
| 486 | } |
| 487 | |
| 488 | // Pass 2: create the morph weight slots |
| 489 | instance->m_MorphSlots.SetCapacity(slot_count); |
| 490 | uint32_t buffer_offset = 0; |
| 491 | for (uint32_t mi = 0; mi < mesh_set->m_Models.m_Count; ++mi) |
| 492 | { |
| 493 | const dmRigDDF::Model* model = &mesh_set->m_Models[mi]; |
| 494 | uint32_t mcount = GetModelMaxMorphTargetCount(model); |
| 495 | if (mcount == 0) |
| 496 | { |
| 497 | continue; |
| 498 | } |
| 499 | |
| 500 | MorphWeightSlot slot; |
| 501 | slot.m_ModelId = model->m_Id; |
| 502 | slot.m_MorphCount = mcount; |
| 503 | slot.m_BufferOffset = buffer_offset; |
| 504 | instance->m_MorphSlots.Push(slot); |
| 505 | buffer_offset += mcount; |
| 506 | } |
| 507 | |
| 508 | instance->m_MorphWeightsBuffer.SetCapacity(total_floats); |
| 509 | instance->m_MorphWeightsBuffer.SetSize(total_floats); |
| 510 | instance->m_MorphScratch.SetCapacity(max_morph); |
| 511 | instance->m_MorphScratch.SetSize(max_morph); |
| 512 | ResetMorphWeights(instance); |
| 513 | } |
| 514 |
no test coverage detected