using System.Collections.Generic; using Unity.Collections; using Unity.Mathematics; using UnityEngine; namespace RealityReboot.jelycho { [ExecuteInEditMode] public class GutRenderer : MonoBehaviour { static readonly List 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 positions = new(vertexCount, Allocator.Temp); NativeArray normals = new(vertexCount, Allocator.Temp); NativeArray uvs = new(vertexCount, Allocator.Temp); NativeArray 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); } } }