Minor tweaks to #2147

This commit is contained in:
Wojtek Figat
2024-02-20 10:49:45 +01:00
parent e446ba69e5
commit 9c9aabcae3
3 changed files with 13 additions and 19 deletions

View File

@@ -269,7 +269,7 @@ CreateAssetResult ImportModel::Import(CreateAssetContext& context)
// Import all of the objects recursive but use current model data to skip loading file again
options.Cached = &cached;
Function<bool(Options& splitOptions, const StringView& objectName, String& outputPath, MeshData& meshData)> splitImport = [&context, &autoImportOutput](Options& splitOptions, const StringView& objectName, String& outputPath, MeshData& meshData)
Function<bool(Options& splitOptions, const StringView& objectName, String& outputPath, MeshData* meshData)> splitImport = [&context, &autoImportOutput](Options& splitOptions, const StringView& objectName, String& outputPath, MeshData* meshData)
{
// Recursive importing of the split object
String postFix = objectName;
@@ -280,19 +280,19 @@ CreateAssetResult ImportModel::Import(CreateAssetContext& context)
outputPath = autoImportOutput / String(StringUtils::GetFileNameWithoutExtension(context.TargetAssetPath)) + TEXT(" ") + postFix + TEXT(".flax");
splitOptions.SubAssetFolder = TEXT(" "); // Use the same folder as asset as they all are imported to the subdir for the prefab (see SubAssetFolder usage above)
if (splitOptions.Type == ModelTool::ModelType::Model)
if (splitOptions.Type == ModelTool::ModelType::Model && meshData)
{
// These settings interfere with submesh reimporting.
// These settings interfere with submesh reimporting
splitOptions.CenterGeometry = false;
splitOptions.UseLocalOrigin = false;
// This properly sets the transformation of the mesh during reimport.
// This properly sets the transformation of the mesh during reimport
auto* nodes = &splitOptions.Cached->Data->Nodes;
Vector3 scale = Vector3::One;
// TODO: Improve this hack.
// This is the same hack as in ImportModel::CreatePrefab(), and it is documented further there.
auto* currentNode = &(*nodes)[meshData.NodeIndex];
// This is the same hack as in ImportModel::CreatePrefab(), and it is documented further there
auto* currentNode = &(*nodes)[meshData->NodeIndex];
while (true)
{
if (currentNode->ParentIndex == -1)
@@ -303,7 +303,7 @@ CreateAssetResult ImportModel::Import(CreateAssetContext& context)
currentNode = &(*nodes)[currentNode->ParentIndex];
}
splitOptions.Translation = meshData.OriginTranslation * scale * -1.0f;
splitOptions.Translation = meshData->OriginTranslation * scale * -1.0f;
}
return AssetsImportingManager::Import(context.InputPath, outputPath, &splitOptions);
@@ -321,7 +321,7 @@ CreateAssetResult ImportModel::Import(CreateAssetContext& context)
splitOptions.Type = ModelTool::ModelType::Model;
splitOptions.ObjectIndex = groupIndex;
if (!splitImport(splitOptions, group.GetKey(), prefabObject.AssetPath, *group.First()))
if (!splitImport(splitOptions, group.GetKey(), prefabObject.AssetPath, group.First()))
{
prefabObjects.Add(prefabObject);
}
@@ -332,9 +332,7 @@ CreateAssetResult ImportModel::Import(CreateAssetContext& context)
auto& animation = data->Animations[i];
splitOptions.Type = ModelTool::ModelType::Animation;
splitOptions.ObjectIndex = i;
MeshData empty;
splitImport(splitOptions, animation.Name, prefabObject.AssetPath, empty);
splitImport(splitOptions, animation.Name, prefabObject.AssetPath, nullptr);
}
}
else if (options.SplitObjects)
@@ -390,7 +388,7 @@ CreateAssetResult ImportModel::Import(CreateAssetContext& context)
auto& group = meshesByName[options.ObjectIndex];
if (&dataThis == data)
{
// Use meshes only from the the grouping (others will be removed manually)
// Use meshes only from the grouping (others will be removed manually)
{
auto& lod = dataThis.LODs[0];
meshesToDelete.Add(lod.Meshes);

View File

@@ -774,7 +774,7 @@ bool ModelTool::ImportDataAssimp(const char* path, ModelData& data, Options& opt
// Setup import options
context.AssimpImporter.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, options.SmoothingNormalsAngle);
context.AssimpImporter.SetPropertyFloat(AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE, options.SmoothingTangentsAngle);
context.AssimpImporter.SetPropertyFloat(AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY, 100.0f); // Convert to cm?
context.AssimpImporter.SetPropertyFloat(AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY, 100.0f); // Convert to cm
//context.AssimpImporter.SetPropertyInteger(AI_CONFIG_PP_SLM_TRIANGLE_LIMIT, MAX_uint16);
context.AssimpImporter.SetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_CAMERAS, false);
context.AssimpImporter.SetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_LIGHTS, false);

View File

@@ -1320,7 +1320,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
!
#endif
}
if (EnumHasAnyFlags(options.ImportTypes, ImportDataTypes::Geometry) && !(options.Type == ModelType::Prefab))
if (EnumHasAnyFlags(options.ImportTypes, ImportDataTypes::Geometry) && options.Type != ModelType::Prefab)
{
// Perform simple nodes mapping to single node (will transform meshes to model local space)
SkeletonMapping<ModelDataNode> skeletonMapping(data.Nodes, nullptr);
@@ -1340,7 +1340,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
if (skeletonMapping.SourceToSource[mesh.NodeIndex] != mesh.NodeIndex)
{
// Transform vertices
auto transformationMatrix = hierarchyUpdater.CombineMatricesFromNodeIndices(skeletonMapping.SourceToSource[mesh.NodeIndex], mesh.NodeIndex);
const Matrix transformationMatrix = hierarchyUpdater.CombineMatricesFromNodeIndices(skeletonMapping.SourceToSource[mesh.NodeIndex], mesh.NodeIndex);
if (!transformationMatrix.IsIdentity())
mesh.TransformBuffer(transformationMatrix);
@@ -1360,7 +1360,6 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
{
auto& mesh = *data.LODs[lodIndex].Meshes[meshIndex];
auto& node = data.Nodes[mesh.NodeIndex];
auto currentNode = &data.Nodes[mesh.NodeIndex];
Vector3 scale = Vector3::One;
@@ -1369,11 +1368,8 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
{
scale *= currentNode->LocalTransform.Scale;
rotation *= currentNode->LocalTransform.Orientation;
if (currentNode->ParentIndex == -1)
{
break;
}
currentNode = &data.Nodes[currentNode->ParentIndex];
}