cubemap贴图转换成6张单独贴图工具

Someone asked if i could add a the ability to separate or extract the images from a LightShape cube map. I decided I would just write up a quick and dirty utility separately.

Instructions:

  1. Put this in a folder called Editor in your assets(Unity)
  2. drag the cubemap you want to separate into the SplitCube spot
  3. set the resolution to the resolution of the cube map you are splitting.(too lazy to auto detect)单独每张图片的分辨率
  4. wait for unity to update the project to reveal the new .png files.

here you go! feel free to make it better.

using UnityEngine;
using UnityEditor;
using System.IO;
using System.Collections;  
using System.Collections.Generic;
 
public class CubeSplitter : EditorWindow
{
    Cubemap splitCube;
    Color[] CubeMapColors;
    int splitSize;
 
    [MenuItem ("Window/CubeSplitter")]
   
    static void Init ()
    {
        CubeSplitter window = (CubeSplitter)EditorWindow.GetWindow (typeof (CubeSplitter), false);
       
        window.maxSize = new Vector2(512, 155);
        window.minSize = window.maxSize;
        window.title  = ("Cube Splitter!");
        window.Show();
 
    }
   
 
   
    void OnGUI ()
    {
 
        GUILayout.Label("Choose the Cube Map you want to save as 6 images and click EXPORT!", EditorStyles.boldLabel);
        splitCube = EditorGUILayout.ObjectField("My Cubemap:", splitCube, typeof(Cubemap), false) as Cubemap;
        GUILayout.Label("Make sure to set the Size to the same as the Cubemap you are using", EditorStyles.boldLabel);
        splitSize = EditorGUILayout.IntField("CubeMap Size: ", splitSize);
 
        if(GUILayout.Button("EXPORT!"))
        {
            if(splitCube)
            {
                Export();
            }
       
            if(!splitCube)
            {
                Debug.Log ("Forget Something?");
            }
        }
    }
 
    void Export()
    {
        var filePath = AssetDatabase.GetAssetPath(splitCube);
 
        Texture2D tex = new Texture2D (splitSize, splitSize, TextureFormat.RGB24, false);
        CubeMapColors = splitCube.GetPixels(CubemapFace.PositiveY);
        tex.SetPixels(CubeMapColors, 0);
 
        tex.Apply ();
 
        byte[] bytes = tex.EncodeToPNG();
        File.WriteAllBytes(filePath + "_Bot.png", bytes);
 
        CubeMapColors = splitCube.GetPixels(CubemapFace.NegativeY);
        tex.SetPixels(CubeMapColors, 0);
       
        tex.Apply ();
       
        bytes = tex.EncodeToPNG();
        File.WriteAllBytes(filePath + "_Top.png", bytes);
 
 
        CubeMapColors = splitCube.GetPixels(CubemapFace.PositiveX);
        tex.SetPixels(CubeMapColors, 0);
       
        tex.Apply ();
       
        bytes = tex.EncodeToPNG();
        File.WriteAllBytes(filePath + "_Lef.png", bytes);
 
 
        CubeMapColors = splitCube.GetPixels(CubemapFace.NegativeX);
        tex.SetPixels(CubeMapColors, 0);
       
        tex.Apply ();
       
        bytes = tex.EncodeToPNG();
        File.WriteAllBytes(filePath + "_Rig.png", bytes);
 
        CubeMapColors = splitCube.GetPixels(CubemapFace.PositiveZ);
        tex.SetPixels(CubeMapColors, 0);
       
        tex.Apply ();
       
        bytes = tex.EncodeToPNG();
        File.WriteAllBytes(filePath + "_Fro.png", bytes);
 
        CubeMapColors = splitCube.GetPixels(CubemapFace.NegativeZ);
        tex.SetPixels(CubeMapColors, 0);
       
        tex.Apply ();
       
        bytes = tex.EncodeToPNG();
        File.WriteAllBytes(filePath + "_Bak.png", bytes);
 
        this.Close();
    }
 
}
 

参考:https://forum.unity.com/threads/cube-map-seperator-here.239101/

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值