Merge remote-tracking branch 'origin/master' into gi

# Conflicts:
#	Flax.flaxproj
#	Source/Engine/Core/Math/Vector3.h
#	Source/Engine/Graphics/Textures/GPUTexture.cpp
#	Source/Engine/GraphicsDevice/DirectX/DX11/GPUContextDX11.cpp
#	Source/Engine/Terrain/Terrain.cpp
#	Source/Engine/Tools/ModelTool/ModelTool.Build.cs
#	Source/FlaxEngine.Gen.cs
#	Source/FlaxEngine.Gen.h
This commit is contained in:
Wojciech Figat
2022-03-22 13:00:21 +01:00
49 changed files with 647 additions and 163 deletions

View File

@@ -163,6 +163,12 @@ namespace FlaxEditor.Content.Import
[EditorOrder(90), DefaultValue(ModelLightmapUVsSource.Disable), EditorDisplay("Geometry", "Lightmap UVs Source"), Tooltip("Model lightmap UVs source")]
public ModelLightmapUVsSource LightmapUVsSource { get; set; } = ModelLightmapUVsSource.Disable;
/// <summary>
/// If specified, all meshes which name starts with this prefix will be imported as a separate collision data (excluded used for rendering).
/// </summary>
[EditorOrder(100), DefaultValue(""), EditorDisplay("Geometry")]
public string CollisionMeshesPrefix { get; set; }
/// <summary>
/// Custom uniform import scale.
/// </summary>
@@ -284,7 +290,7 @@ namespace FlaxEditor.Content.Import
/// </summary>
[EditorOrder(420), DefaultValue(true), EditorDisplay("Materials", "Restore Materials On Reimport"), Tooltip("If checked, the importer will try to restore the assigned materials to the model slots.")]
public bool RestoreMaterialsOnReimport { get; set; } = true;
/// <summary>
/// If checked, the imported mesh/animations are splitted into separate assets. Used if ObjectIndex is set to -1.
/// </summary>
@@ -314,6 +320,7 @@ namespace FlaxEditor.Content.Import
public byte ImportVertexColors;
public byte ImportBlendShapes;
public ModelLightmapUVsSource LightmapUVsSource;
public string CollisionMeshesPrefix;
// Transform
public float Scale;
@@ -364,6 +371,7 @@ namespace FlaxEditor.Content.Import
ImportVertexColors = (byte)(ImportVertexColors ? 1 : 0),
ImportBlendShapes = (byte)(ImportBlendShapes ? 1 : 0),
LightmapUVsSource = LightmapUVsSource,
CollisionMeshesPrefix = CollisionMeshesPrefix,
Scale = Scale,
Rotation = Rotation,
Translation = Translation,
@@ -403,6 +411,7 @@ namespace FlaxEditor.Content.Import
ImportVertexColors = options.ImportVertexColors != 0;
ImportBlendShapes = options.ImportBlendShapes != 0;
LightmapUVsSource = options.LightmapUVsSource;
CollisionMeshesPrefix = options.CollisionMeshesPrefix;
Scale = options.Scale;
Rotation = options.Rotation;
Translation = options.Translation;

View File

@@ -86,6 +86,7 @@ namespace FlaxEditor.Content
{
foreach (var child in modelItem.ParentFolder.Children)
{
// Check if there is collision that was made with this model
if (child is BinaryAssetItem b && b.IsOfType<CollisionData>())
{
var collisionData = FlaxEngine.Content.Load<CollisionData>(b.ID);
@@ -97,6 +98,25 @@ namespace FlaxEditor.Content
return;
}
}
// Check if there is a auto-imported collision
if (child is ContentFolder childFolder && childFolder.ShortName == modelItem.ShortName)
{
foreach (var childFolderChild in childFolder.Children)
{
if (childFolderChild is BinaryAssetItem c && c.IsOfType<CollisionData>())
{
var collisionData = FlaxEngine.Content.Load<CollisionData>(c.ID);
if (collisionData && (collisionData.Options.Model == model.ID || collisionData.Options.Model == Guid.Empty))
{
Editor.Instance.Windows.ContentWin.Select(c);
if (created != null)
FlaxEngine.Scripting.InvokeOnUpdate(() => created(collisionData));
return;
}
}
}
}
}
}

View File

@@ -229,7 +229,13 @@ namespace FlaxEditor.CustomEditors
for (int i = 0; i < Count; i++)
{
if (!Equals(this[i], _defaultValue))
{
// Special case for String (null string is kind of equal to empty string from the user perspective)
if (this[i] == null && _defaultValue is string defaultValueStr && defaultValueStr.Length == 0)
continue;
return true;
}
}
}
return false;

View File

@@ -227,8 +227,8 @@ namespace FlaxEditor.GUI.Tabs
/// </summary>
public Tab SelectedTab
{
get => _selectedIndex == -1 ? null : Children[_selectedIndex + 1] as Tab;
set => SelectedTabIndex = Children.IndexOf(value) - 1;
get => _selectedIndex == -1 && Children.Count > _selectedIndex + 1 ? null : Children[_selectedIndex + 1] as Tab;
set => SelectedTabIndex = value != null ? Children.IndexOf(value) - 1 : -1;
}
/// <summary>

View File

@@ -166,6 +166,7 @@ struct InternalModelOptions
byte ImportVertexColors;
byte ImportBlendShapes;
ModelLightmapUVsSource LightmapUVsSource;
MonoString* CollisionMeshesPrefix;
// Transform
float Scale;
@@ -213,6 +214,7 @@ struct InternalModelOptions
to->ImportVertexColors = from->ImportVertexColors;
to->ImportBlendShapes = from->ImportBlendShapes;
to->LightmapUVsSource = from->LightmapUVsSource;
to->CollisionMeshesPrefix = MUtils::ToString(from->CollisionMeshesPrefix);
to->Scale = from->Scale;
to->Rotation = from->Rotation;
to->Translation = from->Translation;
@@ -251,6 +253,7 @@ struct InternalModelOptions
to->ImportVertexColors = from->ImportVertexColors;
to->ImportBlendShapes = from->ImportBlendShapes;
to->LightmapUVsSource = from->LightmapUVsSource;
to->CollisionMeshesPrefix = MUtils::ToString(from->CollisionMeshesPrefix);
to->Scale = from->Scale;
to->Rotation = from->Rotation;
to->Translation = from->Translation;

View File

@@ -93,6 +93,11 @@ namespace FlaxEditor.Options
public void Load()
{
Editor.Log("Loading editor options");
if (!File.Exists(_optionsFilePath))
{
Editor.LogWarning("Missing editor settings");
return;
}
try
{
@@ -100,12 +105,12 @@ namespace FlaxEditor.Options
var asset = FlaxEngine.Content.LoadAsync<JsonAsset>(_optionsFilePath);
if (asset == null)
{
Editor.LogWarning("Missing or invalid editor settings");
Editor.LogWarning("Invalid editor settings");
return;
}
if (asset.WaitForLoaded())
{
Editor.LogWarning("Failed to load editor settings");
Editor.LogError("Failed to load editor settings");
return;
}

View File

@@ -180,7 +180,22 @@ void CodeEditingManager::OpenSolution(CodeEditorTypes editorType)
const auto editor = GetCodeEditor(editorType);
if (editor)
{
OpenSolution(editor);
// Ensure that no async task is running
if (IsAsyncOpenRunning())
{
// TODO: enqueue action and handle many actions in the queue
LOG(Warning, "Cannot use code editor during async open action.");
return;
}
if (editor->UseAsyncForOpen())
{
AsyncOpenTask::OpenSolution(editor);
}
else
{
editor->OpenSolution();
}
}
else
{
@@ -201,26 +216,6 @@ void CodeEditingManager::OnFileAdded(CodeEditorTypes editorType, const String& p
}
}
void CodeEditingManager::OpenSolution(CodeEditor* editor)
{
// Ensure that no async task is running
if (IsAsyncOpenRunning())
{
// TODO: enqueue action and handle many actions in the queue
LOG(Warning, "Cannot use code editor during async open action.");
return;
}
if (editor->UseAsyncForOpen())
{
AsyncOpenTask::OpenSolution(editor);
}
else
{
editor->OpenSolution();
}
}
void OnAsyncBegin(Thread* thread)
{
ASSERT(AsyncOpenThread == nullptr);

View File

@@ -193,12 +193,6 @@ public:
/// <param name="path">The path.</param>
API_FUNCTION() static void OnFileAdded(CodeEditorTypes editorType, const String& path);
/// <summary>
/// Opens the solution project. Handles async opening.
/// </summary>
/// <param name="editor">The code editor.</param>
static void OpenSolution(CodeEditor* editor);
/// <summary>
/// The asynchronous open begins.
/// </summary>

View File

@@ -156,7 +156,7 @@ bool ScriptsBuilder::IsSourceWorkspaceDirty()
return _wasProjectStructureChanged;
}
bool ScriptsBuilder::IsSourceDirty(const TimeSpan& timeout)
bool ScriptsBuilder::IsSourceDirtyFor(const TimeSpan& timeout)
{
ScopeLock scopeLock(_locker);
return _lastSourceCodeEdited > (_lastCompileAction + timeout);
@@ -626,7 +626,7 @@ void ScriptsBuilderService::Update()
// Check if compile code (if has been edited)
const TimeSpan timeToCallCompileIfDirty = TimeSpan::FromMilliseconds(50);
auto mainWindow = Engine::MainWindow;
if (ScriptsBuilder::IsSourceDirty(timeToCallCompileIfDirty) && mainWindow && mainWindow->IsFocused())
if (ScriptsBuilder::IsSourceDirtyFor(timeToCallCompileIfDirty) && mainWindow && mainWindow->IsFocused())
{
// Check if auto reload is enabled
if (Editor::Managed->CanAutoReloadScripts())

View File

@@ -63,7 +63,7 @@ public:
/// </summary>
/// <param name="timeout">Time to use for checking.</param>
/// <returns>True if source code is dirty, otherwise false.</returns>
static bool IsSourceDirty(const TimeSpan& timeout);
static bool IsSourceDirtyFor(const TimeSpan& timeout);
/// <summary>
/// Returns true if scripts are being now compiled/reloaded.

View File

@@ -829,7 +829,13 @@ namespace FlaxEditor.Utilities
var attr = field.GetAttribute<System.ComponentModel.DefaultValueAttribute>();
if (attr != null)
{
field.SetValue(obj, attr.Value);
// Prevent value type conflicts
var value = attr.Value;
var fieldType = field.ValueType.Type;
if (value != null && value.GetType() != fieldType)
value = Convert.ChangeType(value, fieldType);
field.SetValue(obj, value);
}
else if (isStructure)
{
@@ -845,7 +851,13 @@ namespace FlaxEditor.Utilities
var attr = property.GetAttribute<System.ComponentModel.DefaultValueAttribute>();
if (attr != null)
{
property.SetValue(obj, attr.Value);
// Prevent value type conflicts
var value = attr.Value;
var propertyType = property.ValueType.Type;
if (value != null && value.GetType() != propertyType)
value = Convert.ChangeType(value, propertyType);
property.SetValue(obj, value);
}
}
}