This commit is contained in:
2025-06-03 20:34:16 +02:00
parent 62cb740f69
commit 0abddece7e
3 changed files with 68 additions and 46 deletions

View File

@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Profiling;
namespace RealityReboot.jelycho {
[ExecuteInEditMode]
@@ -19,12 +19,50 @@ namespace RealityReboot.jelycho {
[SerializeField] Mesh m_Mesh;
[SerializeField, Header("Debug")]
bool m_ShowPositions = false;
void Update() {
if (m_Mesh == null) {
Profiler.BeginSample("GutRenderer.GenerateMesh");
GenerateMesh();
Profiler.EndSample();
Graphics.DrawMesh(m_Mesh, Matrix4x4.identity, m_Material, 0);
}
void OnDrawGizmos() {
Gizmos.color = Color.white;
for (int i = 0; i < m_Resolution; ++i) {
float angle = (float)i / m_Resolution * math.PI * 2.0f;
float3 pos = new(math.cos(angle), 0, math.sin(angle));
Gizmos.DrawSphere(pos, 0.1f);
}
if (m_ShowPositions) {
if (m_Positions.Length < 2) {
return;
}
for (int i = 0; i < m_Positions.Length - 1; i++) {
Gizmos.color = Color.white;
Gizmos.DrawLine(m_Positions[i], m_Positions[i + 1]);
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(m_Positions[i], m_Radius);
}
Gizmos.DrawSphere(m_Positions[m_Positions.Length - 1], 0.1f);
}
}
void GenerateMesh() {
if (m_Mesh is null) {
m_Mesh = new Mesh {
name = "GutMesh",
indexFormat = UnityEngine.Rendering.IndexFormat.UInt32
};
m_Mesh.MarkDynamic();
}
@@ -49,10 +87,11 @@ namespace RealityReboot.jelycho {
float startV1 = (float)(i + 1) / (m_Positions.Length - 1);
for (int j = 0; j < m_Resolution - 1; j++) {
float t0 = (float)j / (m_Resolution - 1);
float t1 = (float)(j + 1) / (m_Resolution - 1);
float angle0 = math.lerp(0, math.PI * 2, t0);
float angle1 = math.lerp(0, math.PI * 2, t1);
float t0 = (float)j / m_Resolution;
float t1 = (float)(j + 1) / m_Resolution;
float angle0 = (float)j / m_Resolution * math.PI * 2.0f;
float angle1 = (float)(j + 1) / m_Resolution * math.PI * 2.0f;
float3 offset0 = new float3(math.cos(angle0), 0.0f, math.sin(angle0)) * m_Radius;
float3 offset1 = new float3(math.cos(angle1), 0.0f, math.sin(angle1)) * m_Radius;
@@ -89,24 +128,6 @@ namespace RealityReboot.jelycho {
m_Mesh.SetNormals(normals.AsArray());
m_Mesh.SetUVs(0, uvs.AsArray());
m_Mesh.SetIndices(indices.AsArray(), MeshTopology.Triangles, 0, false);
Graphics.DrawMesh(m_Mesh, Matrix4x4.identity, m_Material, 0);
}
void OnDrawGizmos() {
if (m_Positions.Length < 2) {
return;
}
for (int i = 0; i < m_Positions.Length - 1; i++) {
Gizmos.color = Color.white;
Gizmos.DrawLine(m_Positions[i], m_Positions[i + 1]);
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(m_Positions[i], 0.1f);
}
Gizmos.DrawSphere(m_Positions[m_Positions.Length - 1], 0.1f);
}
}
}

21
Assets/jelycho/Worlds/dev/scn_map_dev.unity Executable file → Normal file

File diff suppressed because one or more lines are too long