Created
September 26, 2021 13:14
-
-
Save keijiro/46a43b50a4cfecf817ee3641021f3d44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
static class RawToTexture3D | |
{ | |
static Color IntToColor(uint b1, uint b2) | |
=> new Color((b2 + (b1 << 8)) / 65536.0f, 0, 0); | |
[MenuItem("Tool/Raw to Texture3D")] | |
static void ConvertRawToTexture3D() | |
{ | |
var dims = new Vector3Int(256, 256, 113); | |
var data = AssetDatabase | |
.LoadAssetAtPath<TextAsset>("Assets/Editor/CThead.bytes").bytes; | |
var tex = new Texture3D | |
(dims.x, dims.y, dims.z, TextureFormat.RHalf, false); | |
var offs = 0; | |
for (var z = 0; z < dims.z; z++) | |
for (var y = 0; y < dims.y; y++) | |
for (var x = 0; x < dims.x; x++) | |
tex.SetPixel(x, y, z, IntToColor(data[offs++], data[offs++]), 0); | |
tex.Apply(); | |
AssetDatabase.CreateAsset(tex, "Assets/temp.asset"); | |
AssetDatabase.SaveAssets(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment