summaryrefslogtreecommitdiffstats
path: root/Editor
diff options
context:
space:
mode:
authoryum <yum.food.vr@gmail.com>2025-06-03 18:11:31 -0700
committeryum <yum.food.vr@gmail.com>2025-06-03 18:11:31 -0700
commit1dca0fed44b9c8eb8a6f3131f54c10f1323ed5a8 (patch)
tree5f30c419644af0e45f28a8e6420b576bf26edd94 /Editor
parent3a3860fbb7eda405f3d5f53e28d74d0f73f9c919 (diff)
Add 3d noise generator
Diffstat (limited to 'Editor')
-rw-r--r--Editor/generate_3d_noise.cs117
1 files changed, 117 insertions, 0 deletions
diff --git a/Editor/generate_3d_noise.cs b/Editor/generate_3d_noise.cs
new file mode 100644
index 0000000..437b0aa
--- /dev/null
+++ b/Editor/generate_3d_noise.cs
@@ -0,0 +1,117 @@
+// !! AI ARTIFACT !!
+// This code was originally generated by Claude 3.5 Sonnet.
+using UnityEngine;
+using UnityEditor;
+
+public enum NoiseType
+{
+ OneDimensional,
+ TwoDimensional,
+ ThreeDimensional,
+ FourDimensional,
+ NormalizedThreeDimensional
+}
+
+public class WhiteNoiseTextureGenerator : EditorWindow
+{
+ private int textureWidth = 32;
+ private int textureHeight = 32;
+ private int textureDepth = 32;
+ private string textureName = "WhiteNoiseTexture";
+ private NoiseType noiseType = NoiseType.ThreeDimensional;
+
+ [MenuItem("Tools/yum_food/White Noise Texture Generator")]
+ public static void ShowWindow()
+ {
+ GetWindow<WhiteNoiseTextureGenerator>("White Noise Texture Generator");
+ }
+
+ private void OnGUI()
+ {
+ GUILayout.Label("White Noise Texture Generator", EditorStyles.boldLabel);
+
+ textureWidth = EditorGUILayout.IntField("Texture Width", textureWidth);
+ textureHeight = EditorGUILayout.IntField("Texture Height", textureHeight);
+ textureDepth = EditorGUILayout.IntField("Texture Depth", textureDepth);
+ textureName = EditorGUILayout.TextField("Texture Name", textureName);
+ noiseType = (NoiseType)EditorGUILayout.EnumPopup("Noise Type", noiseType);
+
+ if (GUILayout.Button("Generate Texture"))
+ {
+ if (textureWidth <= 0 || textureHeight <= 0 || textureDepth <= 0)
+ {
+ EditorUtility.DisplayDialog("Error", "Texture dimensions must be greater than zero.", "OK");
+ return;
+ }
+
+ GenerateWhiteNoiseTexture();
+ }
+ }
+
+ private void GenerateWhiteNoiseTexture()
+ {
+ TextureFormat format = GetTextureFormat();
+ Texture3D texture = new Texture3D(textureWidth, textureHeight, textureDepth, format, false);
+ Color[] colors = new Color[textureWidth * textureHeight * textureDepth];
+
+ for (int z = 0; z < textureDepth; z++)
+ {
+ for (int y = 0; y < textureHeight; y++)
+ {
+ for (int x = 0; x < textureWidth; x++)
+ {
+ int index = x + y * textureWidth + z * textureWidth * textureHeight;
+ colors[index] = GenerateColor();
+ }
+ }
+ }
+
+ texture.SetPixels(colors);
+ texture.Apply();
+
+ string path = $"Assets/{textureName}.asset";
+ AssetDatabase.CreateAsset(texture, path);
+ AssetDatabase.SaveAssets();
+ AssetDatabase.Refresh();
+
+ EditorUtility.DisplayDialog("Success", $"White noise texture generated and saved at {path}", "OK");
+ }
+
+ private TextureFormat GetTextureFormat()
+ {
+ switch (noiseType)
+ {
+ case NoiseType.OneDimensional:
+ return TextureFormat.R8;
+ case NoiseType.TwoDimensional:
+ return TextureFormat.RG16;
+ case NoiseType.ThreeDimensional:
+ case NoiseType.NormalizedThreeDimensional:
+ return TextureFormat.RGB48;
+ case NoiseType.FourDimensional:
+ return TextureFormat.RGBA32;
+ default:
+ return TextureFormat.RGB24;
+ }
+ }
+
+ private Color GenerateColor()
+ {
+ switch (noiseType)
+ {
+ case NoiseType.OneDimensional:
+ return new Color(Random.value, 0, 0, 1);
+ case NoiseType.TwoDimensional:
+ return new Color(Random.value, Random.value, 0, 1);
+ case NoiseType.ThreeDimensional:
+ return new Color(Random.value, Random.value, Random.value, 1);
+ case NoiseType.FourDimensional:
+ return new Color(Random.value, Random.value, Random.value, Random.value);
+ case NoiseType.NormalizedThreeDimensional:
+ Vector3 normalizedColor = Random.insideUnitSphere.normalized;
+ return new Color(normalizedColor.x * 0.5f + 0.5f, normalizedColor.y * 0.5f + 0.5f, normalizedColor.z * 0.5f + 0.5f, 1);
+ default:
+ return Color.white;
+ }
+ }
+}