Skip to content

Instantly share code, notes, and snippets.

@phi16
Last active August 1, 2020 07:40
Show Gist options
  • Save phi16/1f043f4b45558f7cc4fdbe85e8f4dfdd to your computer and use it in GitHub Desktop.
Save phi16/1f043f4b45558f7cc4fdbe85e8f4dfdd to your computer and use it in GitHub Desktop.
don't use this without rewriting the `path`
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Events;
using UnityEditor.Animations;
#endif
public class MeshGenerator : MonoBehaviour {
private int vertexCount = 65536;
#if UNITY_EDITOR
private void Generate() {
Mesh m = new Mesh();
m.name = name;
m.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
Vector3[] vertices = new Vector3[vertexCount];
int[] indices = new int[vertices.Length];
for(int i=0;i<vertices.Length;i++) {
vertices[i] = new Vector3(i,0,0);
indices[i] = i;
}
m.vertices = vertices;
m.SetIndices(indices, MeshTopology.Points, 0);
m.bounds = new Bounds(Vector3.zero, Vector3.one * 1000.0f);
string path = $"Assets/Amebient/Mecha/Model/{vertexCount}.asset";
AssetDatabase.CreateAsset(m, path);
AssetDatabase.SaveAssets();
}
[CustomEditor(typeof(MeshGenerator))]
public class MeshGeneratorEditor : Editor {
public override void OnInspectorGUI() {
MeshGenerator g = target as MeshGenerator;
g.vertexCount = EditorGUILayout.IntField("Vertices", g.vertexCount);
if (GUILayout.Button("Generate")) {
g.Generate();
}
}
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment