Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Simulating Guidewires In Blood Vessels
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Robin Viellieber
Simulating Guidewires In Blood Vessels
Commits
b41902f7
Commit
b41902f7
authored
Jan 22, 2023
by
rv3Dcv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove execution time measurement
Also add clean code
parent
72bac8b8
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
84 additions
and
290 deletions
+84
-290
CollisionDetectionPrimitive.cs
...s/Guidewire_Assets/Scripts/CollisionDetectionPrimitive.cs
+13
-79
CollisionDetectionVessel.cs
...sets/Guidewire_Assets/Scripts/CollisionDetectionVessel.cs
+5
-0
CollisionHandler.cs
...ation/Assets/Guidewire_Assets/Scripts/CollisionHandler.cs
+21
-5
CollisionPair.cs
...mulation/Assets/Guidewire_Assets/Scripts/CollisionPair.cs
+6
-3
CollisionSolvingStep.cs
...n/Assets/Guidewire_Assets/Scripts/CollisionSolvingStep.cs
+36
-124
CollisionSolvingStep_UnityVariant.cs
...ewire_Assets/Scripts/CollisionSolvingStep_UnityVariant.cs
+3
-8
ConstraintSolvingStep.cs
.../Assets/Guidewire_Assets/Scripts/ConstraintSolvingStep.cs
+0
-14
DirectorsDrawer.cs
...lation/Assets/Guidewire_Assets/Scripts/DirectorsDrawer.cs
+0
-1
PredictionStep.cs
...ulation/Assets/Guidewire_Assets/Scripts/PredictionStep.cs
+0
-5
SimulationLoop.cs
...ulation/Assets/Guidewire_Assets/Scripts/SimulationLoop.cs
+0
-51
No files found.
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/CollisionDetectionPrimitive.cs
View file @
b41902f7
...
@@ -7,6 +7,10 @@ using UnityEngine.Assertions;
...
@@ -7,6 +7,10 @@ using UnityEngine.Assertions;
namespace
GuidewireSim
namespace
GuidewireSim
{
{
/**
* This class is responsible for tracking collisions of the object it is attached to. Attach this component only to sphere objects
* of the guidewire.
*/
public
class
CollisionDetectionPrimitive
:
MonoBehaviour
public
class
CollisionDetectionPrimitive
:
MonoBehaviour
{
{
SimulationLoop
simulationLoop
;
//!< The SimulationLoop component in the Simulation GameObject
SimulationLoop
simulationLoop
;
//!< The SimulationLoop component in the Simulation GameObject
...
@@ -31,6 +35,9 @@ namespace GuidewireSim
...
@@ -31,6 +35,9 @@ namespace GuidewireSim
AssignSphereID
();
AssignSphereID
();
}
}
/**
* Assigns the unique ID of the object sphere it is attached to to #sphereID.
*/
private
void
AssignSphereID
()
private
void
AssignSphereID
()
{
{
GameObject
thisSphere
=
this
.
transform
.
gameObject
;
GameObject
thisSphere
=
this
.
transform
.
gameObject
;
...
@@ -47,6 +54,9 @@ namespace GuidewireSim
...
@@ -47,6 +54,9 @@ namespace GuidewireSim
Debug
.
LogWarning
(
"No sphereID could be assigned."
);
Debug
.
LogWarning
(
"No sphereID could be assigned."
);
}
}
/**
* Registers a collision that Unity's collision detection detected.
*/
private
void
OnCollisionEnter
(
Collision
other
)
private
void
OnCollisionEnter
(
Collision
other
)
{
{
Debug
.
Log
(
"trigger "
+
transform
.
name
);
Debug
.
Log
(
"trigger "
+
transform
.
name
);
...
@@ -54,90 +64,14 @@ namespace GuidewireSim
...
@@ -54,90 +64,14 @@ namespace GuidewireSim
collisionHandler
.
RegisterCollision
(
this
.
transform
,
other
,
sphereID
);
collisionHandler
.
RegisterCollision
(
this
.
transform
,
other
,
sphereID
);
}
}
/**
* Registers a collision that Unity's collision detection detected.
*/
private
void
OnCollisionStay
(
Collision
other
)
private
void
OnCollisionStay
(
Collision
other
)
{
{
Debug
.
Log
(
"trigger "
+
transform
.
name
);
Debug
.
Log
(
"trigger "
+
transform
.
name
);
collisionHandler
.
RegisterCollision
(
this
.
transform
,
other
,
sphereID
);
collisionHandler
.
RegisterCollision
(
this
.
transform
,
other
,
sphereID
);
}
}
// private void OnTriggerEnter(Collider other)
// {
// Debug.Log("trigger " + transform.name);
// if (!insideCollision)
// {
// collisionHandler.RegisterCollision(this.transform, other, sphereID);
// Debug.Log("pos" + this.transform.position);
// Debug.Log("colpos" + this.transform.GetComponent<SphereCollider>().center);
// Debug.Log("otherpos" + other.transform.position);
// Vector3 otherClosestPoint = other.ClosestPoint(this.transform.position);
// Debug.Log("otherclosestpoint" + otherClosestPoint.ToString("e4"));
// Debug.Log("thisclosestpoint" + this.transform.GetComponent<SphereCollider>().ClosestPoint(otherClosestPoint).ToString("e4"));
// 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"));
// }
// }
// private void OnTriggerStay(Collider other)
// {
// Debug.Log("trigger " + transform.name);
// if (!insideCollision)
// {
// collisionHandler.RegisterCollision(this.transform, other, sphereID);
// }
// }
// private void OnTriggerExit(Collider other)
// {
// if (insideCollision)
// {
// Debug.Log("trigger " + transform.name);
// collisionHandler.RegisterCollision(this.transform, other, sphereID);
// }
// }
// 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)
// // {
// // collisionHandler.RegisterCollision(this.transform, other, sphereID);
// // Debug.Log("pos" + this.transform.position);
// // 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"));
// // Debug.Log("thisclosestpoint" + this.transform.GetComponent<SphereCollider>().ClosestPoint(otherClosestPoint).ToString("e4"));
// // 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"));
// // }
// }
}
}
}
}
\ No newline at end of file
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/CollisionDetectionVessel.cs
View file @
b41902f7
...
@@ -5,6 +5,10 @@ using UnityEngine.Assertions;
...
@@ -5,6 +5,10 @@ using UnityEngine.Assertions;
namespace
GuidewireSim
namespace
GuidewireSim
{
{
/**
* Similarly to CollisionDetectionPrimitive, this class is responsible for tracking collisions of the object it is attached to.
* Attach this component only to blood vessel objects.
*/
public
class
CollisionDetectionVessel
:
MonoBehaviour
public
class
CollisionDetectionVessel
:
MonoBehaviour
{
{
SimulationLoop
simulationLoop
;
//!< The SimulationLoop component in the Simulation GameObject
SimulationLoop
simulationLoop
;
//!< The SimulationLoop component in the Simulation GameObject
...
@@ -18,6 +22,7 @@ namespace GuidewireSim
...
@@ -18,6 +22,7 @@ namespace GuidewireSim
collisionHandler
=
FindObjectOfType
<
CollisionHandler
>();
collisionHandler
=
FindObjectOfType
<
CollisionHandler
>();
Assert
.
IsNotNull
(
collisionHandler
);
Assert
.
IsNotNull
(
collisionHandler
);
}
}
// private void OnCollisionEnter(Collision other)
// private void OnCollisionEnter(Collision other)
// {
// {
// // ContactPoint contactPoint = other.GetContact(0);
// // ContactPoint contactPoint = other.GetContact(0);
...
...
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/CollisionHandler.cs
View file @
b41902f7
...
@@ -6,6 +6,9 @@ using UnityEngine.Assertions;
...
@@ -6,6 +6,9 @@ using UnityEngine.Assertions;
namespace
GuidewireSim
namespace
GuidewireSim
{
{
/**
* This class manages all collisions that should be resolved, i.e. the collisions of the last frame.
*/
public
class
CollisionHandler
:
MonoBehaviour
public
class
CollisionHandler
:
MonoBehaviour
{
{
public
List
<
CollisionPair
>
registeredCollisions
;
//!< All collisions that occured between the last and the current frame in OnTriggerEnter.
public
List
<
CollisionPair
>
registeredCollisions
;
//!< All collisions that occured between the last and the current frame in OnTriggerEnter.
...
@@ -17,30 +20,43 @@ namespace GuidewireSim
...
@@ -17,30 +20,43 @@ namespace GuidewireSim
*/
*/
float
sphereRadius
=
5f
;
//!< The radius of the sphere elements of the guidewire.
float
sphereRadius
=
5f
;
//!< The radius of the sphere elements of the guidewire.
public
bool
collided
=
false
;
private
void
Start
()
private
void
Start
()
{
{
registeredCollisions
=
new
List
<
CollisionPair
>();
registeredCollisions
=
new
List
<
CollisionPair
>();
}
}
public
void
RegisterCollision
(
Transform
sphere
,
Collision
vesselCollider
,
int
sphereID
)
/**
* Registers a collision by adding it to #registeredCollisions.
* @param sphere The sphere of the guidewire that collided.
* @param collision The Collision instance.
* @param sphereID The unique ID of @p sphere.
*/
public
void
RegisterCollision
(
Transform
sphere
,
Collision
collision
,
int
sphereID
)
{
{
CollisionPair
registeredCollision
=
new
CollisionPair
(
sphere
,
vesselCollider
,
sphereID
);
CollisionPair
registeredCollision
=
new
CollisionPair
(
sphere
,
collision
,
sphereID
);
registeredCollisions
.
Add
(
registeredCollision
);
registeredCollisions
.
Add
(
registeredCollision
);
collided
=
true
;
}
}
/**
* Clears the list of all registered collisions.
*/
public
void
ResetRegisteredCollisions
()
public
void
ResetRegisteredCollisions
()
{
{
registeredCollisions
.
Clear
();
registeredCollisions
.
Clear
();
}
}
/**
* Sets the position of the collider of each sphere to the sphere's position prediction.
* @note The position of the collider is implicitly set by setting the colliders center argument.
* @param spheresCount The count of all spheres of the guidewire. Equals the length of @p spherePositionPredictions.
* @param spherePositionPredictions The prediction of the position at the current frame of each sphere (in this case of the last frame).
* @param spherePositions The position at the current frame of each sphere.
*/
public
void
SetCollidersToPredictions
(
int
spheresCount
,
Vector3
[]
spherePositionPredictions
,
Vector3
[]
spherePositions
)
public
void
SetCollidersToPredictions
(
int
spheresCount
,
Vector3
[]
spherePositionPredictions
,
Vector3
[]
spherePositions
)
{
{
for
(
int
sphereIndex
=
0
;
sphereIndex
<
spheresCount
;
sphereIndex
++)
for
(
int
sphereIndex
=
0
;
sphereIndex
<
spheresCount
;
sphereIndex
++)
{
{
// Siehe Blatt 10 für die Berechnung von .center
Vector3
centerPosition
=
(
spherePositionPredictions
[
sphereIndex
]
-
spherePositions
[
sphereIndex
])
/
(
2
*
sphereRadius
);
Vector3
centerPosition
=
(
spherePositionPredictions
[
sphereIndex
]
-
spherePositions
[
sphereIndex
])
/
(
2
*
sphereRadius
);
sphereColliders
[
sphereIndex
].
center
=
centerPosition
;
sphereColliders
[
sphereIndex
].
center
=
centerPosition
;
}
}
...
...
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/CollisionPair.cs
View file @
b41902f7
...
@@ -4,11 +4,14 @@ using UnityEngine;
...
@@ -4,11 +4,14 @@ using UnityEngine;
namespace
GuidewireSim
namespace
GuidewireSim
{
{
/**
* Carries all information of a collision that occured.
*/
public
struct
CollisionPair
public
struct
CollisionPair
{
{
public
Transform
sphere
;
public
Transform
sphere
;
//!< The sphere object of the guidewire that was part of the collision.
public
Collision
vesselCollider
;
public
Collision
vesselCollider
;
//!< The blood vessel object that was part of the collision.
public
int
sphereID
;
public
int
sphereID
;
//!< The ID of the sphere object of the guidewire that was part of the collision.
public
CollisionPair
(
Transform
sphere
,
Collision
vesselCollider
,
int
sphereID
)
public
CollisionPair
(
Transform
sphere
,
Collision
vesselCollider
,
int
sphereID
)
{
{
...
...
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/CollisionSolvingStep.cs
View file @
b41902f7
This diff is collapsed.
Click to expand it.
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/CollisionSolvingStep_UnityVariant.cs
View file @
b41902f7
...
@@ -4,6 +4,9 @@ using UnityEngine;
...
@@ -4,6 +4,9 @@ using UnityEngine;
namespace
GuidewireSim
namespace
GuidewireSim
{
{
/**
* A specilization of CollisionSolvingStep that uses Unity's provided collision data.
*/
public
class
CollisionSolvingStep_UnityVariant
:
CollisionSolvingStep
public
class
CollisionSolvingStep_UnityVariant
:
CollisionSolvingStep
{
{
protected
override
void
SolveCollisionConstraint
(
Vector3
spherePositionPrediction
,
CollisionPair
collisionPair
,
int
solverStep
,
protected
override
void
SolveCollisionConstraint
(
Vector3
spherePositionPrediction
,
CollisionPair
collisionPair
,
int
solverStep
,
...
@@ -13,11 +16,7 @@ namespace GuidewireSim
...
@@ -13,11 +16,7 @@ namespace GuidewireSim
Vector3
otherPosition
=
contactPoint
.
otherCollider
.
transform
.
position
;
Vector3
otherPosition
=
contactPoint
.
otherCollider
.
transform
.
position
;
Vector3
closestSurfacePoint
=
contactPoint
.
point
;
Vector3
closestSurfacePoint
=
contactPoint
.
point
;
// Vector3 normalVector = (closestSurfacePoint - otherPosition).normalized;
Vector3
normalVector
=
contactPoint
.
normal
;
Vector3
normalVector
=
contactPoint
.
normal
;
// Debug.Log(normalVector.ToString("e2"));
// Debug.Log(closestSurfacePoint.ToString("e5"));
// Debug.Log((40-Mathf.Sqrt(50) - closestSurfacePoint[2]).ToString("e5"));
if
(
solverStep
==
0
)
if
(
solverStep
==
0
)
{
{
...
@@ -25,10 +24,6 @@ namespace GuidewireSim
...
@@ -25,10 +24,6 @@ namespace GuidewireSim
}
}
deltaPosition
=
CalculateDeltaPosition
(
spherePositionPrediction
,
closestSurfacePoint
,
normalVector
);
deltaPosition
=
CalculateDeltaPosition
(
spherePositionPrediction
,
closestSurfacePoint
,
normalVector
);
// Vector3 correction = spherePositionPrediction + 0.001f * deltaPosition;
// float difference = Vector3.Distance(spherePositionPrediction, correction);
// Debug.Log(difference.ToString("e3"));
}
}
}
}
}
}
\ No newline at end of file
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/ConstraintSolvingStep.cs
View file @
b41902f7
...
@@ -356,18 +356,10 @@ public class ConstraintSolvingStep : MonoBehaviour
...
@@ -356,18 +356,10 @@ public class ConstraintSolvingStep : MonoBehaviour
Assert
.
IsTrue
(
sphereIndex
>=
0
);
Assert
.
IsTrue
(
sphereIndex
>=
0
);
Assert
.
AreApproximatelyEqual
(
1f
,
mathHelper
.
QuaternionLength
(
cylinderOrientationPredictions
[
sphereIndex
]),
tolerance
:
0.01f
);
Assert
.
AreApproximatelyEqual
(
1f
,
mathHelper
.
QuaternionLength
(
cylinderOrientationPredictions
[
sphereIndex
]),
tolerance
:
0.01f
);
// spherePositionPredictions[sphereIndex] += Mathf.Pow(1 - (1 - stretchStiffness), 1 / 1000f) * deltaPositionOne;
// spherePositionPredictions[sphereIndex + 1] += Mathf.Pow(1 - (1 - stretchStiffness), 1 / 1000f) * deltaPositionTwo;
// cylinderOrientationPredictions[sphereIndex] += Mathf.Pow(1 - (1 - stretchStiffness), 1 / 1000f) * deltaOrientation;
spherePositionPredictions
[
sphereIndex
]
+=
stretchStiffness
*
deltaPositionOne
;
spherePositionPredictions
[
sphereIndex
]
+=
stretchStiffness
*
deltaPositionOne
;
spherePositionPredictions
[
sphereIndex
+
1
]
+=
stretchStiffness
*
deltaPositionTwo
;
spherePositionPredictions
[
sphereIndex
+
1
]
+=
stretchStiffness
*
deltaPositionTwo
;
cylinderOrientationPredictions
[
sphereIndex
]
+=
stretchStiffness
*
deltaOrientation
;
cylinderOrientationPredictions
[
sphereIndex
]
+=
stretchStiffness
*
deltaOrientation
;
// spherePositionPredictions[sphereIndex] += deltaPositionOne;
// spherePositionPredictions[sphereIndex + 1] += deltaPositionTwo;
// cylinderOrientationPredictions[sphereIndex] += deltaOrientation;
cylinderOrientationPredictions
[
sphereIndex
].
Normalize
();
cylinderOrientationPredictions
[
sphereIndex
].
Normalize
();
Assert
.
AreApproximatelyEqual
(
1f
,
mathHelper
.
QuaternionLength
(
cylinderOrientationPredictions
[
sphereIndex
]),
tolerance
:
0.01f
);
Assert
.
AreApproximatelyEqual
(
1f
,
mathHelper
.
QuaternionLength
(
cylinderOrientationPredictions
[
sphereIndex
]),
tolerance
:
0.01f
);
...
@@ -387,15 +379,9 @@ public class ConstraintSolvingStep : MonoBehaviour
...
@@ -387,15 +379,9 @@ public class ConstraintSolvingStep : MonoBehaviour
Assert
.
AreApproximatelyEqual
(
1f
,
mathHelper
.
QuaternionLength
(
cylinderOrientationPredictions
[
cylinderIndex
]),
tolerance
:
0.01f
);
Assert
.
AreApproximatelyEqual
(
1f
,
mathHelper
.
QuaternionLength
(
cylinderOrientationPredictions
[
cylinderIndex
]),
tolerance
:
0.01f
);
Assert
.
AreApproximatelyEqual
(
1f
,
mathHelper
.
QuaternionLength
(
cylinderOrientationPredictions
[
cylinderIndex
+
1
]),
tolerance
:
0.01f
);
Assert
.
AreApproximatelyEqual
(
1f
,
mathHelper
.
QuaternionLength
(
cylinderOrientationPredictions
[
cylinderIndex
+
1
]),
tolerance
:
0.01f
);
// cylinderOrientationPredictions[cylinderIndex] += Mathf.Pow(1 - (1 - bendStiffness), 1 / 1000f) * deltaOrientationOne;
// cylinderOrientationPredictions[cylinderIndex + 1] += Mathf.Pow(1 - (1 - bendStiffness), 1 / 1000f) * deltaOrientationTwo;
cylinderOrientationPredictions
[
cylinderIndex
]
+=
bendStiffness
*
deltaOrientationOne
;
cylinderOrientationPredictions
[
cylinderIndex
]
+=
bendStiffness
*
deltaOrientationOne
;
cylinderOrientationPredictions
[
cylinderIndex
+
1
]
+=
bendStiffness
*
deltaOrientationTwo
;
cylinderOrientationPredictions
[
cylinderIndex
+
1
]
+=
bendStiffness
*
deltaOrientationTwo
;
// cylinderOrientationPredictions[cylinderIndex] += deltaOrientationOne;
// cylinderOrientationPredictions[cylinderIndex + 1] += deltaOrientationTwo;
cylinderOrientationPredictions
[
cylinderIndex
].
Normalize
();
cylinderOrientationPredictions
[
cylinderIndex
].
Normalize
();
cylinderOrientationPredictions
[
cylinderIndex
+
1
].
Normalize
();
cylinderOrientationPredictions
[
cylinderIndex
+
1
].
Normalize
();
...
...
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/DirectorsDrawer.cs
View file @
b41902f7
...
@@ -35,7 +35,6 @@ public class DirectorsDrawer : MonoBehaviour
...
@@ -35,7 +35,6 @@ public class DirectorsDrawer : MonoBehaviour
DrawDirectors
(
simulationLoop
.
cylinderPositions
,
simulationLoop
.
directors
);
DrawDirectors
(
simulationLoop
.
cylinderPositions
,
simulationLoop
.
directors
);
}
}
/**
/**
* Draws the director basis of each orientation element as arrows.
* Draws the director basis of each orientation element as arrows.
* @param cylinderPositions The center of mass of each cylinder, i.e. the position of each orientation element.
* @param cylinderPositions The center of mass of each cylinder, i.e. the position of each orientation element.
...
...
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/PredictionStep.cs
View file @
b41902f7
...
@@ -29,18 +29,13 @@ public class PredictionStep : MonoBehaviour
...
@@ -29,18 +29,13 @@ public class PredictionStep : MonoBehaviour
*/
*/
public
Vector3
[]
PredictSphereVelocities
(
Vector3
[]
sphereVelocities
,
float
[]
sphereInverseMasses
,
Vector3
[]
sphereExternalForces
)
public
Vector3
[]
PredictSphereVelocities
(
Vector3
[]
sphereVelocities
,
float
[]
sphereInverseMasses
,
Vector3
[]
sphereExternalForces
)
{
{
// Debug.Log("dt " + Time.deltaTime + " fdt " + Time.fixedDeltaTime);
Vector3
calc
=
Time
.
deltaTime
*
sphereInverseMasses
[
1
]
*
sphereExternalForces
[
1
];
Vector3
calc
=
Time
.
deltaTime
*
sphereInverseMasses
[
1
]
*
sphereExternalForces
[
1
];
// Debug.Log("dt " + Time.deltaTime + " invMass " + sphereInverseMasses[1] + " extF " + sphereExternalForces[1].ToString("e3")
// + " calc " + calc.ToString("e3") + " vorherigeVel " + sphereVelocities[1].ToString("e3"));
for
(
int
sphereIndex
=
0
;
sphereIndex
<
sphereVelocities
.
Length
;
sphereIndex
++)
for
(
int
sphereIndex
=
0
;
sphereIndex
<
sphereVelocities
.
Length
;
sphereIndex
++)
{
{
sphereVelocities
[
sphereIndex
]
+=
Time
.
deltaTime
*
sphereInverseMasses
[
sphereIndex
]
*
sphereExternalForces
[
sphereIndex
];
sphereVelocities
[
sphereIndex
]
+=
Time
.
deltaTime
*
sphereInverseMasses
[
sphereIndex
]
*
sphereExternalForces
[
sphereIndex
];
}
}
// Debug.Log("velocity " + sphereVelocities[1].ToString("e3"));
return
sphereVelocities
;
return
sphereVelocities
;
}
}
...
...
GuidewireSimulation/GuidewireSimulation/Assets/Guidewire_Assets/Scripts/SimulationLoop.cs
View file @
b41902f7
...
@@ -101,17 +101,6 @@ public class SimulationLoop : MonoBehaviour
...
@@ -101,17 +101,6 @@ public class SimulationLoop : MonoBehaviour
public
int
SpheresCount
{
get
;
private
set
;
}
//!< The count of all #spheres of the guidewire.
public
int
SpheresCount
{
get
;
private
set
;
}
//!< The count of all #spheres of the guidewire.
public
int
CylinderCount
{
get
;
private
set
;
}
//!< The count of all #cylinders of the guidewire.
public
int
CylinderCount
{
get
;
private
set
;
}
//!< The count of all #cylinders of the guidewire.
float
elapsedTime
=
0
;
float
timeConstraintSolving
=
0
;
float
timeUpdateStep
=
0
;
float
timePredictionStep
=
0
;
float
timeAdaptCalculationsStep
=
0
;
float
timeSetCollidersStep
=
0
;
float
timeCompleteFrame
=
0
;
float
timeCompleteFrameMeasure
=
0
;
float
timeMeasure
=
0
;
float
measurePoint
=
5f
;
private
void
Awake
()
private
void
Awake
()
{
{
Assert
.
IsFalse
(
spheres
.
Length
==
0
);
Assert
.
IsFalse
(
spheres
.
Length
==
0
);
...
@@ -162,8 +151,6 @@ public class SimulationLoop : MonoBehaviour
...
@@ -162,8 +151,6 @@ public class SimulationLoop : MonoBehaviour
if
(
ExecuteSingleLoopTest
)
return
;
if
(
ExecuteSingleLoopTest
)
return
;
PerformSimulationLoop
();
PerformSimulationLoop
();
elapsedTime
+=
Time
.
deltaTime
;
}
}
/**
/**
...
@@ -204,49 +191,11 @@ public class SimulationLoop : MonoBehaviour
...
@@ -204,49 +191,11 @@ public class SimulationLoop : MonoBehaviour
*/
*/
public
void
PerformSimulationLoop
()
public
void
PerformSimulationLoop
()
{
{
if
(
collisionHandler
.
collided
)
{
timeMeasure
=
Time
.
realtimeSinceStartup
;
timeCompleteFrameMeasure
=
Time
.
realtimeSinceStartup
;
}
PerformConstraintSolvingStep
();
PerformConstraintSolvingStep
();
if
(
collisionHandler
.
collided
)
{
timeConstraintSolving
=
Time
.
realtimeSinceStartup
-
timeMeasure
;
timeMeasure
=
Time
.
realtimeSinceStartup
;
}
PerformUpdateStep
();
PerformUpdateStep
();
if
(
collisionHandler
.
collided
)
{
timeUpdateStep
=
Time
.
realtimeSinceStartup
-
timeMeasure
;
timeMeasure
=
Time
.
realtimeSinceStartup
;
}
PerformPredictionStep
();
PerformPredictionStep
();
if
(
collisionHandler
.
collided
)
{
timePredictionStep
=
Time
.
realtimeSinceStartup
-
timeMeasure
;
timeMeasure
=
Time
.
realtimeSinceStartup
;
}
AdaptCalculations
();
AdaptCalculations
();
if
(
collisionHandler
.
collided
)
{
timeAdaptCalculationsStep
=
Time
.
realtimeSinceStartup
-
timeMeasure
;
timeMeasure
=
Time
.
realtimeSinceStartup
;
}
SetCollidersStep
();
SetCollidersStep
();
if
(
collisionHandler
.
collided
)
{
timeSetCollidersStep
=
Time
.
realtimeSinceStartup
-
timeMeasure
;
timeCompleteFrame
=
Time
.
realtimeSinceStartup
-
timeCompleteFrameMeasure
;
Time
.
timeScale
=
0f
;
Debug
.
Log
(
"execution time constraint solving: "
+
timeConstraintSolving
.
ToString
(
"F7"
));
Debug
.
Log
(
"execution time update step: "
+
timeUpdateStep
.
ToString
(
"F7"
));
Debug
.
Log
(
"execution time prediction step: "
+
timePredictionStep
.
ToString
(
"F7"
));
Debug
.
Log
(
"execution time adapt calculations: "
+
timeAdaptCalculationsStep
.
ToString
(
"F7"
));
Debug
.
Log
(
"execution time set colliders: "
+
timeSetCollidersStep
.
ToString
(
"F7"
));
Debug
.
Log
(
"execution time whole frame: "
+
timeCompleteFrame
.
ToString
(
"F7"
));
}
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment