修改水

This commit is contained in:
2026-01-01 22:00:33 +08:00
parent 040a222bd6
commit 9ceffccd39
1800 changed files with 103929 additions and 139495 deletions

View File

@@ -20,7 +20,6 @@ namespace Obi
ObiStructuralElement m_CursorElement = null;
private int m_SourceIndex = -1;
private float lengthChange = 0;
public float cursorMu
{
@@ -67,7 +66,6 @@ namespace Obi
rope = GetComponent<ObiRope>();
rope.OnElementsGenerated += Actor_OnElementsGenerated;
rope.OnSimulationStart += Rope_OnSimulate;
if (rope.elements != null && rope.elements.Count > 0)
Actor_OnElementsGenerated(rope);
}
@@ -75,7 +73,6 @@ namespace Obi
private void OnDisable()
{
rope.OnElementsGenerated -= Actor_OnElementsGenerated;
rope.OnSimulationStart -= Rope_OnSimulate;
}
private void Actor_OnElementsGenerated(ObiActor actor)
@@ -84,13 +81,64 @@ namespace Obi
UpdateSource();
}
private void Rope_OnSimulate(ObiActor actor, float simulatedTime, float substepTime)
public void UpdateCursor()
{
if (!rope.isLoaded || Mathf.Abs(lengthChange) < ObiUtils.epsilon)
rope = GetComponent<ObiRope>();
m_CursorElement = null;
if (rope.isLoaded)
{
float elmMu;
m_CursorElement = rope.GetElementAt(cursorMu, out elmMu);
}
}
public void UpdateSource()
{
rope = GetComponent<ObiRope>();
m_SourceIndex = -1;
if (rope.isLoaded)
{
float elmMu;
var elm = rope.GetElementAt(sourceMu, out elmMu);
if (elm != null && rope.solver != null)
{
m_SourceIndex = elmMu < 0.5f ? elm.particle1 : elm.particle2;
}
}
}
private int AddParticleAt(int index)
{
// Copy data from the particle where we will insert new particles, to the particles we will insert:
int targetIndex = rope.activeParticleCount;
rope.CopyParticle(rope.solver.particleToActor[m_SourceIndex].indexInActor, targetIndex);
// Move the new particle to the one at the place where we will insert it:
rope.TeleportParticle(targetIndex, rope.solver.positions[rope.solverIndices[index]]);
// Activate the particle:
rope.ActivateParticle(targetIndex);
return rope.solverIndices[targetIndex];
}
private void RemoveParticleAt(int index)
{
rope.DeactivateParticle(index);
}
public void ChangeLength(float newLength)
{
if (!rope.isLoaded)
return;
var solver = rope.solver;
// clamp new length to sane limits:
newLength = Mathf.Clamp(newLength, 0, (rope.sourceBlueprint.particleCount - 1) * rope.ropeBlueprint.interParticleDistance);
// calculate the change in rope length:
float lengthChange = newLength - rope.restLength;
// remove:
if (lengthChange < 0)
{
@@ -100,10 +148,6 @@ namespace Obi
{
lengthChange -= m_CursorElement.restLength;
// if we subtracted the length of the last element, break out of the loop.
if (rope.elements.Count == 1)
break;
int index = rope.elements.IndexOf(m_CursorElement);
if (index >= 0)
@@ -121,8 +165,8 @@ namespace Obi
m_CursorElement = rope.elements[index];
}
else
m_CursorElement = rope.elements[Mathf.Max(0, index - 1)];
else
m_CursorElement = rope.elements[Mathf.Max(0,index - 1)];
}
else // negative direction:
{
@@ -220,69 +264,6 @@ namespace Obi
// rebuild constraints:
rope.RebuildConstraintsFromElements();
lengthChange = 0;
}
public void UpdateCursor()
{
rope = GetComponent<ObiRope>();
m_CursorElement = null;
if (rope.isLoaded)
{
float elmMu;
m_CursorElement = rope.GetElementAt(cursorMu, out elmMu);
}
}
public void UpdateSource()
{
rope = GetComponent<ObiRope>();
m_SourceIndex = -1;
if (rope.isLoaded)
{
float elmMu;
var elm = rope.GetElementAt(sourceMu, out elmMu);
if (elm != null && rope.solver != null)
{
m_SourceIndex = elmMu < 0.5f ? elm.particle1 : elm.particle2;
}
}
}
private int AddParticleAt(int index)
{
int targetIndex = rope.activeParticleCount;
// Copy data from the particle where we will insert new particles, to the particles we will insert:
rope.CopyParticle(rope.solver.particleToActor[m_SourceIndex].indexInActor, targetIndex);
// Move the new particle to the one at the place where we will insert it:
rope.TeleportParticle(targetIndex, rope.solver.positions[rope.solverIndices[index]]);
// Activate the particle:
rope.ActivateParticle();
rope.SetRenderingDirty(Oni.RenderingSystemType.AllRopes);
return rope.solverIndices[targetIndex];
}
private void RemoveParticleAt(int index)
{
rope.DeactivateParticle(index);
rope.SetRenderingDirty(Oni.RenderingSystemType.AllRopes);
}
public float ChangeLength(float lengthChange)
{
// clamp new length to sane limits:
//newLength = Mathf.Clamp(newLength, 0, (rope.sourceBlueprint.particleCount - 1) * rope.ropeBlueprint.interParticleDistance);
// accumulate length change, we'll reset it to zero after it has been applied.
this.lengthChange += lengthChange;
// return new length:
return this.lengthChange + rope.restLength;
}
}
}