/** * 保存纹理图片相关信息 */ public string SaveTextureFormat(Texture2D tex, string texPath, string matPath, bool closemipmap = false, string ext = "png", bool normal = false) { string name = PathHelper.CheckFileName(tex.name + ".image.json"); MyJson_Tree textureItem = new MyJson_Tree(); var fileName = texPath.Substring(0, texPath.LastIndexOf(".") + 1) + ext; textureItem.SetString("name", PathHelper.CheckFileName(texPath)); textureItem.SetEnum("filterMode", tex.filterMode, true); textureItem.SetEnum("wrap", tex.wrapMode, true); textureItem.SetBool("mipmap", !closemipmap && tex.mipmapCount > 1); if (tex.anisoLevel > 1) { textureItem.SetNumber("anisotropy", tex.anisoLevel); } if (tex.format == TextureFormat.Alpha8) { textureItem.SetString("format", "Gray"); } else if (ext == "jpg" || tex.format == TextureFormat.RGB24 || tex.format == TextureFormat.PVRTC_RGB2 || tex.format == TextureFormat.PVRTC_RGB4 || tex.format == TextureFormat.RGB565 || tex.format == TextureFormat.ETC_RGB4 || tex.format == TextureFormat.ATC_RGB4 || tex.format == TextureFormat.ETC2_RGB || tex.format == TextureFormat.ASTC_RGB_4x4 || tex.format == TextureFormat.ASTC_RGB_5x5 || tex.format == TextureFormat.ASTC_RGB_6x6 || tex.format == TextureFormat.ASTC_RGB_8x8 || tex.format == TextureFormat.ASTC_RGB_10x10 || tex.format == TextureFormat.ASTC_RGB_12x12 ) { textureItem.SetString("format", "RGB"); } textureItem.SetInt("version", 2); //得到.imgdesc.json数据,并保存到bufs中 System.Text.StringBuilder sb = new System.Text.StringBuilder(); textureItem.CovertToStringWithFormat(sb, 4); byte[] bs = System.Text.Encoding.UTF8.GetBytes(sb.ToString()); //相对路径 var imgdescPath = texPath.Substring(0, texPath.LastIndexOf("/") + 1) + name; this.AddFileBuffer(imgdescPath, bs); return(imgdescPath); }
public MyJson_Tree Write() { this.Update(); var customConfig = ExportConfig.instance.IsCustomShader(this.shaderName); // var materialItemJson = new MyJson_Tree(); var extensions = new MyJson_Tree(); materialItemJson.Add("extensions", extensions); var KHR_techniques_webglJson = new MyJson_Tree(); extensions.Add("KHR_techniques_webgl", KHR_techniques_webglJson); var paperJson = new MyJson_Tree(); extensions.Add("paper", paperJson); var valuesJson = new MyJson_Tree(); KHR_techniques_webglJson.Add("values", valuesJson); // var source = this.source; var shaderName = source.shader.name.ToLower(); MyLog.Log("Shader:" + shaderName); foreach (var value in this.values) { valuesJson.Add(value.Key, value.Value); } if (customConfig != null && !string.IsNullOrEmpty(customConfig.technique)) { KHR_techniques_webglJson.SetString("technique", customConfig.technique); } else { KHR_techniques_webglJson.SetString("technique", this.technique); } //paper paperJson.SetInt("renderQueue", this.source.renderQueue); if (this.defines.Count > 0) { var definesJson = new MyJson_Array(); foreach (var define in this.defines) { definesJson.AddString(define); } paperJson.Add("defines", definesJson); } // //standard var isDoubleSide = this.isDoubleSide; var isTransparent = this.isTransparent; var blend = this.blendMode; var statesJson = new MyJson_Tree(); var enable = new MyJson_Array(); if (isDoubleSide || blend != BlendMode.None || isTransparent || (customConfig != null && customConfig.enable != null)) { //states paperJson.Add("states", statesJson); var functionsJson = new MyJson_Tree(); statesJson.Add("enable", enable); statesJson.Add("functions", functionsJson); if (customConfig != null && customConfig.enable != null) { foreach (var value in customConfig.enable) { enable.AddInt(value); } if (customConfig.blendEquationSeparate != null) { this.SetBlendEquationSeparate(functionsJson, customConfig.blendEquationSeparate); } if (customConfig.blendFuncSeparate != null) { this.SetBlendFuncSeparate(functionsJson, customConfig.blendFuncSeparate); } if (customConfig.frontFace != null) { this.SetFrontFace(functionsJson, customConfig.frontFace); } if (customConfig.cullFace != null) { this.SetCullFace(functionsJson, customConfig.cullFace); } if (customConfig.depthFunc != null) { this.SetDepthFunc(functionsJson, customConfig.depthFunc); } if (customConfig.depthMask != null) { this.SetDepthMask(functionsJson, customConfig.depthMask); } } else { this.SetBlend(enable, functionsJson, blend); this.SetCullFace(enable, functionsJson, !isDoubleSide); this.SetDepth(enable, functionsJson, true, !isTransparent); } } return(materialItemJson); }