@@ -16,7 +16,13 @@ import { RigidBodyComponentData } from './data.js';
1616let ammoRayStart , ammoRayEnd ;
1717
1818/**
19- * Object holding the result of a successful raycast hit.
19+ * Contains the result of a successful raycast intersection with a rigid body. When a ray
20+ * intersects with a rigid body in the physics simulation, this class stores the complete
21+ * information about that intersection including the entity, the exact point of impact, the normal
22+ * at the impact point, and the fractional distance along the ray where the intersection occurred.
23+ *
24+ * Instances of this class are created and returned by {@link RigidBodyComponentSystem#raycastFirst}
25+ * and {@link RigidBodyComponentSystem#raycastAll} methods when performing physics raycasts.
2026 *
2127 * @category Physics
2228 */
@@ -69,8 +75,20 @@ class RaycastResult {
6975}
7076
7177/**
72- * Object holding the result of a contact between two rigid bodies.
78+ * Represents the detailed data of a single contact point between two rigid bodies in the physics
79+ * simulation. This class provides comprehensive information about the contact, including the
80+ * entities involved, the exact contact points in both local and world space coordinates, the
81+ * contact normal, and the collision impulse force.
82+ *
83+ * Instances of this class are created by the physics engine when collision events occur and are
84+ * passed to event handlers only through the global `contact` event on the
85+ * {@link RigidBodyComponentSystem}. Individual rigid body components receive instances of
86+ * {@link ContactResult} instead.
7387 *
88+ * @example
89+ * app.systems.rigidbody.on('contact', (result) => {
90+ * console.log(`Contact between ${result.a.name} and ${result.b.name}`);
91+ * });
7492 * @category Physics
7593 */
7694class SingleContactResult {
@@ -163,7 +181,33 @@ class SingleContactResult {
163181}
164182
165183/**
166- * Object holding the result of a contact between two Entities.
184+ * Represents a single point of contact between two colliding rigid bodies in the physics
185+ * simulation. Each contact point stores detailed spatial information about the collision,
186+ * including both local and world space coordinates of the exact contact points on both entities,
187+ * the contact normal direction, and the collision impulse force.
188+ *
189+ * Contact points are generated by the physics engine during collision detection and are typically
190+ * accessed through a {@link ContactResult} object, which can contain multiple contact points for a
191+ * single collision between two entities. Multiple contact points commonly occur when objects
192+ * collide along edges or faces rather than at a single point.
193+ *
194+ * The impulse property can be particularly useful for gameplay mechanics that need to respond
195+ * differently based on the force of impact, such as damage calculations or sound effect volume.
196+ *
197+ * @example
198+ * // Access contact points from a collision event
199+ * entity.collision.on('contact', (result) => {
200+ * // Get the first contact point
201+ * const contact = result.contacts[0];
202+ *
203+ * // Get the contact position in world space
204+ * const worldPos = contact.point;
205+ *
206+ * // Check how hard the collision was
207+ * if (contact.impulse > 10) {
208+ * console.log("That was a hard impact!");
209+ * }
210+ * });
167211 *
168212 * @category Physics
169213 */
@@ -197,15 +241,16 @@ class ContactPoint {
197241 pointOther ;
198242
199243 /**
200- * The normal vector of the contact on the other entity, in world space.
244+ * The normal vector of the contact on the other entity, in world space. This vector points
245+ * away from the surface of the other entity at the point of contact.
201246 *
202247 * @type {Vec3 }
203248 */
204249 normal ;
205250
206251 /**
207252 * The total accumulated impulse applied by the constraint solver during the last sub-step.
208- * Describes how hard two objects collide .
253+ * This value represents how hard two objects collided. Higher values indicate stronger impacts .
209254 *
210255 * @type {number }
211256 */
@@ -238,7 +283,24 @@ class ContactPoint {
238283}
239284
240285/**
241- * Object holding the result of a contact between two Entities.
286+ * Represents a collection of contact points between two entities in a physics collision.
287+ * When rigid bodies collide, this object stores the entity involved in the collision and
288+ * an array of specific contact points where the collision occurred. This information is
289+ * used by the physics system to resolve collisions and notify components through events.
290+ *
291+ * Instances of this class are passed to event handlers for the `contact` and `collisionstart`
292+ * events on individual {@link RigidBodyComponent} and {@link CollisionComponent} instances.
293+ *
294+ * Unlike {@link SingleContactResult} which is used for global contact events, ContactResult
295+ * objects provide information about collision from the perspective of one entity, with
296+ * information about which other entity was involved and all points of contact.
297+ *
298+ * Please refer to the following event documentation for more information:
299+ *
300+ * - {@link CollisionComponent.EVENT_CONTACT}
301+ * - {@link CollisionComponent.EVENT_COLLISIONSTART}
302+ * - {@link RigidBodyComponent.EVENT_CONTACT}
303+ * - {@link RigidBodyComponent.EVENT_COLLISIONSTART}
242304 *
243305 * @category Physics
244306 */
@@ -273,10 +335,15 @@ class ContactResult {
273335const _schema = [ 'enabled' ] ;
274336
275337/**
276- * The RigidBodyComponentSystem maintains the dynamics world for simulating rigid bodies, it also
277- * controls global values for the world such as gravity. Note: The RigidBodyComponentSystem is only
278- * valid if 3D Physics is enabled in your application. You can enable this in the application
279- * settings for your project.
338+ * The RigidBodyComponentSystem manages the physics simulation for all rigid body components
339+ * in the application. It creates and maintains the underlying Ammo.js physics world, handles
340+ * physics object creation and destruction, performs physics raycasting, detects and reports
341+ * collisions, and updates the transforms of entities with rigid bodies after each physics step.
342+ *
343+ * The system controls global physics settings like gravity and provides methods for raycasting
344+ * and collision detection.
345+ *
346+ * This system is only functional if your application has loaded the Ammo.js {@link WasmModule}.
280347 *
281348 * @category Physics
282349 */
@@ -310,6 +377,9 @@ class RigidBodyComponentSystem extends ComponentSystem {
310377 * [0, -9.81, 0] which is an approximation of the gravitational force on Earth.
311378 *
312379 * @type {Vec3 }
380+ * @example
381+ * // Set the gravity in the physics world to simulate a planet with low gravity
382+ * app.systems.rigidbody.gravity = new pc.Vec3(0, -3.7, 0);
313383 */
314384 gravity = new Vec3 ( 0 , - 9.81 , 0 ) ;
315385
0 commit comments