mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 00:02:55 +00:00
chore: load materials for xmodel
This commit is contained in:
parent
0d343dd3fa
commit
dfd8d1dbe9
@ -469,14 +469,27 @@ namespace
|
|||||||
lodInfo.surfIndex = static_cast<uint16_t>(m_surfaces.size());
|
lodInfo.surfIndex = static_cast<uint16_t>(m_surfaces.size());
|
||||||
lodInfo.numsurfs = static_cast<uint16_t>(common->m_objects.size());
|
lodInfo.numsurfs = static_cast<uint16_t>(common->m_objects.size());
|
||||||
|
|
||||||
|
std::vector<Material*> materialAssets;
|
||||||
|
materialAssets.reserve(common->m_materials.size());
|
||||||
|
for (const auto& commonMaterial : common->m_materials)
|
||||||
|
{
|
||||||
|
auto* assetInfo = m_manager.LoadDependency<AssetMaterial>(commonMaterial.name);
|
||||||
|
if (!assetInfo)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
m_dependencies.emplace(assetInfo);
|
||||||
|
materialAssets.push_back(assetInfo->Asset());
|
||||||
|
}
|
||||||
|
|
||||||
return std::ranges::all_of(common->m_objects,
|
return std::ranges::all_of(common->m_objects,
|
||||||
[this, &common](const XModelObject& commonObject)
|
[this, &common, &materialAssets](const XModelObject& commonObject)
|
||||||
{
|
{
|
||||||
XSurface surface{};
|
XSurface surface{};
|
||||||
if (!CreateXSurface(surface, commonObject, *common))
|
if (!CreateXSurface(surface, commonObject, *common))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_surfaces.emplace_back(surface);
|
m_surfaces.emplace_back(surface);
|
||||||
|
m_materials.push_back(materialAssets[commonObject.materialIndex]);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -521,7 +534,9 @@ namespace
|
|||||||
|
|
||||||
xmodel.numsurfs = static_cast<unsigned char>(m_surfaces.size());
|
xmodel.numsurfs = static_cast<unsigned char>(m_surfaces.size());
|
||||||
xmodel.surfs = m_memory.Alloc<XSurface>(xmodel.numsurfs);
|
xmodel.surfs = m_memory.Alloc<XSurface>(xmodel.numsurfs);
|
||||||
|
xmodel.materialHandles = m_memory.Alloc<Material*>(xmodel.numsurfs);
|
||||||
memcpy(xmodel.surfs, m_surfaces.data(), sizeof(XSurface) * xmodel.numsurfs);
|
memcpy(xmodel.surfs, m_surfaces.data(), sizeof(XSurface) * xmodel.numsurfs);
|
||||||
|
memcpy(xmodel.materialHandles, m_materials.data(), sizeof(Material*) * xmodel.numsurfs);
|
||||||
|
|
||||||
CalculateModelBounds(xmodel);
|
CalculateModelBounds(xmodel);
|
||||||
|
|
||||||
@ -579,6 +594,7 @@ namespace
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<XSurface> m_surfaces;
|
std::vector<XSurface> m_surfaces;
|
||||||
|
std::vector<Material*> m_materials;
|
||||||
|
|
||||||
std::istream& m_stream;
|
std::istream& m_stream;
|
||||||
MemoryManager& m_memory;
|
MemoryManager& m_memory;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user