Importing as instances works now

This commit is contained in:
Menotdan
2023-05-22 10:12:00 -04:00
parent f03bb60d5b
commit 37fe1154a3
3 changed files with 20 additions and 26 deletions
+1
View File
@@ -246,3 +246,4 @@ public:
// Don't include Content.h but just Load method
extern FLAXENGINE_API Asset* LoadAsset(const Guid& id, const ScriptingTypeHandle& type);
extern FLAXENGINE_API Asset* LoadAsset(const StringView& path, const ScriptingTypeHandle& type);
+5
View File
@@ -449,6 +449,11 @@ FLAXENGINE_API Asset* LoadAsset(const Guid& id, const ScriptingTypeHandle& type)
return Content::LoadAsync(id, type);
}
FLAXENGINE_API Asset* LoadAsset(const StringView& path, const ScriptingTypeHandle& type)
{
return Content::LoadAsync(path, type);
}
Asset* Content::LoadAsync(const StringView& path, MClass* type)
{
CHECK_RETURN(type, nullptr);
+14 -26
View File
@@ -864,40 +864,28 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
#if COMPILE_WITH_ASSETS_IMPORTER
auto assetPath = autoImportOutput / filename + ASSET_FILES_EXTENSION_WITH_DOT;
if (options.ImportMaterialsAsInstances) {
LOG(Warning, "Did work poggers");
if (AssetsImportingManager::Create(AssetsImportingManager::CreateMaterialInstanceTag, assetPath, material.AssetID))
{
LOG(Error, "Failed to create material instance.");
LOG(Warning, "Adding material instance for {0}", assetPath);
AssetsImportingManager::Create(AssetsImportingManager::CreateMaterialInstanceTag, assetPath);
MaterialInstance* materialInstance = (MaterialInstance*) LoadAsset(assetPath, MaterialInstance::TypeInitializer);
if (materialInstance->WaitForLoaded()) {
LOG(Error, "Failed to load material instance after creation. ({0})", assetPath);
return true;
}
else
{
MaterialInstance* materialInstance = (MaterialInstance*) LoadAsset(material.AssetID, ScriptingTypeHandle());
if (materialInstance == nullptr)
{
LOG(Error, "Failed to find created material instance.");
return true;
}
MaterialBase *materialInstanceOf = (MaterialBase*) LoadAsset(options.InstanceToImportAs, ScriptingTypeHandle());
if (materialInstanceOf == nullptr)
{
LOG(Error, "Failed to find the material to create an instance of.");
return true;
}
materialInstance->SetBaseMaterial(materialInstanceOf);
if (materialInstance->Save())
{
LOG(Error, "Failed to save the material instance.");
return true;
}
MaterialBase* materialInstanceOf = (MaterialBase*) LoadAsset(options.InstanceToImportAs, MaterialBase::TypeInitializer);
if (materialInstanceOf->WaitForLoaded()) {
LOG(Error, "Failed to load material to create an instance of. ({0})", options.InstanceToImportAs);
return true;
}
materialInstance->SetBaseMaterial(materialInstanceOf);
materialInstance->Save();
}
else {
CreateMaterial::Options materialOptions;
materialOptions.Diffuse.Color = material.Diffuse.Color;
if (material.Diffuse.TextureIndex != -1)
if (material.Diffuse.TextureIndex != -1)
materialOptions.Diffuse.Texture = data.Textures[material.Diffuse.TextureIndex].AssetID;
materialOptions.Diffuse.HasAlphaMask = material.Diffuse.HasAlphaMask;
materialOptions.Emissive.Color = material.Emissive.Color;