增加rope线模式
This commit is contained in:
64
Assets/Scripts/ThirdParty/Rope/Rope.cs
vendored
64
Assets/Scripts/ThirdParty/Rope/Rope.cs
vendored
@@ -75,6 +75,21 @@ namespace NBF
|
||||
|
||||
[Tooltip("绳子使用的阴影投射模式")] public ShadowCastingMode shadowMode = ShadowCastingMode.On;
|
||||
|
||||
[System.Serializable]
|
||||
public struct RenderingSettings
|
||||
{
|
||||
[Tooltip("使用简单线渲染而非完整网格渲染。适用于细绳如鱼线,性能更好。")]
|
||||
public bool useSimpleLineRenderer;
|
||||
|
||||
[Tooltip("简单线渲染的宽度。")]
|
||||
public float simpleLineWidth;
|
||||
}
|
||||
|
||||
[Space] public RenderingSettings rendering = new RenderingSettings()
|
||||
{
|
||||
useSimpleLineRenderer = false,
|
||||
simpleLineWidth = 0.02f
|
||||
};
|
||||
|
||||
// public CustomMeshSettings customMesh = new CustomMeshSettings()
|
||||
// {
|
||||
@@ -142,6 +157,7 @@ namespace NBF
|
||||
solverIterations = 2,
|
||||
};
|
||||
|
||||
|
||||
[System.Serializable]
|
||||
public struct CollisionSettings
|
||||
{
|
||||
@@ -197,6 +213,8 @@ namespace NBF
|
||||
public ParticleTarget target;
|
||||
}
|
||||
|
||||
// 添加LineRenderer组件引用
|
||||
protected LineRenderer lineRenderer;
|
||||
protected bool initialized;
|
||||
protected bool computingSimulationFrame;
|
||||
protected bool simulationDisabledPrevFrame;
|
||||
@@ -268,6 +286,7 @@ namespace NBF
|
||||
{
|
||||
simulation.resolution = Mathf.Max(0.01f, simulation.resolution);
|
||||
simulation.massPerMeter = Mathf.Max(0.01f, simulation.massPerMeter);
|
||||
rendering.simpleLineWidth = Mathf.Max(0.001f, rendering.simpleLineWidth);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -774,6 +793,23 @@ namespace NBF
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rendering.useSimpleLineRenderer)
|
||||
{
|
||||
lineRenderer = gameObject.GetComponent<LineRenderer>();
|
||||
if (lineRenderer == null)
|
||||
{
|
||||
lineRenderer = gameObject.AddComponent<LineRenderer>();
|
||||
}
|
||||
|
||||
lineRenderer.useWorldSpace = true;
|
||||
lineRenderer.loop = isLoop;
|
||||
lineRenderer.widthMultiplier = rendering.simpleLineWidth;
|
||||
lineRenderer.material = material;
|
||||
lineRenderer.shadowCastingMode = shadowMode;
|
||||
lineRenderer.receiveShadows = false;
|
||||
lineRenderer.alignment = LineAlignment.View;
|
||||
}
|
||||
|
||||
// 状态
|
||||
ComputeRealCurve(Allocator.Persistent, out _measurements, out positions);
|
||||
|
||||
@@ -1329,16 +1365,30 @@ namespace NBF
|
||||
}
|
||||
|
||||
Profiler.BeginSample(nameof(SubmitToRenderer));
|
||||
|
||||
// 默认绳子圆柱体
|
||||
if (simulation.enabled)
|
||||
if (rendering.useSimpleLineRenderer)
|
||||
{
|
||||
mesh.SetVertices(vertices);
|
||||
mesh.SetNormals(normals);
|
||||
mesh.RecalculateBounds();
|
||||
// 使用简单线渲染
|
||||
if (lineRenderer != null && simulation.enabled)
|
||||
{
|
||||
lineRenderer.positionCount = positions.Length;
|
||||
for (int i = 0; i < positions.Length; i++)
|
||||
{
|
||||
lineRenderer.SetPosition(i, positions[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 默认绳子圆柱体
|
||||
if (simulation.enabled)
|
||||
{
|
||||
mesh.SetVertices(vertices);
|
||||
mesh.SetNormals(normals);
|
||||
mesh.RecalculateBounds();
|
||||
}
|
||||
|
||||
Graphics.DrawMesh(mesh, Matrix4x4.identity, material, gameObject.layer, null, 0, null, shadowMode);
|
||||
Graphics.DrawMesh(mesh, Matrix4x4.identity, material, gameObject.layer, null, 0, null, shadowMode);
|
||||
}
|
||||
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user