protected override JSONObject ExportResource(ExportPreset preset) { Cubemap cubemap = _cubemap; JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); jsonFile.AddField("desc", TextureUtil.getMeta(cubemap)); JSONObject m_files = new JSONObject(JSONObject.Type.OBJECT); TextureUtil.EnumTexFileExt ext = TextureUtil.ResolveFileExt(cubemap.format); for (int i = 0; i < 6; i++) { Texture2D texture2D = DuplicateTexture(cubemap, i); m_files.AddField( faceNames[i], AddFile( new WXCubeMapTextureImage(texture2D, ext, faceNames[i], unityAssetPath) ) ); } jsonFile.AddField("files", m_files); jsonFile.AddField("version", 2); return(jsonFile); }
protected override JSONObject ExportResource(ExportPreset preset) { if (string.IsNullOrEmpty(unityAssetPath)) { Debug.LogError("Baked reflection probe null."); return(null); } JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); jsonFile.AddField("desc", TextureUtil.getMeta(envMap)); JSONObject m_files = new JSONObject(JSONObject.Type.OBJECT); // get file type TextureUtil.EnumTexFileExt ext = TextureUtil.ResolveFileExt(envMap.format); for (int i = 0; i < 6; i++) { Texture2D texture2D = DuplicateTexture(envMap, i); Texture2D flipV2D = VerticalFlipTexture(texture2D); m_files.AddField( faceNames[i], AddFile( new WXCubeMapTextureImage(flipV2D, ext, faceNames[i], unityAssetPath) ) ); } jsonFile.AddField("files", m_files); jsonFile.AddField("version", 2); return(jsonFile); }
public WXCubeMapTextureImage( Texture2D texture, TextureUtil.EnumTexFileExt ext, string faceName, string texturePath ) : base(texturePath) { this.ext = ext; this.texture = texture; this.faceName = faceName; }
protected override JSONObject ExportResource(ExportPreset preset) { Cubemap cubemap = _cubemap; JSONObject jsonFile = new JSONObject(JSONObject.Type.OBJECT); jsonFile.AddField("desc", TextureUtil.getMeta(cubemap)); JSONObject m_files = new JSONObject(JSONObject.Type.OBJECT); TextureUtil.EnumTexFileExt ext = TextureUtil.ResolveFileExt(cubemap.format); for (int i = 0; i < 6; i++) { Texture2D texture2D = DuplicateTexture(cubemap, i); /* * this behavior is by design: if we speak about cubemaps they are intended to be sampled for reflection, * i.e. with reflection vector, which means that we "want" image to be flipped both vert/horz * and this is exactly what cubemap inspector does with images you assign to slots. * When you copy textures you will get "mirrored" reflection (and you can see this in the preview too) */ if (faceNames[i] != "top" && faceNames[i] != "bottom") { Color[] colors = texture2D.GetPixels(0, 0, texture2D.width, texture2D.height); System.Array.Reverse(colors, 0, colors.Length); Texture2D t = new Texture2D(texture2D.width, texture2D.height, texture2D.format, true); //Debug.Log("Pixel size:" + capx + " " + capy + " " + capwidth + " " + capheight); //t.ReadPixels(new Rect(capx, capy, capwidth, capheight), 0, 0, false); t.SetPixels(colors); t.Apply(); texture2D = t; } m_files.AddField( faceNames[i], AddFile( new WXCubeMapTextureImage(texture2D, ext, faceNames[i], path) ) ); } jsonFile.AddField("files", m_files); jsonFile.AddField("version", 2); return(jsonFile); }