This commit is contained in:
2025-04-18 11:36:40 +02:00
parent cc0441e7ea
commit 62d340853d
180 changed files with 1387 additions and 1467 deletions

View 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);
}
}
}