From c360b3c86907b239273c5e7130d787008f46216d Mon Sep 17 00:00:00 2001 From: bottlefish <781230111@qq.com> Date: Sat, 25 Jan 2025 17:45:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scenes/PeipeiFixScene.unity | 127 ++++++++++++++++-- .../FixSystem/Line/PhysicLineSegment.cs | 36 ++--- .../Scripts/FixSystem/Line/VerletParticle.cs | 7 +- Assets/Scripts/FixSystem/Line/VerletStick.cs | 3 +- .../Scripts/FixSystemNew/BodyModule/Cable.cs | 17 +-- .../Scripts/FixSystemNew/BodyModule/Plug.cs | 21 +-- 6 files changed, 147 insertions(+), 64 deletions(-) diff --git a/Assets/Scenes/PeipeiFixScene.unity b/Assets/Scenes/PeipeiFixScene.unity index d26eef9d8..e0d79abaf 100644 --- a/Assets/Scenes/PeipeiFixScene.unity +++ b/Assets/Scenes/PeipeiFixScene.unity @@ -4638,17 +4638,89 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1236037239} m_Modifications: + - target: {fileID: -3073236352691771152, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: k + value: 30 + objectReference: {fileID: 0} + - target: {fileID: -3073236352691771152, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: gravity + value: -12 + objectReference: {fileID: 0} + - target: {fileID: -3073236352691771152, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: cableSystem + value: + objectReference: {fileID: 1940605072} + - target: {fileID: -3073236352691771152, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: segmentSpacing + value: 0.1 + objectReference: {fileID: 0} - target: {fileID: 3614166255594274803, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} propertyPath: m_Name value: PhysicLinePrefabNew objectReference: {fileID: 0} + - target: {fileID: 3614166255594274803, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Enabled + value: 0 + objectReference: {fileID: 0} - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} propertyPath: m_SortingLayer - value: 11 + value: 10 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_SortingOrder + value: 48 objectReference: {fileID: 0} - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} propertyPath: m_SortingLayerID - value: 1016946085 + value: 1134468525 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.widthMultiplier + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.colorGradient.ctime1 + value: 65342 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.colorGradient.key0.b + value: 0.33962262 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.colorGradient.key0.g + value: 0.18719505 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.colorGradient.key0.r + value: 0.0012815695 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.colorGradient.key1.b + value: 0.5660378 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.colorGradient.key1.g + value: 0.41209447 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.colorGradient.key1.r + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.colorGradient.m_ColorSpace + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.widthCurve.m_Curve.Array.data[0].time + value: 0.012138367 + objectReference: {fileID: 0} + - target: {fileID: 8979707155830308861, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + propertyPath: m_Parameters.widthCurve.m_Curve.Array.data[0].value + value: 0.3029231 objectReference: {fileID: 0} - target: {fileID: 9034087187549040666, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} propertyPath: m_LocalPosition.x @@ -7988,7 +8060,7 @@ Transform: m_GameObject: {fileID: 395292228} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0.43, y: 0.19, z: 0} + m_LocalPosition: {x: 1.98, y: -0.52, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] @@ -16289,6 +16361,17 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1030302553} m_CullTransparentMesh: 1 +--- !u!114 &1035054266 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: -3073236352691771152, guid: befc2e1cb50eae541870ccb46e98e3ee, type: 3} + m_PrefabInstance: {fileID: 205914928} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1198bee0150e12d4aa20514b2c8f3362, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1036194063 GameObject: m_ObjectHideFlags: 0 @@ -19522,7 +19605,6 @@ Transform: m_Children: - {fileID: 453375097} - {fileID: 395292229} - - {fileID: 1248774369} m_Father: {fileID: 1940605071} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1236037240 @@ -19539,7 +19621,7 @@ MonoBehaviour: m_EditorClassIdentifier: StartTranform: {fileID: 395292229} endTransform: {fileID: 1248774369} - physicLine: {fileID: 0} + physicLine: {fileID: 1035054266} --- !u!1 &1244183432 GameObject: m_ObjectHideFlags: 0 @@ -19639,12 +19721,12 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1248774368} serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.11, y: -1.89, z: 0} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] - m_Father: {fileID: 1236037239} + m_Father: {fileID: 1798822120} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1255230568 GameObject: @@ -28234,6 +28316,11 @@ MonoBehaviour: - 0.05 - 0.07 tempPunchTapeGroup: {fileID: 1655025825} +--- !u!4 &1798822120 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 5095564283598629642, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} + m_PrefabInstance: {fileID: 6045551082333026152} + m_PrefabAsset: {fileID: 0} --- !u!1 &1805580364 GameObject: m_ObjectHideFlags: 0 @@ -29556,6 +29643,17 @@ Transform: m_CorrespondingSourceObject: {fileID: 2117906688623379083, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} m_PrefabInstance: {fileID: 6045551082333026152} m_PrefabAsset: {fileID: 0} +--- !u!114 &1940605072 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 3270961982482695146, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} + m_PrefabInstance: {fileID: 6045551082333026152} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 587f3ee69d7c47d291e4e488f9ca3090, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1944658449 GameObject: m_ObjectHideFlags: 0 @@ -34448,11 +34546,11 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 1743353464033058114, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} propertyPath: m_LocalPosition.x - value: -0.62 + value: 0.12 objectReference: {fileID: 0} - target: {fileID: 1743353464033058114, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} propertyPath: m_LocalPosition.y - value: -2.72 + value: -2.67 objectReference: {fileID: 0} - target: {fileID: 1953141088643421057, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} propertyPath: m_Color.b @@ -34488,7 +34586,7 @@ PrefabInstance: objectReference: {fileID: 0} - target: {fileID: 2974144504474559753, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} propertyPath: m_IsActive - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 3058962797372916513, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} propertyPath: m_AnchoredPosition.x @@ -34630,6 +34728,10 @@ PrefabInstance: propertyPath: m_IsActive value: 1 objectReference: {fileID: 0} + - target: {fileID: 4645710116166496809, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 4712647070840856395, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} propertyPath: oscilloscopeSystem value: @@ -34762,6 +34864,9 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 2117906688623379083, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} insertIndex: 0 addedObject: {fileID: 1236037239} + - targetCorrespondingSourceObject: {fileID: 5095564283598629642, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} + insertIndex: -1 + addedObject: {fileID: 1248774369} m_AddedComponents: - targetCorrespondingSourceObject: {fileID: 4445889917739518717, guid: 92aec29b557d59a4ca5363aadd06c7bb, type: 3} insertIndex: -1 diff --git a/Assets/Scripts/FixSystem/Line/PhysicLineSegment.cs b/Assets/Scripts/FixSystem/Line/PhysicLineSegment.cs index 6867684e8..1dff27caf 100644 --- a/Assets/Scripts/FixSystem/Line/PhysicLineSegment.cs +++ b/Assets/Scripts/FixSystem/Line/PhysicLineSegment.cs @@ -24,7 +24,7 @@ public class PhysicLineSegment : MonoBehaviour this.end = end; originalLength = Vector3.Distance(start, end); - segmentCount = Mathf.RoundToInt(Vector3.Distance(start, end) / segmentSpacing * 1.2f); + segmentCount = Mathf.RoundToInt(originalLength / segmentSpacing); lineRenderer = GetComponent(); // Initialize particles @@ -51,7 +51,11 @@ public class PhysicLineSegment : MonoBehaviour UpdateLine(); for (int i = 0; i < segmentCount; i++) { - lineRenderer.SetPosition(i, particles[i].position); + if(lineRenderer!=null) + { + lineRenderer.SetPosition(i, particles[i].position); + } + } } @@ -73,7 +77,6 @@ public class PhysicLineSegment : MonoBehaviour } } } - public void UpdatePlug(Transform plug) { if (plug != null && particles.Count > 1) @@ -82,33 +85,16 @@ public class PhysicLineSegment : MonoBehaviour float plugLength = plug.GetComponent().bounds.size.y; Vector3 direction = particles[particles.Count - 1].position - particles[particles.Count - 2].position; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; - - plug.position = plugPosition + direction.normalized * (plugLength / 2); plug.rotation = Quaternion.Euler(0, 0, angle - 90f); + plug.position = plugPosition + direction.normalized * (plugLength / 2); + - // Adjust the final particle position based on plug position - particles[particles.Count - 1].position = plugPosition + direction.normalized * (plugLength / 2); } } - - public void UpdateEndPoint(Vector3 newEndPosition) + public void UpdateEndPoint(Transform transform) { - end = newEndPosition; - lineRenderer.positionCount = segmentCount; - - // Calculate current length and scale ratio - float currentLength = Vector3.Distance(start, newEndPosition); - float lengthRatio = currentLength / originalLength; - - // Apply length adjustment with smooth transition - for (int i = 1; i < particles.Count; i++) - { - Vector3 direction = (particles[i].position - start).normalized; - particles[i].position = start + direction * (Vector3.Distance(start, particles[i].position) * lengthRatio); - } - - // Lock the last particle and update its position particles[particles.Count - 1].isLocked = true; - particles[particles.Count - 1].position = newEndPosition; + particles[particles.Count - 1].position = transform.position; } + } \ No newline at end of file diff --git a/Assets/Scripts/FixSystem/Line/VerletParticle.cs b/Assets/Scripts/FixSystem/Line/VerletParticle.cs index 636f86686..b36e11545 100644 --- a/Assets/Scripts/FixSystem/Line/VerletParticle.cs +++ b/Assets/Scripts/FixSystem/Line/VerletParticle.cs @@ -6,6 +6,8 @@ public class VerletParticle { public Vector3 position; // 当前帧位置 public Vector3 previousPosition; // 上一帧位置 + + public float mass = 1f; // 默认质量 public bool isLocked; // 是否锁定 public VerletParticle(Vector3 position) @@ -21,8 +23,9 @@ public class VerletParticle if (!isLocked) { Vector3 velocity = position - previousPosition; - Vector3 airResistance = -velocity * 0.15f; // 阻力系数 - velocity += (force + airResistance) * Time.deltaTime; + Vector3 airResistance = -velocity * 0.3f; + //Vector3 damping = velocity * 0.02f; // 额外的速度衰减 + velocity += (force + airResistance) * Time.deltaTime / mass; // 考虑质量 previousPosition = position; position += velocity; } diff --git a/Assets/Scripts/FixSystem/Line/VerletStick.cs b/Assets/Scripts/FixSystem/Line/VerletStick.cs index a894aaa3d..222970193 100644 --- a/Assets/Scripts/FixSystem/Line/VerletStick.cs +++ b/Assets/Scripts/FixSystem/Line/VerletStick.cs @@ -7,13 +7,14 @@ public class VerletStick private VerletParticle particleA; private VerletParticle particleB; private float length; - public float stiffness = 0.3f; // Add this line + public float stiffness = 0.75f; // Add this line public VerletStick(VerletParticle particleA, VerletParticle particleB, float length) { this.particleA = particleA; this.particleB = particleB; this.length = length; + stiffness = Mathf.Clamp(0.2f * (length / 0.5f), 0.5f, 0.75f); // 调整范围根据需要 } public void UpdateStick() diff --git a/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs b/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs index a2da3de9e..b38a747e8 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/Cable.cs @@ -1,4 +1,5 @@ using System; +using System.Drawing; using DG.Tweening.Plugins.Core.PathCore; using UnityEngine; @@ -8,8 +9,6 @@ namespace AibisDream.FixSystem public class Cable : MonoBehaviour { private Transform _start; - - public Transform _controlPoint; private Transform _end; private LineRenderer _lineRenderer; @@ -29,7 +28,7 @@ namespace AibisDream.FixSystem private void InitComponentRefs() { _cableSystem = transform.parent.GetComponent(); - + _lineRenderer = GetComponent(); _lineRenderer.positionCount = config.resolution; @@ -64,13 +63,11 @@ namespace AibisDream.FixSystem Vector3[] UpdateRope() { - + float t = Mathf.InverseLerp(config.dstMin, config.dstMax, (_start.position - _end.position).magnitude); float F = Mathf.Lerp(config.forceMin, config.forceMax, t); _points[0] = _start.position; - _points[1] = _controlPoint.position; - _points[^1] = _end.position; - + _points[^1] = _end.GetChild(0).position; for (int ik = 0; ik < config.k; ik++) { for (int i = 1; i < _points.Length - 1; i++) @@ -99,8 +96,12 @@ namespace AibisDream.FixSystem { _end = endPos; } + public Vector3 GetDirection() + { + return _points[^1]-_points[_points.Length-1]; + } } - + [Serializable] public struct CableConfig { diff --git a/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs b/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs index e2857cf58..b2b2bbefa 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/Plug.cs @@ -55,10 +55,11 @@ namespace AibisDream.FixSystem { //InsertSocket(initSocket); } - public void InitPlug() + + public void Update() { - _cableSystem.PhysicCableRef.Init(); - //_cableSystem.PhysicCableRef.physicLine.UpdatePlug(this.transform); + //_cableSystem.PhysicCableRef.physicLine.UpdateEndPoint(this.transform); + _cableSystem.PhysicCableRef.physicLine.UpdatePlug(this.transform); } /// @@ -155,20 +156,6 @@ namespace AibisDream.FixSystem // }); } } - public void Update() - { - _cableSystem.PhysicCableRef.physicLine.UpdateEndPoint(this.transform.position); - // if(_cableSystem.curSocket!=null&&_isDragging==false) - // { - // _cableSystem.PhysicCableRef.physicLine.UpdatePlug(this.transform); - - // } - // else - // { - // _cableSystem.PhysicCableRef.physicLine.UpdateLine(this.transform); - // } - - } private void AdjustPlugPos() {