升级水插件

This commit is contained in:
2026-01-08 22:30:55 +08:00
parent febff82d24
commit ca68084264
415 changed files with 18138 additions and 7134 deletions

View File

@@ -1,8 +1,9 @@
// Crest Water System
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
using UnityEngine;
using WaveHarmonic.Crest.Internal;
using WaveHarmonic.Crest.Utility;
namespace WaveHarmonic.Crest
{
@@ -84,60 +85,46 @@ namespace WaveHarmonic.Crest
}
}
if (_UseDisplacements)
var success = _UseDisplacements
? collProvider.RetrieveSucceeded(collProvider.Query(GetHashCode(), _ObjectWidth, _SamplePositions, _ResultDisplacements, _UseNormals ? _ResultNormals : null, null, _Layer))
: collProvider.RetrieveSucceeded(collProvider.Query(GetHashCode(), _ObjectWidth, _SamplePositions, _ResultHeights, _UseNormals ? _ResultNormals : null, null, _Layer));
#if !UNITY_EDITOR
// Gizmos handle this in editor.
if (success)
{
if (collProvider.RetrieveSucceeded(collProvider.Query(GetHashCode(), _ObjectWidth, _SamplePositions, _ResultDisplacements, _UseNormals ? _ResultNormals : null, null, _Layer)))
{
for (var i = 0; i < _Steps; i++)
{
for (var j = 0; j < _Steps; j++)
{
var result = _SamplePositions[j * _Steps + i];
result.y = water.SeaLevel;
result += _ResultDisplacements[j * _Steps + i];
var norm = _UseNormals ? _ResultNormals[j * _Steps + i] : Vector3.up;
DebugDrawCross(result, norm, Mathf.Min(_StepSize / 4f, 1f), Color.green);
}
}
}
}
else
{
if (collProvider.RetrieveSucceeded(collProvider.Query(GetHashCode(), _ObjectWidth, _SamplePositions, _ResultHeights, _UseNormals ? _ResultNormals : null, null, _Layer)))
{
for (var i = 0; i < _Steps; i++)
{
for (var j = 0; j < _Steps; j++)
{
var result = _SamplePositions[j * _Steps + i];
result.y = _ResultHeights[j * _Steps + i];
var norm = _UseNormals ? _ResultNormals[j * _Steps + i] : Vector3.up;
DebugDrawCross(result, norm, Mathf.Min(_StepSize / 4f, 1f), Color.green);
}
}
}
Render(water, Debug.DrawLine);
}
#endif
}
public static void DebugDrawCross(Vector3 pos, float r, Color col, float duration = 0f)
internal void Render(WaterRenderer water, DebugUtility.DrawLine draw)
{
Debug.DrawLine(pos - Vector3.up * r, pos + Vector3.up * r, col, duration);
Debug.DrawLine(pos - Vector3.right * r, pos + Vector3.right * r, col, duration);
Debug.DrawLine(pos - Vector3.forward * r, pos + Vector3.forward * r, col, duration);
}
if (_SamplePositions == null)
{
return;
}
public static void DebugDrawCross(Vector3 pos, Vector3 up, float r, Color col, float duration = 0f)
{
up.Normalize();
var right = Vector3.Normalize(Vector3.Cross(up, Vector3.forward));
var forward = Vector3.Cross(up, right);
Debug.DrawLine(pos - up * r, pos + up * r, col, duration);
Debug.DrawLine(pos - right * r, pos + right * r, col, duration);
Debug.DrawLine(pos - forward * r, pos + forward * r, col, duration);
for (var i = 0; i < _Steps; i++)
{
for (var j = 0; j < _Steps; j++)
{
var result = _SamplePositions[j * _Steps + i];
if (_UseDisplacements)
{
result.y = water.SeaLevel;
result += _ResultDisplacements[j * _Steps + i];
}
else
{
result.y = _ResultHeights[j * _Steps + i];
}
var normal = _UseNormals ? _ResultNormals[j * _Steps + i] : Vector3.up;
DebugUtility.DrawCross(draw, result, normal, Mathf.Min(_StepSize / 4f, 1f), Color.green);
}
}
}
}
}