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:
@@ -42,6 +42,7 @@ void ModelTool::Options::Serialize(SerializeStream& stream, const void* otherObj
|
||||
SERIALIZE(ImportVertexColors);
|
||||
SERIALIZE(ImportBlendShapes);
|
||||
SERIALIZE(LightmapUVsSource);
|
||||
SERIALIZE(CollisionMeshesPrefix);
|
||||
SERIALIZE(Scale);
|
||||
SERIALIZE(Rotation);
|
||||
SERIALIZE(Translation);
|
||||
@@ -79,6 +80,7 @@ void ModelTool::Options::Deserialize(DeserializeStream& stream, ISerializeModifi
|
||||
DESERIALIZE(ImportVertexColors);
|
||||
DESERIALIZE(ImportBlendShapes);
|
||||
DESERIALIZE(LightmapUVsSource);
|
||||
DESERIALIZE(CollisionMeshesPrefix);
|
||||
DESERIALIZE(Scale);
|
||||
DESERIALIZE(Rotation);
|
||||
DESERIALIZE(Translation);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "Engine/Tools/TextureTool/TextureTool.h"
|
||||
#include "Engine/ContentImporters/AssetsImportingManager.h"
|
||||
#include "Engine/ContentImporters/CreateMaterial.h"
|
||||
#include "Engine/ContentImporters/CreateCollisionData.h"
|
||||
#include "Editor/Utilities/EditorUtilities.h"
|
||||
#include <ThirdParty/meshoptimizer/meshoptimizer.h>
|
||||
|
||||
@@ -562,7 +563,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
||||
materialOptions.Opacity.Texture = data.Textures[material.Opacity.TextureIndex].AssetID;
|
||||
if (material.Normals.TextureIndex != -1)
|
||||
materialOptions.Normals.Texture = data.Textures[material.Normals.TextureIndex].AssetID;
|
||||
if (material.TwoSided | material.Diffuse.HasAlphaMask)
|
||||
if (material.TwoSided || material.Diffuse.HasAlphaMask)
|
||||
materialOptions.Info.CullMode = CullMode::TwoSided;
|
||||
if (!Math::IsOne(material.Opacity.Value) || material.Opacity.TextureIndex != -1)
|
||||
materialOptions.Info.BlendMode = MaterialBlendMode::Transparent;
|
||||
@@ -624,6 +625,41 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
||||
}
|
||||
}
|
||||
|
||||
// Collision mesh output
|
||||
if (options.CollisionMeshesPrefix.HasChars())
|
||||
{
|
||||
// Extract collision meshes
|
||||
ModelData collisionModel;
|
||||
for (auto& lod : data.LODs)
|
||||
{
|
||||
for (int32 i = lod.Meshes.Count() - 1; i >= 0; i--)
|
||||
{
|
||||
auto mesh = lod.Meshes[i];
|
||||
if (mesh->Name.StartsWith(options.CollisionMeshesPrefix, StringSearchCase::IgnoreCase))
|
||||
{
|
||||
if (collisionModel.LODs.Count() == 0)
|
||||
collisionModel.LODs.AddOne();
|
||||
collisionModel.LODs[0].Meshes.Add(mesh);
|
||||
lod.Meshes.RemoveAtKeepOrder(i);
|
||||
if (lod.Meshes.IsEmpty())
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (collisionModel.LODs.HasItems())
|
||||
{
|
||||
// Create collision
|
||||
CollisionCooking::Argument arg;
|
||||
arg.Type = CollisionDataType::TriangleMesh;
|
||||
arg.OverrideModelData = &collisionModel;
|
||||
auto assetPath = autoImportOutput / StringUtils::GetFileNameWithoutExtension(path) + TEXT("Collision") ASSET_FILES_EXTENSION_WITH_DOT;
|
||||
if (CreateCollisionData::CookMeshCollision(assetPath, arg))
|
||||
{
|
||||
LOG(Error, "Failed to create collision mesh.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For generated lightmap UVs coordinates needs to be moved so all meshes are in unique locations in [0-1]x[0-1] coordinates space
|
||||
if (options.LightmapUVsSource == ModelLightmapUVsSource::Generate && data.LODs.HasItems() && data.LODs[0].Meshes.Count() > 1)
|
||||
{
|
||||
|
||||
@@ -177,6 +177,7 @@ public:
|
||||
bool ImportVertexColors = true;
|
||||
bool ImportBlendShapes = false;
|
||||
ModelLightmapUVsSource LightmapUVsSource = ModelLightmapUVsSource::Disable;
|
||||
String CollisionMeshesPrefix;
|
||||
|
||||
// Transform
|
||||
float Scale = 1.0f;
|
||||
|
||||
Reference in New Issue
Block a user