diff --git a/Source/Engine/ContentImporters/ImportModel.cpp b/Source/Engine/ContentImporters/ImportModel.cpp index cf66762ad..190b4ba41 100644 --- a/Source/Engine/ContentImporters/ImportModel.cpp +++ b/Source/Engine/ContentImporters/ImportModel.cpp @@ -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 splitImport = [&context, &autoImportOutput](Options& splitOptions, const StringView& objectName, String& outputPath, MeshData& meshData) + Function 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); diff --git a/Source/Engine/Tools/ModelTool/ModelTool.Assimp.cpp b/Source/Engine/Tools/ModelTool/ModelTool.Assimp.cpp index 85e320ee6..8b47b21dd 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.Assimp.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.Assimp.cpp @@ -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); diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index a8cb0ecd8..74cbfbb52 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -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 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]; }