private static GameObject DoImport(string gltfPath, PolyImportOptions options, bool savePrefab = false) { var text = File.ReadAllText(gltfPath); GltfSchemaVersion version; if (text.Contains("\"version\": \"1")) { version = GltfSchemaVersion.GLTF1; } else if (text.Contains("\"version\": \"2")) { version = GltfSchemaVersion.GLTF2; } else { // well, just guess I suppose... it's just test code version = GltfSchemaVersion.GLTF1; } Debug.LogFormat("Import {0} as {1}", gltfPath, version); IUriLoader binLoader = new BufferedStreamLoader(Path.GetDirectoryName(gltfPath)); using (TextReader reader = new StreamReader(gltfPath)) { var result = ImportGltf.Import(version, reader, binLoader, options); if (savePrefab) { SaveAsSinglePrefab(result, Path.ChangeExtension(gltfPath, ".prefab")); } return(result.root); } }
public static void TestSaveAsSinglePrefab() { IUriLoader binLoader = new BufferedStreamLoader(Path.GetDirectoryName(Path.Combine(RepoRoot, kMoto))); ImportGltf.GltfImportResult result = null; using (TextReader reader = new StreamReader(Path.Combine(RepoRoot, kMoto))) { result = ImportGltf.Import(GltfSchemaVersion.GLTF1, reader, binLoader, PolyImportOptions.Default()); } string prefabPath = "Assets/Poly/TestData/single_p.prefab"; SaveAsSinglePrefab(result, prefabPath); GameObject.DestroyImmediate(result.root); }
public static void TestSaveAsSeparateWithMeshesInAsset() { IUriLoader binLoader = new BufferedStreamLoader(Path.GetDirectoryName(Path.Combine(RepoRoot, kAllBrush10))); ImportGltf.GltfImportResult result = null; using (TextReader reader = new StreamReader(Path.Combine(RepoRoot, kAllBrush10))) { result = ImportGltf.Import(GltfSchemaVersion.GLTF1, reader, binLoader, PolyImportOptions.Default()); } string assetPath = "Assets/Poly/TestData/separate_a.asset"; string prefabPath = "Assets/Poly/TestData/separate_p.prefab"; SaveAsSeparateWithMeshesInAsset(result, assetPath, prefabPath); GameObject.DestroyImmediate(result.root); }