升级obi

This commit is contained in:
2026-01-22 22:08:21 +08:00
parent 120b8cda26
commit 20f14322bc
1067 changed files with 149894 additions and 29583 deletions

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace Obi
{
public abstract class ObiRopeBase : ObiActor
public abstract class ObiRopeBase : ObiActor, IAerodynamicConstraintsUser
{
[SerializeField] protected bool m_SelfCollisions = false;
@@ -12,11 +12,44 @@ namespace Obi
[HideInInspector] public List<ObiStructuralElement> elements = new List<ObiStructuralElement>(); /**< Elements.*/
public event ActorCallback OnElementsGenerated;
// aerodynamics
[SerializeField] protected bool _aerodynamicsEnabled = true;
[SerializeField] protected float _drag = 0.05f;
[SerializeField] protected float _lift = 0.02f;
/// <summary>
/// Whether this actor's aerodynamic constraints are enabled.
/// </summary>
public bool aerodynamicsEnabled
{
get { return _aerodynamicsEnabled; }
set { if (value != _aerodynamicsEnabled) { _aerodynamicsEnabled = value; SetConstraintsDirty(Oni.ConstraintType.Aerodynamics); } }
}
/// <summary>
/// Aerodynamic drag value.
/// </summary>
public float drag
{
get { return _drag; }
set { _drag = value; SetConstraintsDirty(Oni.ConstraintType.Aerodynamics); }
}
/// <summary>
/// Aerodynamic lift value.
/// </summary>
public float lift
{
get { return _lift; }
set { _lift = value; SetConstraintsDirty(Oni.ConstraintType.Aerodynamics); }
}
public float restLength
{
get { return restLength_; }
}
public ObiPath path
{
get {
@@ -25,6 +58,37 @@ namespace Obi
}
}
public float GetDrag(ObiAerodynamicConstraintsBatch batch, int constraintIndex)
{
return drag;
}
public float GetLift(ObiAerodynamicConstraintsBatch batch, int constraintIndex)
{
return lift;
}
public override void ProvideDeformableEdges(ObiNativeIntList deformableEdges)
{
deformableEdgesOffset = deformableEdges.count / 2;
var ropeBlueprint = sharedBlueprint as ObiRopeBlueprintBase;
if (ropeBlueprint != null && ropeBlueprint.deformableEdges != null)
{
// Send deformable edge indices to the solver:
for (int i = 0; i < ropeBlueprint.deformableEdges.Length; ++i)
deformableEdges.Add(solverIndices[ropeBlueprint.deformableEdges[i]]);
}
}
public override int GetDeformableEdgeCount()
{
var ropeBlueprint = sharedBlueprint as ObiRopeBlueprintBase;
if (ropeBlueprint != null && ropeBlueprint.deformableEdges != null)
return ropeBlueprint.deformableEdges.Length / 2;
return 0;
}
/// <summary>
/// Calculates and returns current rope length, including stretching/compression.
/// </summary>
@@ -105,5 +169,25 @@ namespace Obi
return null;
}
/// <summary>
/// Returns index of the edge that contains a length-normalized coordinate. It will also return the length-normalized coordinate within the edge.
/// </summary>
public int GetEdgeAt(float mu, out float elementMu)
{
elementMu = -1;
var ropeBlueprint = sharedBlueprint as ObiRopeBlueprintBase;
if (ropeBlueprint != null && ropeBlueprint.deformableEdges != null)
{
float edgeMu = ropeBlueprint.deformableEdges.Length/2 * Mathf.Clamp(mu, 0, 0.99999f);
int index = (int)edgeMu;
elementMu = edgeMu - index;
if (index < ropeBlueprint.deformableEdges.Length/2)
return index;
}
return -1;
}
}
}