增加rope线模式
This commit is contained in:
@@ -1184,11 +1184,9 @@ MonoBehaviour:
|
|||||||
isLoop: 0
|
isLoop: 0
|
||||||
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
||||||
shadowMode: 1
|
shadowMode: 1
|
||||||
customMesh:
|
rendering:
|
||||||
mesh: {fileID: 0}
|
useSimpleLineRenderer: 0
|
||||||
rotation: 90
|
simpleLineWidth: 0.02
|
||||||
scale: {x: 1, y: 1, z: 1}
|
|
||||||
stretch: 0
|
|
||||||
spawnPoints:
|
spawnPoints:
|
||||||
- x: 4
|
- x: 4
|
||||||
y: 0
|
y: 0
|
||||||
@@ -2440,11 +2438,9 @@ MonoBehaviour:
|
|||||||
isLoop: 0
|
isLoop: 0
|
||||||
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
||||||
shadowMode: 1
|
shadowMode: 1
|
||||||
customMesh:
|
rendering:
|
||||||
mesh: {fileID: 0}
|
useSimpleLineRenderer: 0
|
||||||
rotation: 90
|
simpleLineWidth: 0.02
|
||||||
scale: {x: 1, y: 1, z: 1}
|
|
||||||
stretch: 0
|
|
||||||
spawnPoints:
|
spawnPoints:
|
||||||
- x: 0
|
- x: 0
|
||||||
y: 0
|
y: 0
|
||||||
@@ -2578,11 +2574,9 @@ MonoBehaviour:
|
|||||||
isLoop: 0
|
isLoop: 0
|
||||||
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
||||||
shadowMode: 1
|
shadowMode: 1
|
||||||
customMesh:
|
rendering:
|
||||||
mesh: {fileID: 0}
|
useSimpleLineRenderer: 0
|
||||||
rotation: 90
|
simpleLineWidth: 0.02
|
||||||
scale: {x: 1, y: 1, z: 1}
|
|
||||||
stretch: 0
|
|
||||||
spawnPoints:
|
spawnPoints:
|
||||||
- x: 0
|
- x: 0
|
||||||
y: 0
|
y: 0
|
||||||
@@ -3329,16 +3323,14 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 325b217b839086b4ca705834516bc0d5, type: 3}
|
m_Script: {fileID: 11500000, guid: 325b217b839086b4ca705834516bc0d5, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
radius: 0.04
|
radius: 0.001
|
||||||
radialVertices: 6
|
radialVertices: 6
|
||||||
isLoop: 0
|
isLoop: 0
|
||||||
material: {fileID: 2100000, guid: 85feedf64f0c16d4182fd4c33e342d2a, type: 2}
|
material: {fileID: 2100000, guid: 85feedf64f0c16d4182fd4c33e342d2a, type: 2}
|
||||||
shadowMode: 1
|
shadowMode: 1
|
||||||
customMesh:
|
rendering:
|
||||||
mesh: {fileID: 4257529212018882713, guid: dc3ad6005b4f0514982b05eb88b9ed3f, type: 3}
|
useSimpleLineRenderer: 1
|
||||||
rotation: 90
|
simpleLineWidth: 0.001
|
||||||
scale: {x: 1, y: 1, z: 1}
|
|
||||||
stretch: 1
|
|
||||||
spawnPoints:
|
spawnPoints:
|
||||||
- x: -0.90364826
|
- x: -0.90364826
|
||||||
y: -1.0066781
|
y: -1.0066781
|
||||||
@@ -3491,11 +3483,9 @@ MonoBehaviour:
|
|||||||
isLoop: 1
|
isLoop: 1
|
||||||
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
||||||
shadowMode: 1
|
shadowMode: 1
|
||||||
customMesh:
|
rendering:
|
||||||
mesh: {fileID: 0}
|
useSimpleLineRenderer: 0
|
||||||
rotation: 90
|
simpleLineWidth: 0.02
|
||||||
scale: {x: 1, y: 1, z: 1}
|
|
||||||
stretch: 0
|
|
||||||
spawnPoints:
|
spawnPoints:
|
||||||
- x: 0
|
- x: 0
|
||||||
y: 0
|
y: 0
|
||||||
@@ -3792,11 +3782,9 @@ MonoBehaviour:
|
|||||||
isLoop: 0
|
isLoop: 0
|
||||||
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
||||||
shadowMode: 1
|
shadowMode: 1
|
||||||
customMesh:
|
rendering:
|
||||||
mesh: {fileID: 0}
|
useSimpleLineRenderer: 0
|
||||||
rotation: 90
|
simpleLineWidth: 0.02
|
||||||
scale: {x: 1, y: 1, z: 1}
|
|
||||||
stretch: 0
|
|
||||||
spawnPoints:
|
spawnPoints:
|
||||||
- x: 0
|
- x: 0
|
||||||
y: 0
|
y: 0
|
||||||
@@ -5224,11 +5212,9 @@ MonoBehaviour:
|
|||||||
isLoop: 0
|
isLoop: 0
|
||||||
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
material: {fileID: 2100000, guid: 189732c736fdb544f98524f96c34aff6, type: 2}
|
||||||
shadowMode: 1
|
shadowMode: 1
|
||||||
customMesh:
|
rendering:
|
||||||
mesh: {fileID: 0}
|
useSimpleLineRenderer: 0
|
||||||
rotation: 90
|
simpleLineWidth: 0.02
|
||||||
scale: {x: 1, y: 1, z: 1}
|
|
||||||
stretch: 0
|
|
||||||
spawnPoints:
|
spawnPoints:
|
||||||
- x: 4
|
- x: 4
|
||||||
y: 0
|
y: 0
|
||||||
|
|||||||
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;
|
[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()
|
// public CustomMeshSettings customMesh = new CustomMeshSettings()
|
||||||
// {
|
// {
|
||||||
@@ -142,6 +157,7 @@ namespace NBF
|
|||||||
solverIterations = 2,
|
solverIterations = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public struct CollisionSettings
|
public struct CollisionSettings
|
||||||
{
|
{
|
||||||
@@ -197,6 +213,8 @@ namespace NBF
|
|||||||
public ParticleTarget target;
|
public ParticleTarget target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加LineRenderer组件引用
|
||||||
|
protected LineRenderer lineRenderer;
|
||||||
protected bool initialized;
|
protected bool initialized;
|
||||||
protected bool computingSimulationFrame;
|
protected bool computingSimulationFrame;
|
||||||
protected bool simulationDisabledPrevFrame;
|
protected bool simulationDisabledPrevFrame;
|
||||||
@@ -268,6 +286,7 @@ namespace NBF
|
|||||||
{
|
{
|
||||||
simulation.resolution = Mathf.Max(0.01f, simulation.resolution);
|
simulation.resolution = Mathf.Max(0.01f, simulation.resolution);
|
||||||
simulation.massPerMeter = Mathf.Max(0.01f, simulation.massPerMeter);
|
simulation.massPerMeter = Mathf.Max(0.01f, simulation.massPerMeter);
|
||||||
|
rendering.simpleLineWidth = Mathf.Max(0.001f, rendering.simpleLineWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -774,6 +793,23 @@ namespace NBF
|
|||||||
return false;
|
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);
|
ComputeRealCurve(Allocator.Persistent, out _measurements, out positions);
|
||||||
|
|
||||||
@@ -1329,16 +1365,30 @@ namespace NBF
|
|||||||
}
|
}
|
||||||
|
|
||||||
Profiler.BeginSample(nameof(SubmitToRenderer));
|
Profiler.BeginSample(nameof(SubmitToRenderer));
|
||||||
|
if (rendering.useSimpleLineRenderer)
|
||||||
// 默认绳子圆柱体
|
|
||||||
if (simulation.enabled)
|
|
||||||
{
|
{
|
||||||
mesh.SetVertices(vertices);
|
// 使用简单线渲染
|
||||||
mesh.SetNormals(normals);
|
if (lineRenderer != null && simulation.enabled)
|
||||||
mesh.RecalculateBounds();
|
{
|
||||||
|
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();
|
Profiler.EndSample();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user