Class CollisionSet
Defines two groups of objects that will be tested for collision against each other.
Inherited Members
Namespace: ABB.Robotics.RobotStudio.Stations
Assembly: ABB.Robotics.RobotStudio.Stations.dll
Syntax
sistent("CollisionSet")]
public sealed class CollisionSet : ProjectObject
Constructors
CollisionSet()
Initializes a new instance of the CollisionSet class.
Declaration
public CollisionSet()
Examples
New CollisionSet.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
Properties
Active
Gets or set whether this set will be included when checking collisions
Declaration
public bool Active { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Examples
Get/Set Active.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
CollisionColor
Gets or sets the color of colliding objects
Declaration
public Color CollisionColor { get; set; }
Property Value
Type | Description |
---|---|
Color |
Examples
Get/Set CollisionColor.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
FirstGroup
Gets the first group of objects
Declaration
public CollisionObjectCollection FirstGroup { get; }
Property Value
Type | Description |
---|---|
CollisionObjectCollection |
Examples
Get FirstGroup.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
Highlight
Gets or sets whether colliding objects will be highlighted.
Declaration
public bool Highlight { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Examples
Get/Set Highlight.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
HighlightLevel
Gets or sets which level of the object hierarchy should be highlighted.
Declaration
public CollisionHighlightLevel HighlightLevel { get; set; }
Property Value
Type | Description |
---|---|
CollisionHighlightLevel |
Remarks
Level Body or Face is only used for parts with geometry. If several bodies/faces in a part are colliding, only one will be highlighted and which one is undefined.
IncludeInvisible
Gets or sets if invisible objects should be considered for collision in this collision set.
Declaration
public bool IncludeInvisible { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
NearMissColor
Gets or sets the color of objects in a near miss
Declaration
public Color NearMissColor { get; set; }
Property Value
Type | Description |
---|---|
Color |
Examples
Get/Set NearMissColor.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
NearMissDistance
Gets or sets the distance at which near miss occurs
Declaration
public double NearMissDistance { get; set; }
Property Value
Type | Description |
---|---|
Double |
Remarks
A value of 0 means near miss is disabled.
Examples
Get/Set NearMissDistance.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
Parent
The Parent property returns a reference to the parent Station object.
Declaration
public override ProjectObject Parent { get; }
Property Value
Type | Description |
---|---|
ProjectObject | Returns a ProjectObject object. |
Overrides
Remarks
You can use the Parent property to navigate up from the current object to the object one level higher.
SecondGroup
Gets the second group of objects
Declaration
public CollisionObjectCollection SecondGroup { get; }
Property Value
Type | Description |
---|---|
CollisionObjectCollection |
Examples
Get SecondGroup.
public void CollisionDetection()
{
Project.UndoContext.BeginUndoStep("CollisionDetection");
try
{
Station station = Station.ActiveStation;
#region CollisionDetectionPoint1
// Create two parts and bodies to use in collision detection.
Part p1 = new Part();
p1.Name = "My Part1";
Part p2 = new Part();
p2.Name = "My Part2";
station.GraphicComponents.Add(p1);
station.GraphicComponents.Add(p2);
#endregion
// Create two boxes.
Body box1 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box1.Name = "My Box1";
Body box2 = Body.CreateSolidBox(new Matrix4(Vector3.XVector, 0.0),
new Vector3(0.1, 0.1, 0.1));
box2.Name = "My Box2";
// Move box2 0.105 meters along the X-axis .
box2.Transform.X = box2.Transform.X + 0.105;
// Add the boxes to the bodies.
p1.Bodies.Add(box1);
p2.Bodies.Add(box2);
// Manually check to see if there is a collision between the two parts.
// Also tests for a near miss, defined as being within 0.01 meter from each other.
#region CollisionDetectionPoint2
CollisionType colType = CollisionDetector.CheckCollision(p1, p2, 0.01);
switch (colType)
{
case CollisionType.Collision:
Logger.AddMessage(new LogMessage("Part: " + p1.Name
+ " and part: " + p2.Name + " is colliding!"));
break;
case CollisionType.NearMiss:
Logger.AddMessage(new LogMessage("There is a near miss between part: "
+ p1.Name
+ " and part: " + p2.Name + "."));
Vector3 p1Point;
Vector3 p2Point;
Logger.AddMessage(new LogMessage("The distance between them are: "
+ CollisionDetector.MinimumDistance(p1, p2, out p1Point, out p2Point)));
Logger.AddMessage(new LogMessage("The closest points are: "));
Logger.AddMessage(new LogMessage("For part: " + p1.Name + " x: " + p1Point.x
+ " y: " + p1Point.y + " z: " + p1Point.z));
Logger.AddMessage(new LogMessage("For part: " + p2.Name + " x: " + p2Point.x
+ " y: " + p2Point.y + " z: " + p2Point.z));
break;
case CollisionType.None:
Logger.AddMessage(new LogMessage("There is no collision!"));
break;
}
#endregion
// Reset the collision sets and highlights.
CollisionDetector.ResetCollisions();
// Add an event handler to the collision event.
CollisionDetector.Collision += new CollisionEventHandler(myCollisionEventHandler);
// Activate auto check for collisions each time the graphics is updated.
CollisionDetector.AutoCheck = true;
// Test for collisions on polygon level, not just for the bounding boxes.
CollisionDetector.FastCheck = false;
#region CollisionDetectionPoint3
// Add the two boxes to a collision set.
CollisionSet cs = new CollisionSet();
cs.Name = "My CollisionSet";
// Set the near miss distance to 0.01 meters.
cs.NearMissDistance = 0.01;
// Set the near miss color to black.
cs.NearMissColor = System.Drawing.Color.Black;
// Activate this collision set for collision checks.
cs.Active = true;
// Set the collision color to semi-transparent yellow.
cs.CollisionColor = Color.FromArgb(128, System.Drawing.Color.Yellow);
// Turn on highlighting of colliding objects.
cs.Highlight = true;
// Add the collision set to the station.
station.CollisionSets.Add(cs);
// Add the two parts to the two different collision object collections of the collision set.
cs.FirstGroup.Add(p1);
cs.SecondGroup.Add(p2);
#endregion
#region CollisionDetectionPoint4
// Force check the station for collisions.
CollisionDetector.CheckCollisions(station);
// Force check the collision set for collisiosn.
CollisionDetector.CheckCollisions(cs);
#endregion
// Freehand move the boxes in the graphics.
// Notice the messages generated by the event handler code,
// and the change in color of the boxes.
}
catch
{
Project.UndoContext.CancelUndoStep(CancelUndoStepType.Rollback);
throw;
}
finally
{
Project.UndoContext.EndUndoStep();
}
}
private void myCollisionEventHandler(object sender, CollisionEventArgs e)
{
switch (e.CollisionEvent)
{
case CollisionEvent.CollisionStarted:
Logger.AddMessage
(new LogMessage("Collision started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.CollisionEnded:
Logger.AddMessage(new LogMessage("Collision ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissStarted:
Logger.AddMessage(new LogMessage("Near Miss started by collision set: '" + e.CollisionSet.Name
+ "' First part : '" + e.FirstPart.Name
+ "' Second part: '" + e.SecondPart.Name + "'"));
break;
case CollisionEvent.NearMissEnded:
Logger.AddMessage(new LogMessage("Near Miss ended by collision set: '" + e.CollisionSet.Name
+ "' First part : '"
+ e.FirstPart.Name + "' Second part: '" + e.SecondPart.Name + "'"));
break;
default:
break;
}
}
ShowMarkup
Gets or sets if a markup should be displayed at the approximate point of collision or near miss.
Declaration
public bool ShowMarkup { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
AfterLoad(PimDocument)
Declaration
protected override void AfterLoad(PimDocument doc)
Parameters
Type | Name | Description |
---|---|---|
RobotStudio.API.Persistence.PimDocument | doc |
Overrides
GetCurrentState()
Returns the current state of collisions in the set.
Declaration
public CollisionType GetCurrentState()
Returns
Type | Description |
---|---|
CollisionType | CollisionType.Collision if there is any collision occurring, CollisionType.NearMiss if there is any near miss (but no collision) occurring, CollisionType.None otherwise. |
OnCreatingObject()
Declaration
protected override void OnCreatingObject()