cannon_physics
This is a dart conversion of cannon.js and cannon-es, originally created by Stefan Hedman @schteppe and has a maintaind fork by Poimandres @pmndrs.
Getting started
To get started add cannon_physics, three_dart, and three_dart_jsm to your pubspec.yaml file.
The Cannon World is the main scene that has all of the objects that will be manipulated to the scene. To get started add the cannon world then all of the objects in it.
If there is no shapes or type in the ObjectConfigure class it will not work. If you need a RigidBody use shapes. If you need a Joint use type.
world = cannon.World();
const mass = 1.0;
const size = 0.25;
final cylinderShape = cannon.Cylinder(
radiusTop: size,
radiusBottom: size,
height: size * 2,
numSegments: 10
);
final cylinderBody = cannon.Body(mass:mass);
cylinderBody.addShape(cylinderShape);
cylinderBody.position.set(size * 2, size + 1, size * 2);
world.addBody(cylinderBody);
Usage
This project is a basic physics engine for three_dart. This package includes RigidBodies, Constraints, and Joints.
Features
- Rigid body dynamics
- Discrete collision detection
- Contacts, friction and restitution
- Constraints
- PointToPoint (a.k.a. ball/socket joint)
- Distance
- Hinge (with optional motor)
- Lock
- ConeTwist
- Gauss-Seidel constraint solver and an island split algorithm
- Collision filters
- Body sleeping
- Experimental SPH / fluid support
- Various shapes and collision algorithms (see table below)
Sphere | Plane | Box | Convex | Particle | Heightfield | Trimesh | |
---|---|---|---|---|---|---|---|
Sphere | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
Plane | - | - | Yes | Yes | Yes | - | Yes |
Box | - | - | Yes | Yes | Yes | Yes | (todo) |
Cylinder | - | - | Yes | Yes | Yes | Yes | (todo) |
Convex | - | - | - | Yes | Yes | Yes | (todo) |
Particle | - | - | - | - | - | (todo) | (todo) |
Heightfield | - | - | - | - | - | - | (todo) |
Trimesh | - | - | - | - | - | - | (todo) |
Example
Find the example app here and the current web version of the code here.
Contributing
Contributions are welcome. In case of any problems look at existing issues, if you cannot find anything related to your problem then open an issue. Create an issue before opening a pull request for non trivial fixes. In case of trivial fixes open a pull request directly.
Additional Information
This plugin is only for performing basic physics. While this can be used as a standalone project it does not render scenes.
Libraries
- cannon_physics
- collision/aabb
- collision/array_collision_matrix
- collision/broadphase
- collision/grid_broadphase
- collision/naive_broadphase
- collision/object_collision_matrix
- collision/overlap_keeper
- collision/ray_class
- collision/raycast_result
- collision/sap_broadphase
- constraints/cone_twist_constraint
- constraints/constraint_class
- constraints/distance_constraint
- constraints/hinge_constraint
- constraints/lock_constraint
- constraints/point_to_point_constraint
- equations/cone_equation
- equations/contact_equation
- equations/equation_class
- equations/friction_equation
- equations/rotational_equation
- equations/rotational_motor_equation
- material/contact_material
- material/material
- math/jacobian_element
- math/mat3
- math/quaternion
- math/transform
- math/vec3
- objects/body
- objects/raycast_vehicle
- objects/rigid_vehicle
- objects/sph_system
- objects/spring
- objects/wheel_info
- shapes/box
- shapes/convex_polyhedron
- shapes/cylinder
- shapes/heightfield
- shapes/particle
- shapes/plane
- shapes/shape
- shapes/sphere
- shapes/trimesh
- solver/gs_solver
- solver/solver
- solver/split_solver
- utils/event_target
- utils/logger
- utils/octree
- utils/pool
- utils/tuple_dictionary
- utils/utils
- utils/vec3_pool
- world/narrow_phase
- world/world_class