| 31 | #include "AssetsImportingManager.h" |
| 32 | |
| 33 | bool ImportModel::TryGetImportOptions(const StringView& path, Options& options) |
| 34 | { |
| 35 | if (FileSystem::FileExists(path)) |
| 36 | { |
| 37 | // Try to load asset file and asset info |
| 38 | auto tmpFile = ContentStorageManager::GetStorage(path); |
| 39 | AssetInitData data; |
| 40 | if (tmpFile |
| 41 | && tmpFile->GetEntriesCount() == 1 |
| 42 | && ( |
| 43 | (tmpFile->GetEntry(0).TypeName == Model::TypeName && !tmpFile->LoadAssetHeader(0, data) && data.SerializedVersion >= 4) |
| 44 | || |
| 45 | (tmpFile->GetEntry(0).TypeName == SkinnedModel::TypeName && !tmpFile->LoadAssetHeader(0, data) && data.SerializedVersion >= 1) |
| 46 | || |
| 47 | (tmpFile->GetEntry(0).TypeName == Animation::TypeName && !tmpFile->LoadAssetHeader(0, data) && data.SerializedVersion >= 1) |
| 48 | )) |
| 49 | { |
| 50 | // Check import meta |
| 51 | rapidjson_flax::Document metadata; |
| 52 | metadata.Parse((const char*)data.Metadata.Get(), data.Metadata.Length()); |
| 53 | if (metadata.HasParseError() == false) |
| 54 | { |
| 55 | options.Deserialize(metadata, nullptr); |
| 56 | return true; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | else |
| 61 | { |
| 62 | // Try model prefab |
| 63 | String pathPrefab = String(StringUtils::GetPathWithoutExtension(path)) + DEFAULT_PREFAB_EXTENSION_DOT; |
| 64 | if (FileSystem::FileExists(pathPrefab)) |
| 65 | { |
| 66 | auto prefab = Content::Load<Prefab>(pathPrefab); |
| 67 | if (prefab) |
| 68 | { |
| 69 | for (const auto& e : prefab->ObjectsDataCache) |
| 70 | { |
| 71 | auto importOptionsMember = e.Value->FindMember("ImportOptions"); |
| 72 | if (importOptionsMember != e.Value->MemberEnd() && importOptionsMember->value.IsObject()) |
| 73 | { |
| 74 | options.Deserialize(*(ISerializable::DeserializeStream*)&importOptionsMember->value, nullptr); |
| 75 | return true; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | struct PrefabObject |
| 85 | { |
nothing calls this directly
no test coverage detected