Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physics Iteration 8 #13539

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions packages/dev/core/src/Physics/v2/IPhysicsEnginePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export enum ConstraintType {
HINGE,
SLIDER,
LOCK,
PRISMATIC,
}

/** @internal */
Expand Down Expand Up @@ -74,6 +75,8 @@ export interface PhysicsConstraintParameters {
pivotB?: Vector3;
axisA?: Vector3;
axisB?: Vector3;
maxDistance?: number;
collision?: boolean;
}

/**
Expand Down Expand Up @@ -145,6 +148,7 @@ export interface IPhysicsEnginePluginV2 {
disposeBody(body: PhysicsBody): void;
registerOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
unregisterOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
addConstraint(body: PhysicsBody, childBody: PhysicsBody, constraint: PhysicsConstraint): void;

// shape
initShape(shape: PhysicsShape, type: ShapeType, options: PhysicsShapeParameters): void;
Expand All @@ -169,13 +173,7 @@ export interface IPhysicsEnginePluginV2 {
disposeMaterial(material: PhysicsMaterial): void;

// constraint
initConstraint(constraint: PhysicsConstraint, type: ConstraintType, options: PhysicsConstraintParameters): void;
setParentBody(constraint: PhysicsConstraint, body: PhysicsBody): void;
getParentBody(constraint: PhysicsConstraint): PhysicsBody;
setChildBody(constraint: PhysicsConstraint, body: PhysicsBody): void;
getChildBody(constraint: PhysicsConstraint): PhysicsBody;
setAnchorInParent(constraint: PhysicsConstraint, pivot: Vector3, axisX: Vector3, axisY: Vector3): void;
setAnchorInChild(constraint: PhysicsConstraint, pivot: Vector3, axisX: Vector3, axisY: Vector3): void;
initConstraint(constraint: PhysicsConstraint, body: PhysicsBody, childBody: PhysicsBody): void;
setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;
getEnabled(constraint: PhysicsConstraint): boolean;
setCollisionsEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;
Expand Down
15 changes: 13 additions & 2 deletions packages/dev/core/src/Physics/v2/physicsBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Scene } from "../../scene";
import type { PhysicsEngine } from "./physicsEngine";
import type { Mesh, TransformNode, AbstractMesh } from "../../Meshes";
import type { Nullable } from "core/types";

import type { PhysicsConstraint } from "./physicsConstraint";
/**
* PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows
* the user to set the mass and velocity of the body, which can then be used to calculate the
Expand Down Expand Up @@ -368,13 +368,24 @@ export class PhysicsBody {
}

/**
* return geometric center of the associated mesh
* @returns geometric center of the associated mesh
*/
public getObjectCenter(): Vector3 {
// TODO
return new Vector3(0, 0, 0);
}

/**
* Adds a constraint to the physics engine.
*
* @param childBody - The body to which the constraint will be applied.
* @param constraint - The constraint to be applied.
*
*/
public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void {
this._physicsPlugin.addConstraint(this, childBody, constraint);
}

/**
* Disposes the body from the physics engine.
*
Expand Down
Loading