Fix crash when importing model with materials and Split Objects enabled
This commit is contained in:
@@ -545,7 +545,7 @@ namespace FlaxEditor.GUI
|
|||||||
Render2D.DrawRectangle(clientRect.MakeExpanded(-2.0f), borderColor);
|
Render2D.DrawRectangle(clientRect.MakeExpanded(-2.0f), borderColor);
|
||||||
|
|
||||||
// Check if has selected item
|
// Check if has selected item
|
||||||
if (_selectedIndices.Count > 0)
|
if (_selectedIndices != null && _selectedIndices.Count > 0)
|
||||||
{
|
{
|
||||||
string text = _selectedIndices.Count == 1 ? _items[_selectedIndices[0]] : "Multiple Values";
|
string text = _selectedIndices.Count == 1 ? _items[_selectedIndices[0]] : "Multiple Values";
|
||||||
|
|
||||||
|
|||||||
@@ -716,13 +716,13 @@ bool ModelTool::ImportDataAssimp(const char* path, ImportedModelData& data, Opti
|
|||||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry) && context->Scene->HasMeshes())
|
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry) && context->Scene->HasMeshes())
|
||||||
{
|
{
|
||||||
const int meshCount = context->Scene->mNumMeshes;
|
const int meshCount = context->Scene->mNumMeshes;
|
||||||
if (options.SplitObjects && options.ObjectIndex == -1)
|
if (options.SplitObjects && options.ObjectIndex == -1 && meshCount > 1)
|
||||||
{
|
{
|
||||||
// Import the first object within this call
|
// Import the first object within this call
|
||||||
options.SplitObjects = false;
|
options.SplitObjects = false;
|
||||||
options.ObjectIndex = 0;
|
options.ObjectIndex = 0;
|
||||||
|
|
||||||
if (meshCount > 1 && options.OnSplitImport.IsBinded())
|
if (options.OnSplitImport.IsBinded())
|
||||||
{
|
{
|
||||||
// Split all animations into separate assets
|
// Split all animations into separate assets
|
||||||
LOG(Info, "Splitting imported {0} meshes", meshCount);
|
LOG(Info, "Splitting imported {0} meshes", meshCount);
|
||||||
@@ -789,13 +789,13 @@ bool ModelTool::ImportDataAssimp(const char* path, ImportedModelData& data, Opti
|
|||||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Animations) && context->Scene->HasAnimations())
|
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Animations) && context->Scene->HasAnimations())
|
||||||
{
|
{
|
||||||
const int32 animCount = (int32)context->Scene->mNumAnimations;
|
const int32 animCount = (int32)context->Scene->mNumAnimations;
|
||||||
if (options.SplitObjects && options.ObjectIndex == -1)
|
if (options.SplitObjects && options.ObjectIndex == -1 && animCount > 1)
|
||||||
{
|
{
|
||||||
// Import the first object within this call
|
// Import the first object within this call
|
||||||
options.SplitObjects = false;
|
options.SplitObjects = false;
|
||||||
options.ObjectIndex = 0;
|
options.ObjectIndex = 0;
|
||||||
|
|
||||||
if (animCount > 1 && options.OnSplitImport.IsBinded())
|
if (options.OnSplitImport.IsBinded())
|
||||||
{
|
{
|
||||||
// Split all animations into separate assets
|
// Split all animations into separate assets
|
||||||
LOG(Info, "Splitting imported {0} animations", animCount);
|
LOG(Info, "Splitting imported {0} animations", animCount);
|
||||||
|
|||||||
@@ -1245,13 +1245,13 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
|||||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry) && context->Scene->getMeshCount() > 0)
|
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Geometry) && context->Scene->getMeshCount() > 0)
|
||||||
{
|
{
|
||||||
const int meshCount = context->Scene->getMeshCount();
|
const int meshCount = context->Scene->getMeshCount();
|
||||||
if (options.SplitObjects && options.ObjectIndex == -1)
|
if (options.SplitObjects && options.ObjectIndex == -1 && meshCount > 1)
|
||||||
{
|
{
|
||||||
// Import the first object within this call
|
// Import the first object within this call
|
||||||
options.SplitObjects = false;
|
options.SplitObjects = false;
|
||||||
options.ObjectIndex = 0;
|
options.ObjectIndex = 0;
|
||||||
|
|
||||||
if (meshCount > 1 && options.OnSplitImport.IsBinded())
|
if (options.OnSplitImport.IsBinded())
|
||||||
{
|
{
|
||||||
// Split all animations into separate assets
|
// Split all animations into separate assets
|
||||||
LOG(Info, "Splitting imported {0} meshes", meshCount);
|
LOG(Info, "Splitting imported {0} meshes", meshCount);
|
||||||
@@ -1328,13 +1328,13 @@ bool ModelTool::ImportDataOpenFBX(const char* path, ImportedModelData& data, Opt
|
|||||||
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Animations))
|
if (EnumHasAnyFlags(data.Types, ImportDataTypes::Animations))
|
||||||
{
|
{
|
||||||
const int animCount = context->Scene->getAnimationStackCount();
|
const int animCount = context->Scene->getAnimationStackCount();
|
||||||
if (options.SplitObjects && options.ObjectIndex == -1)
|
if (options.SplitObjects && options.ObjectIndex == -1 && animCount > 1)
|
||||||
{
|
{
|
||||||
// Import the first object within this call
|
// Import the first object within this call
|
||||||
options.SplitObjects = false;
|
options.SplitObjects = false;
|
||||||
options.ObjectIndex = 0;
|
options.ObjectIndex = 0;
|
||||||
|
|
||||||
if (animCount > 1 && options.OnSplitImport.IsBinded())
|
if (options.OnSplitImport.IsBinded())
|
||||||
{
|
{
|
||||||
// Split all animations into separate assets
|
// Split all animations into separate assets
|
||||||
LOG(Info, "Splitting imported {0} animations", animCount);
|
LOG(Info, "Splitting imported {0} animations", animCount);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "Engine/Graphics/Textures/TextureData.h"
|
#include "Engine/Graphics/Textures/TextureData.h"
|
||||||
#include "Engine/Graphics/Models/ModelData.h"
|
#include "Engine/Graphics/Models/ModelData.h"
|
||||||
#include "Engine/Content/Assets/Model.h"
|
#include "Engine/Content/Assets/Model.h"
|
||||||
|
#include "Engine/Content/Content.h"
|
||||||
#include "Engine/Serialization/MemoryWriteStream.h"
|
#include "Engine/Serialization/MemoryWriteStream.h"
|
||||||
#if USE_EDITOR
|
#if USE_EDITOR
|
||||||
#include "Engine/Core/Types/DateTime.h"
|
#include "Engine/Core/Types/DateTime.h"
|
||||||
@@ -909,6 +910,10 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
|||||||
{
|
{
|
||||||
auto& texture = data.Textures[i];
|
auto& texture = data.Textures[i];
|
||||||
|
|
||||||
|
// When splitting imported meshes allow only the first mesh to import assets (mesh[0] is imported after all following ones so import assets during mesh[1])
|
||||||
|
if (!options.SplitObjects && options.ObjectIndex != 1 && options.ObjectIndex != -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Auto-import textures
|
// Auto-import textures
|
||||||
if (autoImportOutput.IsEmpty() || (data.Types & ImportDataTypes::Textures) == ImportDataTypes::None || texture.FilePath.IsEmpty())
|
if (autoImportOutput.IsEmpty() || (data.Types & ImportDataTypes::Textures) == ImportDataTypes::None || texture.FilePath.IsEmpty())
|
||||||
continue;
|
continue;
|
||||||
@@ -994,6 +999,17 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
|||||||
materialOptions.Info.CullMode = CullMode::TwoSided;
|
materialOptions.Info.CullMode = CullMode::TwoSided;
|
||||||
if (!Math::IsOne(material.Opacity.Value) || material.Opacity.TextureIndex != -1)
|
if (!Math::IsOne(material.Opacity.Value) || material.Opacity.TextureIndex != -1)
|
||||||
materialOptions.Info.BlendMode = MaterialBlendMode::Transparent;
|
materialOptions.Info.BlendMode = MaterialBlendMode::Transparent;
|
||||||
|
|
||||||
|
// When splitting imported meshes allow only the first mesh to import assets (mesh[0] is imported after all following ones so import assets during mesh[1])
|
||||||
|
if (!options.SplitObjects && options.ObjectIndex != 1 && options.ObjectIndex != -1)
|
||||||
|
{
|
||||||
|
// Find that asset create previously
|
||||||
|
AssetInfo info;
|
||||||
|
if (Content::GetAssetInfo(assetPath, info))
|
||||||
|
material.AssetID = info.ID;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
AssetsImportingManager::Create(AssetsImportingManager::CreateMaterialTag, assetPath, material.AssetID, &materialOptions);
|
AssetsImportingManager::Create(AssetsImportingManager::CreateMaterialTag, assetPath, material.AssetID, &materialOptions);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user