Fixed albedo not working when first importing asset

This commit is contained in:
antopilo
2025-04-17 20:58:38 -04:00
parent 5da09282d0
commit d276e875a8
2 changed files with 17 additions and 3 deletions

View File

@@ -83,7 +83,7 @@ Ref<File> GLTFBaker::Bake(const Ref<File>& file)
material = CreateRef<Material>();
if (!materialData.albedo.empty())
{
material->SetAlbedo(absolutePath + "/../" + materialData.albedo);
material->SetAlbedo(FileSystem::AbsoluteToRelative(absolutePath + "/../" + materialData.albedo));
}
if (!materialData.normal.empty())
@@ -117,7 +117,7 @@ Ref<File> GLTFBaker::Bake(const Ref<File>& file)
materialCache[materialPath] = material;
}
mesh->MaterialResource = RID(material->ID);
mesh->SetMaterial(material);
model->AddMesh(std::move(mesh));
}

View File

@@ -100,7 +100,21 @@ namespace Nuake
inline bool GetUnlit() { return data.u_Unlit == 1; }
bool HasAlbedo() { return (m_Albedo != nullptr || AlbedoImage != UUID(0)); }
void SetAlbedo(const std::string path) { m_Albedo = CreateRef<Texture>(path); }
void SetAlbedo(const std::string path)
{
if (FileSystem::FileExists(path))
{
GPUResources& resources = GPUResources::Get();
Ref<VulkanImage> image = CreateRef<VulkanImage>(FileSystem::RelativeToAbsolute(path));
if (resources.AddTexture(image))
{
AlbedoImage = image->GetID();
}
Ref<Texture> albedoTexture = TextureManager::Get()->GetTexture(path);
SetAlbedo(albedoTexture);
}
}
void SetAlbedo(Ref<Texture> texture) { m_Albedo = texture; }
bool HasAO() { return m_AO != nullptr; }