| 698 | } |
| 699 | |
| 700 | bool ModelTool::ImportDataAssimp(const String& path, ModelData& data, Options& options, String& errorMsg) |
| 701 | { |
| 702 | static bool AssimpInited = false; |
| 703 | if (!AssimpInited) |
| 704 | { |
| 705 | AssimpInited = true; |
| 706 | LOG(Info, "Assimp {0}.{1}.{2}", aiGetVersionMajor(), aiGetVersionMinor(), aiGetVersionRevision()); |
| 707 | } |
| 708 | bool importMeshes = EnumHasAnyFlags(options.ImportTypes, ImportDataTypes::Geometry); |
| 709 | bool importAnimations = EnumHasAnyFlags(options.ImportTypes, ImportDataTypes::Animations); |
| 710 | AssimpImporterData context(path, options); |
| 711 | |
| 712 | // Setup import flags |
| 713 | unsigned int flags = |
| 714 | aiProcess_JoinIdenticalVertices | |
| 715 | aiProcess_LimitBoneWeights | |
| 716 | aiProcess_Triangulate | |
| 717 | aiProcess_SortByPType | |
| 718 | aiProcess_GenUVCoords | |
| 719 | aiProcess_FindDegenerates | |
| 720 | aiProcess_FindInvalidData | |
| 721 | aiProcess_GlobalScale | |
| 722 | //aiProcess_ValidateDataStructure | |
| 723 | aiProcess_ConvertToLeftHanded; |
| 724 | if (importMeshes) |
| 725 | { |
| 726 | if (options.CalculateNormals) |
| 727 | flags |= aiProcess_FixInfacingNormals | aiProcess_GenSmoothNormals; |
| 728 | if (options.CalculateTangents) |
| 729 | flags |= aiProcess_CalcTangentSpace; |
| 730 | if (options.ReverseWindingOrder) |
| 731 | flags &= ~aiProcess_FlipWindingOrder; |
| 732 | if (options.OptimizeMeshes) |
| 733 | flags |= aiProcess_OptimizeMeshes | aiProcess_SplitLargeMeshes | aiProcess_ImproveCacheLocality; |
| 734 | if (options.MergeMeshes) |
| 735 | flags |= aiProcess_RemoveRedundantMaterials; |
| 736 | } |
| 737 | |
| 738 | // Setup import options |
| 739 | context.AssimpImporter.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, options.SmoothingNormalsAngle); |
| 740 | context.AssimpImporter.SetPropertyFloat(AI_CONFIG_PP_CT_MAX_SMOOTHING_ANGLE, options.SmoothingTangentsAngle); |
| 741 | context.AssimpImporter.SetPropertyFloat(AI_CONFIG_GLOBAL_SCALE_FACTOR_KEY, 100.0f); // Convert to cm |
| 742 | //context.AssimpImporter.SetPropertyInteger(AI_CONFIG_PP_SLM_TRIANGLE_LIMIT, MAX_uint16); |
| 743 | context.AssimpImporter.SetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_CAMERAS, false); |
| 744 | context.AssimpImporter.SetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_LIGHTS, false); |
| 745 | context.AssimpImporter.SetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_TEXTURES, false); |
| 746 | context.AssimpImporter.SetPropertyBool(AI_CONFIG_IMPORT_FBX_READ_ANIMATIONS, importAnimations); |
| 747 | //context.AssimpImporter.SetPropertyBool(AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS, false); // TODO: optimize pivots when https://github.com/assimp/assimp/issues/1068 gets fixed |
| 748 | context.AssimpImporter.SetPropertyBool(AI_CONFIG_IMPORT_FBX_OPTIMIZE_EMPTY_ANIMATION_CURVES, true); |
| 749 | |
| 750 | // Import file |
| 751 | { |
| 752 | AnsiPathTempFile tempFile(path); |
| 753 | context.Scene = context.AssimpImporter.ReadFile(tempFile.Path.Get(), flags); |
| 754 | } |
| 755 | if (context.Scene == nullptr) |
| 756 | { |
| 757 | LOG_STR(Warning, String(context.AssimpImporter.GetErrorString())); |
nothing calls this directly
no test coverage detected