增加rope线模式

This commit is contained in:
2025-11-04 23:33:51 +08:00
parent e8f6308580
commit 524edd4cc6
2 changed files with 79 additions and 43 deletions

View File

@@ -1184,11 +1184,9 @@ MonoBehaviour:
isLoop: 0
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
shadowMode: 1
customMesh:
mesh: {fileID: 0}
rotation: 90
scale: {x: 1, y: 1, z: 1}
stretch: 0
rendering:
useSimpleLineRenderer: 0
simpleLineWidth: 0.02
spawnPoints:
- x: 4
y: 0
@@ -2440,11 +2438,9 @@ MonoBehaviour:
isLoop: 0
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
shadowMode: 1
customMesh:
mesh: {fileID: 0}
rotation: 90
scale: {x: 1, y: 1, z: 1}
stretch: 0
rendering:
useSimpleLineRenderer: 0
simpleLineWidth: 0.02
spawnPoints:
- x: 0
y: 0
@@ -2578,11 +2574,9 @@ MonoBehaviour:
isLoop: 0
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
shadowMode: 1
customMesh:
mesh: {fileID: 0}
rotation: 90
scale: {x: 1, y: 1, z: 1}
stretch: 0
rendering:
useSimpleLineRenderer: 0
simpleLineWidth: 0.02
spawnPoints:
- x: 0
y: 0
@@ -3329,16 +3323,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 325b217b839086b4ca705834516bc0d5, type: 3}
m_Name:
m_EditorClassIdentifier:
radius: 0.04
radius: 0.001
radialVertices: 6
isLoop: 0
material: {fileID: 2100000, guid: 85feedf64f0c16d4182fd4c33e342d2a, type: 2}
shadowMode: 1
customMesh:
mesh: {fileID: 4257529212018882713, guid: dc3ad6005b4f0514982b05eb88b9ed3f, type: 3}
rotation: 90
scale: {x: 1, y: 1, z: 1}
stretch: 1
rendering:
useSimpleLineRenderer: 1
simpleLineWidth: 0.001
spawnPoints:
- x: -0.90364826
y: -1.0066781
@@ -3491,11 +3483,9 @@ MonoBehaviour:
isLoop: 1
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
shadowMode: 1
customMesh:
mesh: {fileID: 0}
rotation: 90
scale: {x: 1, y: 1, z: 1}
stretch: 0
rendering:
useSimpleLineRenderer: 0
simpleLineWidth: 0.02
spawnPoints:
- x: 0
y: 0
@@ -3792,11 +3782,9 @@ MonoBehaviour:
isLoop: 0
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
shadowMode: 1
customMesh:
mesh: {fileID: 0}
rotation: 90
scale: {x: 1, y: 1, z: 1}
stretch: 0
rendering:
useSimpleLineRenderer: 0
simpleLineWidth: 0.02
spawnPoints:
- x: 0
y: 0
@@ -5224,11 +5212,9 @@ MonoBehaviour:
isLoop: 0
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
shadowMode: 1
customMesh:
mesh: {fileID: 0}
rotation: 90
scale: {x: 1, y: 1, z: 1}
stretch: 0
rendering:
useSimpleLineRenderer: 0
simpleLineWidth: 0.02
spawnPoints:
- x: 4
y: 0

View File

@@ -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();
}