idk
This commit is contained in:
56
Assets/jelycho/Code/GutRenderer.cs
Normal file
56
Assets/jelycho/Code/GutRenderer.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Collections;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RealityReboot.jelycho {
|
||||
[ExecuteInEditMode]
|
||||
public class GutRenderer : MonoBehaviour {
|
||||
static readonly List<Vector3> s_worldPositions = new(1024);
|
||||
|
||||
[SerializeField] Rope m_Rope;
|
||||
[SerializeField] Material m_Material;
|
||||
|
||||
[SerializeField] float3[] m_Positions;
|
||||
|
||||
[SerializeField, Range(3, 128)] int m_Resolution = 16;
|
||||
|
||||
|
||||
[SerializeField] Mesh m_Mesh;
|
||||
|
||||
void Update() {
|
||||
if (m_Mesh == null) {
|
||||
m_Mesh = new Mesh {
|
||||
name = "GutMesh",
|
||||
indexFormat = UnityEngine.Rendering.IndexFormat.UInt32
|
||||
};
|
||||
m_Mesh.MarkDynamic();
|
||||
}
|
||||
|
||||
if (m_Positions.Length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
int segmentCount = m_Positions.Length - 1;
|
||||
int vertexCount = m_Resolution * segmentCount;
|
||||
int triangleCount = (segmentCount - 1) * m_Resolution * 2;
|
||||
|
||||
NativeArray<float3> positions = new(vertexCount, Allocator.Temp);
|
||||
NativeArray<float3> normals = new(vertexCount, Allocator.Temp);
|
||||
NativeArray<float2> uvs = new(vertexCount, Allocator.Temp);
|
||||
NativeArray<int> indices = new(triangleCount * 3, Allocator.Temp);
|
||||
|
||||
for (int i = 0; i < m_Positions.Length - 1; i++) {
|
||||
|
||||
}
|
||||
|
||||
m_Mesh.Clear();
|
||||
m_Mesh.SetVertices(positions);
|
||||
m_Mesh.SetNormals(normals);
|
||||
m_Mesh.SetUVs(0, uvs);
|
||||
m_Mesh.SetIndices(indices, MeshTopology.Triangles, 0, false);
|
||||
|
||||
Graphics.DrawMesh(m_Mesh, Matrix4x4.identity, m_Material, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user