fix a couple of bugs with importing without material instances
This commit is contained in:
@@ -437,6 +437,12 @@ namespace FlaxEditor.Content.Import
|
||||
|
||||
internal void ToInternal(out InternalOptions options)
|
||||
{
|
||||
Guid instanceToImportAsGuid = Guid.Empty;
|
||||
if (InstanceToImportAs != null)
|
||||
{
|
||||
instanceToImportAsGuid = InstanceToImportAs.ID;
|
||||
}
|
||||
|
||||
options = new InternalOptions
|
||||
{
|
||||
Type = Type,
|
||||
@@ -472,7 +478,7 @@ namespace FlaxEditor.Content.Import
|
||||
TriangleReduction = TriangleReduction,
|
||||
ImportMaterials = (byte)(ImportMaterials ? 1 : 0),
|
||||
ImportMaterialsAsInstances = (byte)(ImportMaterialsAsInstances ? 1 : 0),
|
||||
InstanceToImportAs = InstanceToImportAs.ID,
|
||||
InstanceToImportAs = instanceToImportAsGuid,
|
||||
ImportTextures = (byte)(ImportTextures ? 1 : 0),
|
||||
RestoreMaterialsOnReimport = (byte)(RestoreMaterialsOnReimport ? 1 : 0),
|
||||
GenerateSDF = (byte)(GenerateSDF ? 1 : 0),
|
||||
@@ -484,6 +490,16 @@ namespace FlaxEditor.Content.Import
|
||||
|
||||
internal void FromInternal(ref InternalOptions options)
|
||||
{
|
||||
Material instanceToImportAsMat = null;
|
||||
if (options.InstanceToImportAs != Guid.Empty)
|
||||
{
|
||||
AssetInfo assetInfo;
|
||||
if (FlaxEngine.Content.GetAssetInfo(options.InstanceToImportAs, out assetInfo))
|
||||
{
|
||||
instanceToImportAsMat = FlaxEngine.Content.Load<Material>(options.InstanceToImportAs);
|
||||
}
|
||||
}
|
||||
|
||||
Type = options.Type;
|
||||
CalculateNormals = options.CalculateNormals != 0;
|
||||
SmoothingNormalsAngle = options.SmoothingNormalsAngle;
|
||||
@@ -516,7 +532,7 @@ namespace FlaxEditor.Content.Import
|
||||
TriangleReduction = options.TriangleReduction;
|
||||
ImportMaterials = options.ImportMaterials != 0;
|
||||
ImportMaterialsAsInstances = options.ImportMaterialsAsInstances != 0;
|
||||
InstanceToImportAs = FlaxEngine.Content.Load<Material>(options.InstanceToImportAs);
|
||||
InstanceToImportAs = instanceToImportAsMat;
|
||||
ImportTextures = options.ImportTextures != 0;
|
||||
RestoreMaterialsOnReimport = options.RestoreMaterialsOnReimport != 0;
|
||||
GenerateSDF = options.GenerateSDF != 0;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#if ENABLE_ASSETS_DISCOVERY
|
||||
#include "Engine/Core/Collections/HashSet.h"
|
||||
#endif
|
||||
#include <Engine/Debug/DebugLog.h>
|
||||
|
||||
TimeSpan Content::AssetsUpdateInterval = TimeSpan::FromMilliseconds(500);
|
||||
TimeSpan Content::AssetsUnloadInterval = TimeSpan::FromSeconds(10);
|
||||
@@ -1003,6 +1004,7 @@ Asset* Content::load(const Guid& id, const ScriptingTypeHandle& type, AssetInfo&
|
||||
if (!GetAssetInfo(id, assetInfo))
|
||||
{
|
||||
LOG(Warning, "Invalid or missing asset ({0}, {1}).", id.ToString(Guid::FormatType::N), type.ToString());
|
||||
LOG(Warning, "{0}", DebugLog::GetStackTrace());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -863,18 +863,19 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
||||
importedFileNames.Add(filename);
|
||||
#if COMPILE_WITH_ASSETS_IMPORTER
|
||||
auto assetPath = autoImportOutput / filename + ASSET_FILES_EXTENSION_WITH_DOT;
|
||||
if (options.ImportMaterialsAsInstances) {
|
||||
LOG(Warning, "Adding material instance for {0}", assetPath);
|
||||
|
||||
if (options.ImportMaterialsAsInstances)
|
||||
{
|
||||
AssetsImportingManager::Create(AssetsImportingManager::CreateMaterialInstanceTag, assetPath, material.AssetID);
|
||||
MaterialInstance* materialInstance = (MaterialInstance*) LoadAsset(assetPath, MaterialInstance::TypeInitializer);
|
||||
if (materialInstance->WaitForLoaded()) {
|
||||
if (materialInstance->WaitForLoaded())
|
||||
{
|
||||
LOG(Error, "Failed to load material instance after creation. ({0})", assetPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
MaterialBase* materialInstanceOf = (MaterialBase*) LoadAsset(options.InstanceToImportAs, MaterialBase::TypeInitializer);
|
||||
if (materialInstanceOf->WaitForLoaded()) {
|
||||
if (materialInstanceOf->WaitForLoaded())
|
||||
{
|
||||
LOG(Error, "Failed to load material to create an instance of. ({0})", options.InstanceToImportAs);
|
||||
return true;
|
||||
}
|
||||
@@ -882,7 +883,8 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
||||
materialInstance->SetBaseMaterial(materialInstanceOf);
|
||||
materialInstance->Save();
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
CreateMaterial::Options materialOptions;
|
||||
materialOptions.Diffuse.Color = material.Diffuse.Color;
|
||||
if (material.Diffuse.TextureIndex != -1)
|
||||
|
||||
Reference in New Issue
Block a user