Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@keijiro
Created September 26, 2021 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keijiro/46a43b50a4cfecf817ee3641021f3d44 to your computer and use it in GitHub Desktop.
Save keijiro/46a43b50a4cfecf817ee3641021f3d44 to your computer and use it in GitHub Desktop.
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