Commit 10e0d319 authored by rv3Dcv's avatar rv3Dcv

Add CollisionDetectionVessel.cs

parent 39af84d5
...@@ -59,3 +59,4 @@ sysinfo.txt ...@@ -59,3 +59,4 @@ sysinfo.txt
crashlytics-build.properties crashlytics-build.properties
GuidewireSimulation/GuidewireSimulation/.vscode/launch.json GuidewireSimulation/GuidewireSimulation/.vscode/launch.json
GuidewireSimulation/GuidewireSimulation/UserSettings/EditorUserSettings.asset
...@@ -16,7 +16,6 @@ namespace GuidewireSim ...@@ -16,7 +16,6 @@ namespace GuidewireSim
* @note Should also match the position in @p spherePositions, @p sphereVelocities, @p sphereExternalForces, * @note Should also match the position in @p spherePositions, @p sphereVelocities, @p sphereExternalForces,
* @p spherePositionPredictions in #SimulationLoop. * @p spherePositionPredictions in #SimulationLoop.
*/ */
[SerializeField] bool insideCollision = false; //!< Whether the guidewire collides from within the blood vessel or from the outside.
private void Awake() private void Awake()
{ {
...@@ -48,6 +47,29 @@ namespace GuidewireSim ...@@ -48,6 +47,29 @@ namespace GuidewireSim
Debug.LogWarning("No sphereID could be assigned."); Debug.LogWarning("No sphereID could be assigned.");
} }
private void OnCollisionEnter(Collision other)
{
Debug.Log("trigger " + transform.name);
collisionHandler.RegisterCollision(this.transform, other, sphereID);
}
private void OnCollisionStay(Collision other)
{
Debug.Log("trigger " + transform.name);
collisionHandler.RegisterCollision(this.transform, other, sphereID);
}
// private void OnTriggerEnter(Collider other) // private void OnTriggerEnter(Collider other)
// { // {
// Debug.Log("trigger " + transform.name); // Debug.Log("trigger " + transform.name);
...@@ -88,45 +110,34 @@ namespace GuidewireSim ...@@ -88,45 +110,34 @@ namespace GuidewireSim
// } // }
// } // }
private void OnCollisionEnter(Collision other) // private void OnCollisionEnter(Collision other)
{
Debug.Log("trigger " + transform.name);
// needed to use ClosestPoint().
// other.collider.GetComponent<MeshCollider>().convex = true;
collisionHandler.RegisterCollision(this.transform, other, sphereID);
// Debug.Log(other.GetContact(0).normal.ToString("e2"));
// if (!insideCollision)
// { // {
// Debug.Log("trigger " + transform.name);
// // needed to use ClosestPoint().
// // other.collider.GetComponent<MeshCollider>().convex = true;
// collisionHandler.RegisterCollision(this.transform, other, sphereID); // collisionHandler.RegisterCollision(this.transform, other, sphereID);
// Debug.Log("pos" + this.transform.position); // // Debug.Log(other.GetContact(0).normal.ToString("e2"));
// Debug.Log("colpos" + this.transform.GetComponent<SphereCollider>().center);
// Debug.Log("otherpos" + other.transform.position);
// other.collider.GetComponent<MeshCollider>().convex = true;
// Vector3 otherClosestPoint = other.collider.ClosestPoint(this.transform.position);
// Debug.Log("otherclosestpoint" + otherClosestPoint.ToString("e4")); // // if (!insideCollision)
// Debug.Log("thisclosestpoint" + this.transform.GetComponent<SphereCollider>().ClosestPoint(otherClosestPoint).ToString("e4")); // // {
// Vector3 thisclosestpoint2 = this.transform.GetComponent<SphereCollider>().ClosestPoint(other.transform.position); // // collisionHandler.RegisterCollision(this.transform, other, sphereID);
// Debug.Log("thisclosestpoint2" + thisclosestpoint2.ToString("e4")); // // Debug.Log("pos" + this.transform.position);
// Vector3 DiffCollisionPointToCenter = thisclosestpoint2 - (this.transform.position + this.transform.GetComponent<SphereCollider>().center); // // Debug.Log("colpos" + this.transform.GetComponent<SphereCollider>().center);
// Debug.Log("DiffCollisionPointToCenter" + DiffCollisionPointToCenter.ToString("e4")); // // Debug.Log("otherpos" + other.transform.position);
// }
} // // other.collider.GetComponent<MeshCollider>().convex = true;
// // Vector3 otherClosestPoint = other.collider.ClosestPoint(this.transform.position);
private void OnCollisionStay(Collision other) // // Debug.Log("otherclosestpoint" + otherClosestPoint.ToString("e4"));
{ // // Debug.Log("thisclosestpoint" + this.transform.GetComponent<SphereCollider>().ClosestPoint(otherClosestPoint).ToString("e4"));
Debug.Log("trigger " + transform.name); // // Vector3 thisclosestpoint2 = this.transform.GetComponent<SphereCollider>().ClosestPoint(other.transform.position);
// // Debug.Log("thisclosestpoint2" + thisclosestpoint2.ToString("e4"));
// // Vector3 DiffCollisionPointToCenter = thisclosestpoint2 - (this.transform.position + this.transform.GetComponent<SphereCollider>().center);
// // Debug.Log("DiffCollisionPointToCenter" + DiffCollisionPointToCenter.ToString("e4"));
// // }
if (!insideCollision) // }
{
collisionHandler.RegisterCollision(this.transform, other, sphereID);
}
}
} }
} }
\ No newline at end of file
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;
namespace GuidewireSim
{
public class CollisionDetectionVessel : MonoBehaviour
{
SimulationLoop simulationLoop; //!< The SimulationLoop component in the Simulation GameObject
CollisionHandler collisionHandler; //!< The CollisionHandler component in the Simulation GameObject
private void Awake()
{
simulationLoop = FindObjectOfType<SimulationLoop>();
Assert.IsNotNull(simulationLoop);
collisionHandler = FindObjectOfType<CollisionHandler>();
Assert.IsNotNull(collisionHandler);
}
// private void OnCollisionEnter(Collision other)
// {
// // ContactPoint contactPoint = other.GetContact(0);
// // DebugExtension.DrawPoint(contactPoint.point, Color.black);
// int sphereID = 1;
// collisionHandler.RegisterCollision(other.transform, other, sphereID);
// }
// private void OnCollisionStay(Collision other)
// {
// // ContactPoint contactPoint = other.GetContact(0);
// // DebugExtension.DrawPoint(contactPoint.point, Color.black);
// int sphereID = 1;
// collisionHandler.RegisterCollision(other.transform, other, sphereID);
// }
private int YieldSphereID(Transform sphereTransform)
{
GameObject sphereGO = sphereTransform.gameObject;
for (int sphereIndex = 0; sphereIndex < simulationLoop.SpheresCount; sphereIndex++)
{
if (sphereGO == simulationLoop.spheres[sphereIndex])
{
return sphereIndex;
}
}
Debug.LogWarning("No sphereID could be assigned.");
return 0;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: bb0903acb76666a4a9257caa76e71835
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -16,7 +16,7 @@ namespace GuidewireSim ...@@ -16,7 +16,7 @@ namespace GuidewireSim
* sphere GameObject that is referenced in the second element of @p spheres in SimulationLoop. * sphere GameObject that is referenced in the second element of @p spheres in SimulationLoop.
*/ */
float sphereRadius = 5f; float sphereRadius = 5f; //!< The radius of the sphere elements of the guidewire.
private void Start() private void Start()
{ {
......
...@@ -64,7 +64,7 @@ namespace GuidewireSim ...@@ -64,7 +64,7 @@ namespace GuidewireSim
protected virtual void SolveCollisionConstraint(Vector3 spherePositionPrediction, CollisionPair collisionPair, int solverStep, protected virtual void SolveCollisionConstraint(Vector3 spherePositionPrediction, CollisionPair collisionPair, int solverStep,
out Vector3 deltaPosition) out Vector3 deltaPosition)
{ {
int sphereID = collisionPair.sphereID; // int sphereID = collisionPair.sphereID;
ContactPoint contactPoint = collisionPair.vesselCollider.GetContact(0); ContactPoint contactPoint = collisionPair.vesselCollider.GetContact(0);
Vector3 otherPosition = contactPoint.otherCollider.transform.position; Vector3 otherPosition = contactPoint.otherCollider.transform.position;
......
fileFormatVersion: 2
guid: cea302732c4b76f4ea21bc1b324d78a9
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
...@@ -169,6 +169,7 @@ GameObject: ...@@ -169,6 +169,7 @@ GameObject:
- component: {fileID: 137101341} - component: {fileID: 137101341}
- component: {fileID: 137101339} - component: {fileID: 137101339}
- component: {fileID: 137101340} - component: {fileID: 137101340}
- component: {fileID: 137101344}
m_Layer: 6 m_Layer: 6
m_Name: Sphere_MeshCollider m_Name: Sphere_MeshCollider
m_TagString: Untagged m_TagString: Untagged
...@@ -269,6 +270,18 @@ Transform: ...@@ -269,6 +270,18 @@ Transform:
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 5 m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &137101344
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 137101338}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: bb0903acb76666a4a9257caa76e71835, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &152071858 stripped --- !u!1 &152071858 stripped
GameObject: GameObject:
m_CorrespondingSourceObject: {fileID: 2996864074033366817, guid: 21245aa63eb67904188b68d3b66312df, type: 3} m_CorrespondingSourceObject: {fileID: 2996864074033366817, guid: 21245aa63eb67904188b68d3b66312df, type: 3}
...@@ -286,6 +299,10 @@ PrefabInstance: ...@@ -286,6 +299,10 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 49749013} m_TransformParent: {fileID: 49749013}
m_Modifications: m_Modifications:
- target: {fileID: 163888678, guid: 71f983e886cdf6b418bb6e5402e7361d, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 163888678, guid: 71f983e886cdf6b418bb6e5402e7361d, type: 3} - target: {fileID: 163888678, guid: 71f983e886cdf6b418bb6e5402e7361d, type: 3}
propertyPath: insideCollision propertyPath: insideCollision
value: 0 value: 0
...@@ -425,6 +442,10 @@ PrefabInstance: ...@@ -425,6 +442,10 @@ PrefabInstance:
propertyPath: fixedTimeStep propertyPath: fixedTimeStep
value: 0.02 value: 0.02
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 4233146888435007091, guid: 0e128b35dc3ea6746b6de609560d672d, type: 3}
propertyPath: constraintSolverSteps
value: 1000
objectReference: {fileID: 0}
- target: {fileID: 4233146888435007091, guid: 0e128b35dc3ea6746b6de609560d672d, type: 3} - target: {fileID: 4233146888435007091, guid: 0e128b35dc3ea6746b6de609560d672d, type: 3}
propertyPath: spheres.Array.data[0] propertyPath: spheres.Array.data[0]
value: value:
...@@ -5375,6 +5396,10 @@ PrefabInstance: ...@@ -5375,6 +5396,10 @@ PrefabInstance:
m_Modification: m_Modification:
m_TransformParent: {fileID: 49749013} m_TransformParent: {fileID: 49749013}
m_Modifications: m_Modifications:
- target: {fileID: 163888678, guid: 71f983e886cdf6b418bb6e5402e7361d, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
- target: {fileID: 163888678, guid: 71f983e886cdf6b418bb6e5402e7361d, type: 3} - target: {fileID: 163888678, guid: 71f983e886cdf6b418bb6e5402e7361d, type: 3}
propertyPath: insideCollision propertyPath: insideCollision
value: 0 value: 0
......
...@@ -6,34 +6,34 @@ EditorUserSettings: ...@@ -6,34 +6,34 @@ EditorUserSettings:
serializedVersion: 4 serializedVersion: 4
m_ConfigSettings: m_ConfigSettings:
RecentlyUsedScenePath-0: RecentlyUsedScenePath-0:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814cc001b14d71dfa2fc61608d22f1ddcc41cdff79bc3dae3ccf2 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc29affd6e2f3c1
flags: 0 flags: 0
RecentlyUsedScenePath-1: RecentlyUsedScenePath-1:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814cc001b14d71d8b0fc61608d2 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc2ebf8d7ffe6ccdbdbeee7faf9fae1
flags: 0 flags: 0
RecentlyUsedScenePath-2: RecentlyUsedScenePath-2:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019f511d51f860a12c20d05 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc2ebefdcece296cbd1a9e6ed
flags: 0 flags: 0
RecentlyUsedScenePath-3: RecentlyUsedScenePath-3:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019f511d51ff72a12c20d05f8cc0fd8e2dbc29affd6e2f3c1 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc2ebc8dde7e8cffbdba7f7bae5e0f1e1e8
flags: 0 flags: 0
RecentlyUsedScenePath-4: RecentlyUsedScenePath-4:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06d540d1137f7180c18c93b18021c07e90707fa3d1602cd28cc0acd2029c51008d7fb1cc3ead4d8c0a4cde5eeccc7 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019f511d51ff72a12c20d05f8cc0fd8e2dbc29affd6e2f3c1
flags: 0 flags: 0
RecentlyUsedScenePath-5: RecentlyUsedScenePath-5:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019f608cd1fda1a23fe1715dad42bd0f1dcd7dafe96fee9d1cac6 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc2ebd9ccf9e6d1d9d7b4bce1fee7ecec
flags: 0 flags: 0
RecentlyUsedScenePath-6: RecentlyUsedScenePath-6:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc29affd6e2f3c1 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc2ebd8d7ffe6ccdbdbeee7faf9fae1
flags: 0 flags: 0
RecentlyUsedScenePath-7: RecentlyUsedScenePath-7:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc2ebf8d7ffe6ccdbdbeee7faf9fae1 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019f608cd1fda1a23fe1715dad42bd0f1dcd7dafe96fee9d1cac6
flags: 0 flags: 0
RecentlyUsedScenePath-8: RecentlyUsedScenePath-8:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc2ebefdcece296cbd1a9e6ed value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019f608cd1fda1a23fe1715dad42bd0f1dcd7dafe98baa9cdd0d6b4eb
flags: 0 flags: 0
RecentlyUsedScenePath-9: RecentlyUsedScenePath-9:
value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06e372e093ae00f1a34c6190306181af41814d2150019e60dc71ff72a12c20d05f8cc0fd8e2dbc2ebc8dde7e8cffbdba7f7bae5e0f1e1e8 value: 224247031146467c18070827072a4d1529360b39293c357f0e26113febf33d37ecd333faf3093c393707d06d540d1137f7180c18c93b18021c07e90707fa3d1602cd28cc0acd2029c51008d7fb1cc3ead4d8c0a4cde5eeccc7
flags: 0 flags: 0
vcSharedLogLevel: vcSharedLogLevel:
value: 0d5e400f0650 value: 0d5e400f0650
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment