public static void SetAnimation(this MyJson_Object jsonNode, GameObject obj, UnityEngine.AnimationClip[] animationClips) { var exportAnimations = new MyJson_Array(); jsonNode["_animations"] = exportAnimations; foreach (var animationClip in animationClips) { var gltfHash = animationClip.GetInstanceID(); var url = UnityEditor.AssetDatabase.GetAssetPath(animationClip); url = url.Substring(0, url.LastIndexOf(".")) + "_" + animationClip.name + ".ani.bin"; url = PathHelper.CheckFileName(url); // var assetIndex = ResourceManager.instance.AddAssetUrl(url); if (!ResourceManager.instance.HaveCache(gltfHash)) { var glTFWriter = new AnimationXWriter(obj.transform, animationClip); ResourceManager.instance.AddFileBuffer(url, glTFWriter.WriteGLTF()); // ResourceManager.instance.SaveCache(gltfHash, url); } var aniItem = new MyJson_Tree(); aniItem.SetInt("asset", assetIndex); exportAnimations.Add(aniItem); } }
protected void AddCurve(MyJson_Tree curveItem, string key, Keyframe[] keys) { MyJson_Array frmes = new MyJson_Array(); foreach (Keyframe k in keys) { MyJson_Array keyItem = new MyJson_Array(); keyItem.AddNumber(k.time); keyItem.AddNumber(k.value); frmes.Add(keyItem); } curveItem[key] = frmes; }
public override byte[] WriteGLTF() { var target = this._target; var gltfJson = new MyJson_Tree(); // var assetJson = new MyJson_Tree(); assetJson.SetInt("version", 2); gltfJson.Add("asset", assetJson); var materialsJson = new MyJson_Array(); gltfJson.Add("materials", materialsJson); var extensionsRequired = new MyJson_Array(); extensionsRequired.AddString("KHR_techniques_webgl"); extensionsRequired.AddString("paper"); gltfJson.Add("extensionsRequired", extensionsRequired); var extensionsUsed = new MyJson_Array(); extensionsUsed.AddString("KHR_techniques_webgl"); extensionsUsed.AddString("paper"); gltfJson.Add("extensionsUsed", extensionsUsed); // gltfJson.SetInt("version", 4); //Unifrom or Defines var materialType = this.GetMaterialType(); var writer = MaterialWriterFactory.Create(materialType, target); var materialItemJson = writer.Write(); materialsJson.Add(materialItemJson); writer.Clean(); // gltfJson.isWithFormat = true; var jsonStr = gltfJson.ToString(); return(System.Text.Encoding.UTF8.GetBytes(jsonStr)); }
private static MyJson_Array AddLightmaps(string exportPath) { var lightmapsJson = new MyJson_Array(); foreach (var lightmapData in LightmapSettings.lightmaps) { Texture2D lmTexture = lightmapData.lightmapColor; int lmID = lmTexture.GetInstanceID(); if (!ResourceManager.instance.HaveCache(lmID)) { //格式转换 string suffix = "png"; string relativePath = UnityEditor.AssetDatabase.GetAssetPath(lmTexture); MyLog.Log("导出lightmap:" + relativePath); string exrPath = Path.Combine(Application.dataPath, relativePath.Replace("Assets/", "")); string ralPngPath = PathHelper.CheckFileName(relativePath.Substring(0, relativePath.LastIndexOf('/') + 1) + lmTexture.name + "." + suffix); string pngPath = PathHelper.CheckFileName(Path.Combine(exportPath, ralPngPath)); // string ralPngPath = relativePath.Substring(0, relativePath.LastIndexOf('/') + 1) + lmTexture.name + "." + suffix; // string pngPath = Path.Combine(exportPath, ralPngPath); exrPath = exrPath.Replace("\\", "/"); pngPath = pngPath.Replace("\\", "/"); var bs = ExportImageTools.instance.EncodeToPNG(lmTexture); ResourceManager.instance.AddFileBuffer(ralPngPath, bs); // ExportImageTools.instance.AddExr(exrPath, pngPath); //添加到 compList 和 assetsList ResourceManager.instance.SaveTextureFormat(lmTexture, ralPngPath, ralPngPath + ".image", false); string name = lmTexture.name + ".image.json"; var imgdescPath = PathHelper.CheckFileName(ralPngPath.Substring(0, ralPngPath.LastIndexOf("/") + 1) + name); var assetIndex = ResourceManager.instance.AddAssetUrl(imgdescPath); var assetItem = new MyJson_Tree(); assetItem.SetInt("asset", assetIndex); lightmapsJson.Add(assetItem); } } // ExportImageTools.instance.ExrToPng(); return(lightmapsJson); }
public static void SetMaterials(this MyJson_Object jsonNode, GameObject obj, Material[] materials, bool isParticleMat = false, bool isAnimationMat = false) { var materialsItem = new MyJson_Array(); jsonNode["_materials"] = materialsItem; //写材质 foreach (var material in materials) { if (!material) { Debug.LogWarning(obj.gameObject.name + " 材质缺失,请检查资源"); continue; } int hash = material.GetInstanceID(); string url = ResourceManager.instance.SaveMaterial(material, isParticleMat, isAnimationMat); var assetIndex = ResourceManager.instance.AddAssetUrl(url); var matItem = new MyJson_Tree(); matItem.SetInt("asset", assetIndex); materialsItem.Add(matItem); } }
public override bool WriteToJson(GameObject obj, Component component, MyJson_Object compJson) { FB.PosePlus.AniPlayer comp = component as FB.PosePlus.AniPlayer; var animationsItem = new MyJson_Array(); compJson["_animations"] = animationsItem; var animator = obj.GetComponent <Animator>(); if (comp.clips.Count > 0 && animator != null) { int gltfHash = animator.runtimeAnimatorController.GetInstanceID(); string url = ResourceManager.instance.SaveAniPlayer(comp, animator); var assetIndex = ResourceManager.instance.AddAssetUrl(url); var aniItem = new MyJson_Tree(); aniItem.SetInt("asset", assetIndex); animationsItem.Add(aniItem); } return(true); }
protected void AddGradient(MyJson_Tree gradientItem, string key, Gradient gradient) { //alpha和color过渡值最大为4,如果不够手动填充,如果超过,中间的截掉 GradientAlphaKey[] alphaKeys = this.FillGradientAlpha(gradient); GradientColorKey[] colorKeys = this.FillGradientColor(gradient); MyJson_Tree gradients = new MyJson_Tree(false); gradients.SetEnum("mode", gradient.mode); var alphaKeysItem = new MyJson_Array(); var colorKeysItem = new MyJson_Array(); gradients["alphaKeys"] = alphaKeysItem; gradients["colorKeys"] = colorKeysItem; //alphaKey foreach (GradientAlphaKey _ak in alphaKeys) { MyJson_Tree akItem = new MyJson_Tree(false); int akHash = akItem.GetHashCode(); akItem.SetNumber("alpha", _ak.alpha); akItem.SetNumber("time", _ak.time); alphaKeysItem.Add(akItem); } //colorKey foreach (GradientColorKey _ck in colorKeys) { MyJson_Tree ckItem = new MyJson_Tree(false); int ckHash = ckItem.GetHashCode(); ckItem.SetColor("color", _ck.color); ckItem.SetNumber("time", _ck.time); colorKeysItem.Add(ckItem); } gradientItem[key] = gradients; }
public static void AddString(this MyJson_Array array, string value) { array.Add(new MyJson_String(value)); }
public static void AddHashCode(this MyJson_Array array, UnityEngine.Object value) { array.Add(new MyJson_HashCode(value.GetInstanceID())); }
public static void AddNumber(this MyJson_Array array, double value, int?digits = null) { array.Add(new MyJson_Number(Math.Round(value, digits ?? ExportToolsSetting.instance.floatRoundDigits))); }
public static void AddInt(this MyJson_Array array, int value) { array.Add(new MyJson_Number(value)); }
public static void AddBool(this MyJson_Array array, bool value) { array.Add(new MyJson_Number(value)); }