static void ExtractMaterialsAndTextures(ScriptedImporter self, GltfParser parser) { if (string.IsNullOrEmpty(self.assetPath)) { return; } Action <Texture2D> addRemap = externalObject => { self.AddRemap(new AssetImporter.SourceAssetIdentifier(typeof(UnityEngine.Texture2D), externalObject.name), externalObject); }; Action <IEnumerable <UnityPath> > onCompleted = _ => { AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); self.ExtractMaterials(); AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); }; var assetPath = UnityPath.FromFullpath(parser.TargetPath); var dirName = $"{assetPath.FileNameWithoutExtension}.Textures"; TextureExtractor.ExtractTextures(parser, assetPath.Parent.Child(dirName), GltfTextureEnumerator.Enumerate, self.GetSubAssets <UnityEngine.Texture2D>(self.assetPath).ToArray(), addRemap, onCompleted ); }
static void ExtractMaterialsAndTextures(ScriptedImporter self, GltfParser parser, EnumerateAllTexturesDistinctFunc enumTextures, Func <string, string> textureDir, Func <string, string> materialDir) { if (string.IsNullOrEmpty(self.assetPath)) { return; } Action <SubAssetKey, Texture2D> addRemap = (key, externalObject) => { self.AddRemap(new AssetImporter.SourceAssetIdentifier(key.Type, key.Name), externalObject); }; Action <IEnumerable <UnityPath> > onCompleted = _ => { AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); self.ExtractMaterials(materialDir); AssetDatabase.ImportAsset(self.assetPath, ImportAssetOptions.ForceUpdate); }; var assetPath = UnityPath.FromFullpath(parser.TargetPath); var dirName = textureDir(assetPath.Value); // $"{assetPath.FileNameWithoutExtension}.Textures"; TextureExtractor.ExtractTextures(parser, assetPath.Parent.Child(dirName), enumTextures, self.GetSubAssets <UnityEngine.Texture2D>(self.assetPath).ToArray(), addRemap, onCompleted ); }
protected virtual UnityPath GetAssetPath(UnityPath prefabPath, UnityEngine.Object o) { if (o is Material) { var materialDir = prefabPath.GetAssetFolder(".Materials"); var materialPath = materialDir.Child(o.name.EscapeFilePath() + ".asset"); return(materialPath); } else if (o is Texture2D) { var textureDir = prefabPath.GetAssetFolder(".Textures"); var texturePath = textureDir.Child(o.name.EscapeFilePath() + ".asset"); return(texturePath); } else if (o is Mesh && !MeshAsSubAsset) { var meshDir = prefabPath.GetAssetFolder(".Meshes"); var meshPath = meshDir.Child(o.name.EscapeFilePath() + ".asset"); return(meshPath); } else { return(default(UnityPath)); } }
public static ImporterContext Parse(string path, Byte[] bytes) { var ext = Path.GetExtension(path).ToLower(); var context = new ImporterContext(UnityPath.FromFullpath(path)); switch (ext) { case ".gltf": context.ParseJson(Encoding.UTF8.GetString(bytes), new FileSystemStorage(Path.GetDirectoryName(path))); break; case ".zip": { var zipArchive = Zip.ZipArchiveStorage.Parse(bytes); var gltf = zipArchive.Entries.FirstOrDefault(x => x.FileName.ToLower().EndsWith(".gltf")); if (gltf == null) { throw new Exception("no gltf in archive"); } var jsonBytes = zipArchive.Extract(gltf); var json = Encoding.UTF8.GetString(jsonBytes); context.ParseJson(json, zipArchive); } break; case ".glb": context.ParseGlb(bytes); break; default: throw new NotImplementedException(); } return(context); }
static void ImportDelayed(string src, UnityPath prefabPath, ImporterContext context) { EditorApplication.delayCall += () => { // // After textures imported(To ensure TextureImporter be accessible). // try { context.Load(); context.SaveAsAsset(prefabPath); context.EditorDestroyRoot(); } catch (UniGLTFNotSupportedException ex) { Debug.LogWarningFormat("{0}: {1}", src, ex.Message ); context.EditorDestroyRootAndAssets(); } catch (Exception ex) { Debug.LogErrorFormat("import error: {0}", src); Debug.LogErrorFormat("{0}", ex); context.EditorDestroyRootAndAssets(); } }; }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { foreach (string path in importedAssets) { if (UnityPath.FromUnityPath(path).IsStreamingAsset) { Debug.LogFormat("Skip StreamingAssets: {0}", path); continue; } var ext = Path.GetExtension(path).ToLower(); switch (ext) { case ".gltf": case ".glb": { var gltfPath = UnityPath.FromUnityPath(path); var prefabPath = gltfPath.Parent.Child(gltfPath.FileNameWithoutExtension + ".prefab"); ImportAsset(UnityPath.FromUnityPath(path).FullPath, ext, prefabPath); break; } } } }
static BytesWithMime GetBytesWithMime(Texture texture, glTFTextureTypes textureType) { #if UNITY_EDITOR var path = UnityPath.FromAsset(texture); if (path.IsUnderAssetsFolder) { if (path.Extension == ".png") { return(new BytesWithMime { Bytes = System.IO.File.ReadAllBytes(path.FullPath), Mime = "image/png", }); } if (path.Extension == ".jpg") { return(new BytesWithMime { Bytes = System.IO.File.ReadAllBytes(path.FullPath), Mime = "image/jpeg", }); } } #endif return(new BytesWithMime { Bytes = TextureItem.CopyTexture(texture, TextureIO.GetColorSpace(textureType), null).EncodeToPNG(), Mime = "image/png", }); }
public void SaveTexturesAsPng(UnityPath prefabPath) { TextureBaseDir = prefabPath.Parent; TextureBaseDir.ImportAsset(); // // https://answers.unity.com/questions/647615/how-to-update-import-settings-for-newly-created-as.html // for (int i = 0; i < GLTF.textures.Count; ++i) { var x = GLTF.textures[i]; var image = GLTF.images[x.source]; if (string.IsNullOrEmpty(image.uri)) { // glb buffer var folder = prefabPath.GetAssetFolder(".Textures"); folder.EnsureFolder(); // name & bytes var textureName = !string.IsNullOrEmpty(image.name) ? image.name : string.Format("{0:00}#GLB", i); var byteSegment = GLTF.GetViewBytes(image.bufferView); // path var png = folder.Child(textureName + ".png"); File.WriteAllBytes(png.FullPath, byteSegment.ToArray()); png.ImportAsset(); image.uri = png.Value.Substring(TextureBaseDir.Value.Length + 1); //Debug.LogFormat("image.uri: {0}", image.uri); } } UnityEditor.AssetDatabase.Refresh(); }
/// <summary> /// /// * Texture(.png etc...)をディスクに書き出す /// * EditorApplication.delayCall で処理を進めて 書き出した画像が Asset として成立するのを待つ /// * 書き出した Asset から TextureImporter を取得して設定する /// /// </summary> /// <param name="importer"></param> /// <param name="dirName"></param> /// <param name="onCompleted"></param> public static void ExtractTextures(GltfData data, UnityPath textureDirectory, ITextureDescriptorGenerator textureDescriptorGenerator, IReadOnlyDictionary <SubAssetKey, Texture> subAssets, Action <SubAssetKey, Texture2D> addRemap, Action <IEnumerable <UnityPath> > onCompleted = null) { var extractor = new TextureExtractor(data, textureDirectory, subAssets); foreach (var param in textureDescriptorGenerator.Get().GetEnumerable()) { extractor.Extract(param.SubAssetKey, param); } EditorApplication.delayCall += () => { // Wait for the texture assets to be imported foreach (var(key, targetPath) in extractor.Textures) { // remap var externalObject = targetPath.LoadAsset <Texture2D>(); #if VRM_DEVELOP // Debug.Log($"remap: {targetPath} => {externalObject}"); #endif if (externalObject != null) { addRemap(key, externalObject); } } if (onCompleted != null) { onCompleted(extractor.Textures.Values); } }; }
public TextureExtractor(GltfData data, UnityPath textureDirectory, IReadOnlyDictionary <SubAssetKey, Texture> subAssets) { m_data = data; m_textureDirectory = textureDirectory; m_textureDirectory.EnsureFolder(); m_subAssets = subAssets; }
public virtual bool AvoidOverwriteAndLoad(UnityPath assetPath, UnityEngine.Object o) { if (o is Material) { var loaded = assetPath.LoadAsset <Material>(); // replace component reference foreach (var mesh in Meshes) { foreach (var r in mesh.Renderers) { for (int i = 0; i < r.sharedMaterials.Length; ++i) { if (r.sharedMaterials.Contains(o)) { r.sharedMaterials = r.sharedMaterials.Select(x => x == o ? loaded : x).ToArray(); } } } } return(true); } return(false); }
public TextureExtractor(GltfParser parser, UnityPath textureDirectory, UnityEngine.Texture2D[] subAssets) { m_parser = parser; m_textureDirectory = textureDirectory; m_textureDirectory.EnsureFolder(); m_subAssets = subAssets; }
public void SaveAsAsset(UnityPath prefabPath) { ShowMeshes(); //var prefabPath = PrefabPath; if (prefabPath.IsFileExists) { // clear SubAssets foreach (var x in prefabPath.GetSubAssets().Where(x => !(x is GameObject) && !(x is Component))) { GameObject.DestroyImmediate(x, true); } } // // save sub assets // var paths = new List <UnityPath>() { prefabPath }; foreach (var o in ObjectsForSubAsset()) { if (o == null) { continue; } var assetPath = GetAssetPath(prefabPath, o); if (!assetPath.IsNull) { assetPath.Parent.EnsureFolder(); assetPath.CreateAsset(o); paths.Add(assetPath); } else { // save as subasset prefabPath.AddObjectToAsset(o); } } // Create or upate Main Asset if (prefabPath.IsFileExists) { Debug.LogFormat("replace prefab: {0}", prefabPath); var prefab = prefabPath.LoadAsset <GameObject>(); PrefabUtility.ReplacePrefab(Root, prefab, ReplacePrefabOptions.ReplaceNameBased); } else { Debug.LogFormat("create prefab: {0}", prefabPath); PrefabUtility.CreatePrefab(prefabPath.Value, Root); } foreach (var x in paths) { x.ImportAsset(); } }
/// <summary> /// 画像のバイト列を得る /// </summary> /// <param name="bytes"></param> /// <param name="texture"></param> /// <returns></returns> static (byte[] bytes, string mine) GetBytesWithMime(Texture2D texture) { #if UNITY_EDITOR var path = UnityPath.FromAsset(texture); if (path.IsUnderAssetsFolder) { if (path.Extension == ".png") { return ( System.IO.File.ReadAllBytes(path.FullPath), "image/png" ); } if (path.Extension == ".jpg") { return ( System.IO.File.ReadAllBytes(path.FullPath), "image/jpeg" ); } } #endif return ( texture.EncodeToPNG(), "image/png" ); }
/// <summary> /// /// * Texture(.png etc...)をディスクに書き出す /// * EditorApplication.delayCall で処理を進めて 書き出した画像が Asset として成立するのを待つ /// * 書き出した Asset から TextureImporter を取得して設定する /// /// </summary> /// <param name="importer"></param> /// <param name="dirName"></param> /// <param name="onCompleted"></param> public static void ExtractTextures(GltfParser parser, UnityPath textureDirectory, TextureEnumerator textureEnumerator, Texture2D[] subAssets, Action <Texture2D> addRemap, Action <IEnumerable <UnityPath> > onCompleted = null) { var extractor = new TextureExtractor(parser, textureDirectory, subAssets); foreach (var x in textureEnumerator(parser)) { extractor.Extract(x); } EditorApplication.delayCall += () => { // Wait for the texture assets to be imported foreach (var kv in extractor.Textures) { var targetPath = kv.Key; var param = kv.Value; // remap var externalObject = targetPath.LoadAsset <Texture2D>(); if (externalObject != null) { addRemap(externalObject); } } if (onCompleted != null) { onCompleted(extractor.Textures.Keys); } }; }
public void TextureExtractTest() { var path = GetGltfTestModelPath("BoomBox.glb"); if (path == null) { return; } // parse var data = new GlbFileParser(path.FullName).Parse(); // load using (var context = new ImporterContext(data)) { var instance = context.Load(); var textureMap = instance.RuntimeResources .Select(kv => (kv.Item1, kv.Item2 as Texture)) .Where(kv => kv.Item2 != null) .ToDictionary(kv => kv.Item1, kv => kv.Item2) ; // extractor var extractor = new TextureExtractor(data, UnityPath.FromUnityPath(""), textureMap); var m = context.TextureDescriptorGenerator.Get().GetEnumerable() .FirstOrDefault(x => x.SubAssetKey.Name == "texture_1.standard"); Assert.Catch <NotImplementedException>(() => extractor.Extract(m.SubAssetKey, m)); } }
public void CreateTextureItems(UnityPath imageBaseDir = default(UnityPath)) { if (m_textures.Any()) { return; } for (int i = 0; i < GLTF.textures.Count; ++i) { TextureItem item = null; #if UNITY_EDITOR var image = GLTF.GetImageFromTextureIndex(i); if (imageBaseDir.IsUnderAssetsFolder && !string.IsNullOrEmpty(image.uri) && !image.uri.StartsWith("data:") ) { /// /// required SaveTexturesAsPng or SetTextureBaseDir /// var assetPath = imageBaseDir.Child(image.uri); var textureName = !string.IsNullOrEmpty(image.name) ? image.name : Path.GetFileNameWithoutExtension(image.uri); item = new TextureItem(i, assetPath, textureName); } else #endif { item = new TextureItem(i); } AddTexture(item); } }
public void TextureExtractTest() { var path = GetGltfTestModelPath("BoomBox.glb"); if (path == null) { return; } // parse var parser = new GltfParser(); parser.ParsePath(path.FullName); // load var loader = new ImporterContext(parser); loader.Load(); // extractor var extractor = new TextureExtractor(parser, UnityPath.FromUnityPath(""), loader.TextureFactory.Textures.Select(x => (new SubAssetKey(typeof(Texture2D), x.Texture.name), x.Texture)).ToArray()); var m = GltfTextureEnumerator.EnumerateTexturesReferencedByMaterials(parser, 0).FirstOrDefault(x => x.Item1.Name == "texture_1.standard"); Assert.Catch <NotImplementedException>(() => extractor.Extract(m.Item1, m.Item2)); }
public virtual (Byte[] bytes, string mine) GetBytesWithMime(Texture texture, glTFTextureTypes textureType) { #if UNITY_EDITOR var path = UnityPath.FromAsset(texture); if (path.IsUnderAssetsFolder) { var textureImporter = AssetImporter.GetAtPath(path.Value) as TextureImporter; var getSizeMethod = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance); if (textureImporter != null && getSizeMethod != null) { var args = new object[2] { 0, 0 }; getSizeMethod.Invoke(textureImporter, args); var originalWidth = (int)args[0]; var originalHeight = (int)args[1]; var originalSize = Mathf.Max(originalWidth, originalHeight); var requiredMaxSize = textureImporter.maxTextureSize; // Resized exporting if MaxSize setting value is smaller than original image size. if (originalSize > requiredMaxSize) { return ( TextureConverter.CopyTexture(texture, GetColorSpace(textureType), null).EncodeToPNG(), "image/png" ); } } if (path.Extension == ".png") { return ( System.IO.File.ReadAllBytes(path.FullPath), "image/png" ); } if (path.Extension == ".jpg") { return ( System.IO.File.ReadAllBytes(path.FullPath), "image/jpeg" ); } } #endif return ( TextureConverter.CopyTexture(texture, TextureIO.GetColorSpace(textureType), null).EncodeToPNG(), "image/png" ); }
public static void IntegrateSelected() { var go = Selection.activeObject as GameObject; var meshWithMaterials = Integrate(go.transform); // save as asset var assetPath = ""; #if UNITY_2018_2_OR_NEWER var prefab = PrefabUtility.GetCorrespondingObjectFromSource(go); #else var prefab = PrefabUtility.GetPrefabParent(go); #endif if (prefab != null) { var prefabPath = AssetDatabase.GetAssetPath(prefab); assetPath = string.Format("{0}/{1}_{2}{3}", Path.GetDirectoryName(prefabPath), Path.GetFileNameWithoutExtension(prefabPath), go.name, ASSET_SUFFIX ); } else { var path = EditorUtility.SaveFilePanel( "Save mesh", "Assets", go.name + ".asset", "asset"); if (string.IsNullOrEmpty(path)) { return; } assetPath = UnityPath.FromFullpath(path).Value; } assetPath = AssetDatabase.GenerateUniqueAssetPath(assetPath); Debug.LogFormat("CreateAsset: {0}", assetPath); AssetDatabase.CreateAsset(meshWithMaterials.Mesh, assetPath); // add component var meshObject = new GameObject(go.name + ".integrated"); if (go.transform.parent != null) { meshObject.transform.SetParent(go.transform.parent, false); } meshObject.transform.localPosition = go.transform.localPosition; meshObject.transform.localRotation = go.transform.localRotation; meshObject.transform.localScale = go.transform.localScale; var filter = meshObject.AddComponent <MeshFilter>(); filter.sharedMesh = meshWithMaterials.Mesh; var renderer = meshObject.AddComponent <MeshRenderer>(); renderer.sharedMaterials = meshWithMaterials.Materials; }
public static void Import(UnityPath gltfPath) { if (!gltfPath.IsUnderAssetsFolder) { throw new Exception(); } ImporterContext context = new ImporterContext(gltfPath); var ext = gltfPath.Extension.ToLower(); try { var prefabPath = gltfPath.Parent.Child(gltfPath.FileNameWithoutExtension + ".prefab"); if (ext == ".gltf") { context.ParseJson(File.ReadAllText(gltfPath.FullPath, System.Text.Encoding.UTF8), new FileSystemStorage(gltfPath.Parent.FullPath)); gltfImporter.Load(context); context.SaveAsAsset(prefabPath); context.Destroy(false); } else if (ext == ".glb") { context.ParseGlb(File.ReadAllBytes(gltfPath.FullPath)); context.SaveTexturesAsPng(prefabPath); EditorApplication.delayCall += () => { // delay and can import png texture gltfImporter.Load(context); context.SaveAsAsset(prefabPath); context.Destroy(false); }; } else { return; } } catch (UniGLTFNotSupportedException ex) { Debug.LogWarningFormat("{0}: {1}", gltfPath, ex.Message ); } catch (Exception ex) { Debug.LogErrorFormat("import error: {0}", gltfPath); Debug.LogErrorFormat("{0}", ex); if (context != null) { context.Destroy(true); } } }
public void Dispose() { // end m_w.Write(@" } // class } // namespace "); m_w.Dispose(); m_s.Dispose(); UnityPath.FromFullpath(m_path).ImportAsset(); }
public static Task <Texture2D> LoadTaskAsync(UnityPath m_assetPath, glTF gltf, int textureIndex) { var textureType = TextureIO.GetglTFTextureType(gltf, textureIndex); var colorSpace = TextureIO.GetColorSpace(textureType); var isLinear = colorSpace == RenderTextureReadWrite.Linear; var sampler = gltf.GetSamplerFromTextureIndex(textureIndex); // // texture from assets // m_assetPath.ImportAsset(); var importer = m_assetPath.GetImporter <UnityEditor.TextureImporter>(); if (importer == null) { Debug.LogWarningFormat("fail to get TextureImporter: {0}", m_assetPath); } else { importer.maxTextureSize = 8192; importer.sRGBTexture = !isLinear; importer.SaveAndReimport(); } var Texture = m_assetPath.LoadAsset <Texture2D>(); if (Texture == null) { Debug.LogWarningFormat("fail to Load Texture2D: {0}", m_assetPath); } else { var maxSize = Mathf.Max(Texture.width, Texture.height); importer.maxTextureSize = maxSize > 4096 ? 8192 : maxSize > 2048 ? 4096 : maxSize > 1024 ? 2048 : maxSize > 512 ? 1024 : 512; importer.SaveAndReimport(); } if (sampler != null) { TextureSamplerUtil.SetSampler(Texture, sampler); } return(Task.FromResult(Texture)); }
/// <summary> /// 画像のバイト列を得る /// </summary> /// <param name="bytes"></param> /// <param name="texture"></param> /// <returns></returns> static (byte[] bytes, string mine) GetBytesWithMime(Texture2D texture) { #if UNITY_EDITOR var path = UnityPath.FromAsset(texture); if (path.IsUnderAssetsFolder) { if (path.Extension == ".png") { return ( System.IO.File.ReadAllBytes(path.FullPath), "image/png" ); } if (path.Extension == ".jpg") { return ( System.IO.File.ReadAllBytes(path.FullPath), "image/jpeg" ); } } #endif try { var png = texture.EncodeToPNG(); if (png != null) { return(png, "image/png"); } } catch (Exception ex) { // fail to EncodeToPng // System.ArgumentException: not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings. Debug.LogWarning(ex); } { // try copy and EncodeToPng var copy = TextureConverter.CopyTexture(texture, TextureImportTypes.sRGB, null); var png = copy.EncodeToPNG(); UnityEngine.Object.DestroyImmediate(copy); return(png, "image/png"); } }
static void Import(string readPath, UnityPath prefabPath) { var bytes = File.ReadAllBytes(readPath); var context = gltfImporter.Parse(readPath, bytes); context.SaveTexturesAsPng(prefabPath); EditorApplication.delayCall += () => { // delay and can import png texture gltfImporter.Load(context); context.SaveAsAsset(prefabPath); context.Destroy(false); }; }
public TextureItem(glTF gltf, int index, UnityPath textureBase = default(UnityPath)) { m_textureIndex = index; var image = gltf.GetImageFromTextureIndex(m_textureIndex); #if UNITY_EDITOR if (!string.IsNullOrEmpty(image.uri) && !image.uri.StartsWith("data:") && textureBase.IsUnderAssetsFolder) { m_assetPath = textureBase.Child(image.uri); m_textureName = !string.IsNullOrEmpty(image.name) ? image.name : Path.GetFileNameWithoutExtension(image.uri); } #endif }
public void Prepare(UniGLTF.glTF gltf, UnityPath imageBaseDir = default(UnityPath)) { if (m_textures.Count == 0) { // // runtime // CreateTextureItems(gltf, imageBaseDir); } else { // // already CreateTextures(by assetPostProcessor or editor menu) // } }
/// <summary> /// Extract images from glb or gltf out of Assets folder. /// </summary> /// <param name="prefabPath"></param> public void ExtranctImages(UnityPath prefabPath) { var prefabParentDir = prefabPath.Parent; // glb buffer var folder = prefabPath.GetAssetFolder(".Textures"); // // https://answers.unity.com/questions/647615/how-to-update-import-settings-for-newly-created-as.html // int created = 0; //for (int i = 0; i < GLTF.textures.Count; ++i) for (int i = 0; i < GLTF.images.Count; ++i) { folder.EnsureFolder(); //var x = GLTF.textures[i]; var image = GLTF.images[i]; var src = Storage.GetPath(image.uri); if (UnityPath.FromFullpath(src).IsUnderAssetsFolder) { // asset is exists. } else { string textureName; var byteSegment = GLTF.GetImageBytes(Storage, i, out textureName); // path var dst = folder.Child(textureName + image.GetExt()); File.WriteAllBytes(dst.FullPath, byteSegment.ToArray()); dst.ImportAsset(); // make relative path from PrefabParentDir image.uri = dst.Value.Substring(prefabParentDir.Value.Length + 1); ++created; } } if (created > 0) { AssetDatabase.Refresh(); } CreateTextureItems(prefabParentDir); }
/// <summary> /// Extract images from glb or gltf out of Assets folder. /// </summary> /// <param name="prefabPath"></param> public void ExtractImages(UnityPath prefabPath) { var prefabParentDir = prefabPath.Parent; // glb buffer var folder = prefabPath.GetAssetFolder(".Textures"); // // https://answers.unity.com/questions/647615/how-to-update-import-settings-for-newly-created-as.html // int created = 0; for (int i = 0; i < m_context.GLTF.textures.Count; ++i) { folder.EnsureFolder(); var gltfTexture = m_context.GLTF.textures[i]; var gltfImage = m_context.GLTF.images[gltfTexture.source]; var src = m_context.Storage.GetPath(gltfImage.uri); if (UnityPath.FromFullpath(src).IsUnderAssetsFolder) { // asset is exists. } else { var byteSegment = m_context.GLTF.GetImageBytes(m_context.Storage, gltfTexture.source); var textureName = gltfTexture.name; // path var dst = folder.Child(textureName + gltfImage.GetExt()); File.WriteAllBytes(dst.FullPath, byteSegment.ToArray()); dst.ImportAsset(); // make relative path from PrefabParentDir gltfImage.uri = dst.Value.Substring(prefabParentDir.Value.Length + 1); ++created; } } if (created > 0) { AssetDatabase.Refresh(); } // texture will load from assets m_context.TextureFactory.ImageBaseDir = prefabParentDir; }
static void GenerateSerializer() { var info = new ObjectSerialization(typeof(glTF), "gltf", "Deserialize_"); Debug.Log(info); using (var s = File.Open(OutPath, FileMode.Create)) using (var w = new StreamWriter(s, new UTF8Encoding(false))) { w.Write(Begin); info.GenerateDeserializer(w, "Deserialize"); w.Write(End); } Debug.LogFormat("write: {0}", OutPath); UnityPath.FromFullpath(OutPath).ImportAsset(); }