Verlet Intergration Soft Body
Loading...
Searching...
No Matches
PhysicsCSAlevlProject.Mesh Class Reference

The Mesh class stores everything that should be loadable in and savebal for undo/redo functionality to file saving. More...

Classes

class  MeshStick

Public Member Functions

void RestoreStickReferences ()
Mesh DeepCopy ()
int AddParticle (Vector2 position, float mass, bool isPinned, Color color, Vector2? size=null, OscillatingParticle oscillatingProps=null)
void ResetMesh ()
void BuildPolygon (KeyboardState keyboardState, KeyboardState previousKeyboardState, MouseState mouseState, MouseState previousMouseState, bool imguiWantsMouse, Action beforeChange=null)
 Handles the logic for building a polygon by allowing the user to click to create vertices and sticks between them. The user can left-click to add vertices, press Enter to close the polygon by connecting the last vertex to the first, press Escape to cancel the polygon building process, or press C to create a collider from the current vertices. The method takes into account the current keyboard and mouse states, as well as whether ImGui is currently using the mouse input, to ensure that the polygon building interactions work smoothly without interfering with other UI interactions. The beforeChange action can be used to perform any necessary setup or state changes before modifying the mesh with new particles and sticks.
void ResetPolygonBuilder ()
bool RemoveParticle (int particleId)
void CutSticksAlongLine (Vector2 lineStart, Vector2 lineEnd)
int? AddStick (int p1Id, int p2Id, Color color, float width=2.0f, float naturalLength=-1f)
void AddSticksAccrossLength (Vector2 Start, Vector2 End, int numberOfSticks, float naturalLengthRatio=1f)
bool RemoveStick (int stickId)
int RemoveSticksBetween (int p1Id, int p2Id)
IEnumerable< MeshStickGetSticksForParticle (int particleId)
void Draw (SpriteBatch spriteBatch, PrimitiveBatch primitiveBatch, bool drawParticles, bool drawConstraints)
int AddParticleAt (Vector2 position, bool isPinned=false)
int? AddStickBetween (int p1Id, int p2Id, float naturalLength=-1f)
int? FindClosestParticle (Vector2 position, float radius)
void ResetSimulation (string[] parameters)
void CreateHubSpokeTire (object[] args)
 Creates a hub-and-spoke tire structure in the mesh based on the specified center position, inner and outer radii, and the number of segments for the rim. The method calculates the positions of particles for both the inner and outer rims of the tire, and then creates sticks to connect these particles in a hub-and-spoke pattern. It ensures that the inner and outer radii are valid and that there are enough segments to form a proper tire structure. The resulting structure consists of two concentric circles of particles connected by sticks, with additional sticks connecting the inner rim to the outer rim to create a strong and flexible tire-like structure in the mesh.
void ArgClothMeshFactory (object[] args)

Static Public Member Functions

static Mesh CreateGridMesh (Vector2 Start, Vector2 End, float DistanceBetweenParticles, Mesh mesh)
 Creates a grid mesh of particles and sticks between them based on the specified start and end positions, distance between particles, and an optional existing mesh to build upon. The method calculates the number of particles needed in both width and height directions based on the provided distance, and then iteratively adds particles at the calculated positions. It also creates sticks between adjacent particles to form a grid structure. The method ensures that the number of particles does not exceed a reasonable limit (1000 in either direction) to prevent performance issues. Finally, it returns the modified mesh with the newly added grid structure.
static Mesh CreateClothMesh (Vector2 Start, Vector2 End, float naturalLength, Mesh mesh=null, float springConstant=10000f, float drag=0.997f, float mass=1f)
 Creates a cloth mesh in the specified area defined by the start and end positions, with particles spaced according to the natural length parameter. The method builds a grid mesh using the CreateGridMesh method and then pins the top-left and top-right particles to create a hanging cloth effect. The spring constant, drag, and mass parameters can be customized to adjust the behavior of the cloth simulation. The resulting mesh will have a flexible cloth-like structure that can interact with forces and collisions in the physics simulation.

Public Attributes

float stickDrawThickness = -1
 the thickness to use when drawing the sticks in the mesh. If set to a negative value, it will use the default thickness defined in the DrawableStick class
float meanForceMagnitude = 0f
 the mean force used for colouring the sticks
float forceStdDeviation = 0f
 the standert deviation of the force used for colouring the sticks
float maxForceMagnitude = 0f
 the max force magnitude experienced by any stick in the mesh, used for normalizing stick colours based on force. This value is updated during the physics simulation to reflect the current maximum force magnitude, allowing for dynamic coloring of sticks based on their stress levels.
float springConstant = 10000f
 the spring constant used for the sticks in the physics simulation, which determines how stiff the sticks are
float drag = 0.997f
 the amount constant to multiply the velocity of the particles to simulate drag and icnrease stabilty
float mass = 1f
 the mass of all the particles in the mesh
List< ColliderColliders = new List<Collider>()
 all colliders in the mesh

Protected Member Functions

int RegisterParticle (DrawableParticle particle)

Properties

Dictionary< int, DrawableParticleParticles = new() [get]
 A dictionary that maps particle IDs to their corresponding DrawableParticle instances in the mesh.
Dictionary< int, MeshStickSticks = new() [get]
 the dictionary store of all sticks
int NextParticle [get]

Private Member Functions

bool LinesIntersect (Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)

Private Attributes

int _nextParticleId = 1
 the id for the next particle to be added to the mesh, which is used to ensure that each particle has a unique identifier.
int _nextStickId = 1
 the id for the next stick to be added to the mesh, which is used to ensure that each stick has a unique identifier.
int _polygonInitialParticle = -1
 the particle id for the first particle when building a polygon to connect the first and last part together
int _polygonFinalParticle = -1
 the final particle id when building a polygon, used to connect the new particle to the last one created
readonly List< int > _polygonVertices = new()
 all of the ids in the polygon currently being created
bool _isPolygonBuilding = false
 if the polygon is currently being built
readonly Dictionary< int, HashSet< int > > _particleToStickIds = new()
 a helper dictionary that maps particle IDs to the set of stick IDs that are connected to that particle.

Detailed Description

The Mesh class stores everything that should be loadable in and savebal for undo/redo functionality to file saving.

Member Function Documentation

◆ BuildPolygon()

void PhysicsCSAlevlProject.Mesh.BuildPolygon ( KeyboardState keyboardState,
KeyboardState previousKeyboardState,
MouseState mouseState,
MouseState previousMouseState,
bool imguiWantsMouse,
Action beforeChange = null )
inline

Handles the logic for building a polygon by allowing the user to click to create vertices and sticks between them. The user can left-click to add vertices, press Enter to close the polygon by connecting the last vertex to the first, press Escape to cancel the polygon building process, or press C to create a collider from the current vertices. The method takes into account the current keyboard and mouse states, as well as whether ImGui is currently using the mouse input, to ensure that the polygon building interactions work smoothly without interfering with other UI interactions. The beforeChange action can be used to perform any necessary setup or state changes before modifying the mesh with new particles and sticks.

Parameters
keyboardState
previousKeyboardState
mouseState
previousMouseState
imguiWantsMouse
beforeChange

◆ CreateClothMesh()

Mesh PhysicsCSAlevlProject.Mesh.CreateClothMesh ( Vector2 Start,
Vector2 End,
float naturalLength,
Mesh mesh = null,
float springConstant = 10000f,
float drag = 0::997f,
float mass = 1f )
inlinestatic

Creates a cloth mesh in the specified area defined by the start and end positions, with particles spaced according to the natural length parameter. The method builds a grid mesh using the CreateGridMesh method and then pins the top-left and top-right particles to create a hanging cloth effect. The spring constant, drag, and mass parameters can be customized to adjust the behavior of the cloth simulation. The resulting mesh will have a flexible cloth-like structure that can interact with forces and collisions in the physics simulation.

Parameters
Start
End
naturalLength
mesh
springConstant
drag
mass
Returns

◆ CreateGridMesh()

Mesh PhysicsCSAlevlProject.Mesh.CreateGridMesh ( Vector2 Start,
Vector2 End,
float DistanceBetweenParticles,
Mesh mesh )
inlinestatic

Creates a grid mesh of particles and sticks between them based on the specified start and end positions, distance between particles, and an optional existing mesh to build upon. The method calculates the number of particles needed in both width and height directions based on the provided distance, and then iteratively adds particles at the calculated positions. It also creates sticks between adjacent particles to form a grid structure. The method ensures that the number of particles does not exceed a reasonable limit (1000 in either direction) to prevent performance issues. Finally, it returns the modified mesh with the newly added grid structure.

Parameters
Start
End
DistanceBetweenParticles
mesh
Returns

◆ CreateHubSpokeTire()

void PhysicsCSAlevlProject.Mesh.CreateHubSpokeTire ( object[] args)
inline

Creates a hub-and-spoke tire structure in the mesh based on the specified center position, inner and outer radii, and the number of segments for the rim. The method calculates the positions of particles for both the inner and outer rims of the tire, and then creates sticks to connect these particles in a hub-and-spoke pattern. It ensures that the inner and outer radii are valid and that there are enough segments to form a proper tire structure. The resulting structure consists of two concentric circles of particles connected by sticks, with additional sticks connecting the inner rim to the outer rim to create a strong and flexible tire-like structure in the mesh.

Parameters
args
Exceptions
ArgumentException

The documentation for this class was generated from the following file:
  • PhysicsCSAlevlProject/Objects.Mesh.cs