Skip to content
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
11 changes: 9 additions & 2 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @module PhysicsComponents
*/

import { init } from './physics/init.mjs';
export { JoltManager } from './physics/jolt/manager.mjs';
export * from './physics/jolt/settings.mjs';

export { ShapeComponent } from './physics/jolt/front/shape/component.mjs';
export { ShapeComponentSystem } from './physics/jolt/front/shape/system.mjs';
Expand Down Expand Up @@ -46,4 +47,10 @@ export { IndexedCache } from './physics/indexed-cache.mjs';
export * from './physics/jolt/front/constraint/types/settings.mjs';
export * from './physics/jolt/constants.mjs';

export { init };
export { JoltBackend } from './physics/jolt/back/backend.mjs';
export { Querier } from './physics/jolt/back/operators/querier.mjs';
export { Creator } from './physics/jolt/back/operators/creator.mjs';
export { Listener } from './physics/jolt/back/operators/listener.mjs';
export { Tracker } from './physics/jolt/back/operators/tracker.mjs';

export { init, JoltInitSettings } from './physics/init.mjs';
6 changes: 3 additions & 3 deletions src/physics/indexed-cache.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class IndexedCache {
/**
* Store an element in the cache. Will return one of the freed indices, or a new one.
*
* @param {*} element - An object or a function to store in the cache
* @returns {number} - TODO
* @param {object | function} element - An object or a function to store in the cache
* @returns {number} - Index number under which the element is stored.
*/
add(element) {
const freed = this._freed;
Expand All @@ -33,7 +33,7 @@ class IndexedCache {
* Retrieves a stored element under the given index.
*
* @param {number} index - An index of the element to retrieve.
* @returns {*} - TODO
* @returns {object | function} - Element stored under given index.
*/
get(index) {
return this._storage[index];
Expand Down
769 changes: 514 additions & 255 deletions src/physics/init.mjs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/physics/jolt/back/backend.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ import {
OPERATOR_CREATOR, OPERATOR_MODIFIER, OPERATOR_QUERIER
} from '../constants.mjs';

/**
* Jolt Backend.
*
* @group Private
* @private
*/
class JoltBackend {
constructor(messenger, data) {
const config = {
Expand Down
4 changes: 4 additions & 0 deletions src/physics/jolt/back/operators/cleaner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
BUFFER_READ_UINT32, CMD_DESTROY_BODY, CMD_DESTROY_CONSTRAINT, CMD_DESTROY_SHAPE
} from '../../constants.mjs';

/**
* @group Private
* @private
*/
class Cleaner {
static cleanDebugDrawData(body, Jolt) {
if (body.debugDrawData) {
Expand Down
4 changes: 4 additions & 0 deletions src/physics/jolt/back/operators/creator.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
} from '../../constants.mjs';
import { ConstraintCreator } from './helpers/constraint-creator.mjs';

/**
* @group Private
* @private
*/
class Creator {
static createShapeSettings(cb, meshBuffers, Jolt, jv, jq) {
const shapeType = cb.read(BUFFER_READ_UINT8);
Expand Down
4 changes: 4 additions & 0 deletions src/physics/jolt/back/operators/listener.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {

const eval2 = eval;

/**
* @group Private
* @private
*/
class Listener {
constructor(backend) {
this._listener = null;
Expand Down
15 changes: 13 additions & 2 deletions src/physics/jolt/back/operators/querier.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Debug } from '../../debug.mjs';
import {
BFM_IGNORE_BACK_FACES,
BUFFER_READ_BOOL, BUFFER_READ_FLOAT32, BUFFER_READ_UINT32, BUFFER_READ_UINT8, BUFFER_WRITE_BOOL,
BUFFER_WRITE_FLOAT32, BUFFER_WRITE_JOLTVEC32, BUFFER_WRITE_UINT16, BUFFER_WRITE_UINT32, CMD_CAST_RAY,
CMD_CAST_SHAPE, CMD_COLLIDE_POINT, CMD_COLLIDE_SHAPE_IDX, COMPONENT_SYSTEM_MANAGER
Expand Down Expand Up @@ -52,6 +53,10 @@ function writeCollideShapeHit(cb, system, tracker, calculateNormal, hit, Jolt) {
let collidePointResult;
let params = [];

/**
* @group Private
* @private
*/
class Querier {
constructor(backend) {
this._backend = backend;
Expand Down Expand Up @@ -289,8 +294,14 @@ class Querier {
} else {
offset.Set(0, 0, 0);
}
if (cb.flag) castSettings.mBackFaceModeTriangles = cb.read(BUFFER_READ_UINT8);
if (cb.flag) castSettings.mBackFaceModeConvex = cb.read(BUFFER_READ_UINT8);
if (cb.flag) {
castSettings.mBackFaceModeTriangles = cb.read(BUFFER_READ_UINT8) === BFM_IGNORE_BACK_FACES ?
Jolt.EBackFaceMode_IgnoreBackFaces : Jolt.EBackFaceMode_CollideWithBackFaces;
}
if (cb.flag) {
castSettings.mBackFaceModeConvex = cb.read(BUFFER_READ_UINT8) === BFM_IGNORE_BACK_FACES ?
Jolt.EBackFaceMode_IgnoreBackFaces : Jolt.EBackFaceMode_CollideWithBackFaces;
}
if (cb.flag) castSettings.mUseShrunkenShapeAndConvexRadius = cb.read(BUFFER_READ_BOOL);
if (cb.flag) castSettings.mReturnDeepestPoint = cb.read(BUFFER_READ_BOOL);

Expand Down
4 changes: 4 additions & 0 deletions src/physics/jolt/back/operators/tracker.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @group Private
* @private
*/
class Tracker {
constructor(Jolt) {
this._Jolt = Jolt;
Expand Down
6 changes: 4 additions & 2 deletions src/physics/jolt/front/constraint/types/constraint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ class Constraint {

/**
* Override for the number of solver velocity iterations to run. If set to `0`, the constraint
* will use global default set by Physics initialization setting (TODO add link).
* will use global default set by Physics initialization setting
* {@link JoltInitSettings.numVelocitySteps}.
*
* @returns {number} - Velocity steps override.
* @defaultValue 0
Expand All @@ -155,7 +156,8 @@ class Constraint {

/**
* Override for the number of solver position iterations to run. If set to `0`, the constraint
* will use global default set by Physics initialization setting (TODO add link).
* will use global default set by Physics initialization setting
* {@link JoltInitSettings.numPositionSteps}.
*
* @returns {number} - Positions steps override.
* @defaultValue 0
Expand Down
6 changes: 4 additions & 2 deletions src/physics/jolt/front/constraint/types/settings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
class ConstraintSettings {
/**
* Override for the number of solver position iterations to run. If set to `0`, the constraint
* will use global default set by Physics initialization setting (TODO add link).
* will use global default set by Physics initialization setting
* {@link JoltInitSettings.numPositionSteps}.
*
* @type {number}
* @defaultValue 0
Expand All @@ -15,7 +16,8 @@ class ConstraintSettings {

/**
* Override for the number of solver velocity iterations to run. If set to `0`, the constraint
* will use global default set by Physics initialization setting (TODO add link).
* will use global default set by Physics initialization setting
* {@link JoltInitSettings.numVelocitySteps}.
*
* @type {number}
* @defaultValue 0
Expand Down
2 changes: 2 additions & 0 deletions src/physics/jolt/front/response-handler.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class ResponseHandler {
const firstOnly = cb.read(BUFFER_READ_BOOL);
const hitsCount = cb.read(BUFFER_READ_UINT16);

// TODO
// always use array
let result = firstOnly ? null : [];

for (let i = 0; i < hitsCount; i++) {
Expand Down
42 changes: 21 additions & 21 deletions src/physics/jolt/front/shape/component.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,49 @@ const defaultHalfExtent = new Vec3(0.5, 0.5, 0.5);
* @category Shape Component
*/
class ShapeComponent extends Component {
_shape = SHAPE_BOX;
_convexRadius = 0.05;

_index = -1;
_debugDraw = false;

_renderAsset = null;
_density = 1000;

_mesh = null;
_halfExtent = defaultHalfExtent;

_isCompoundChild = false;
_halfHeight = 0.5;

_useEntityScale = true;
_hfActiveEdgeCosThresholdAngle = 0.996195;

_debugDraw = false;
_hfBitsPerSample = 8;

_halfExtent = defaultHalfExtent;
_hfBlockSize = 2;

_radius = 0.5;
_hfOffset = Vec3.ZERO;

_convexRadius = 0.05;
_hfSampleCount = 0;

_halfHeight = 0.5;
_hfSamples = null;

_density = 1000;
_hfScale = Vec3.ONE;

_shapePosition = Vec3.ZERO;
_index = -1;

_shapeRotation = Quat.IDENTITY;
_isCompoundChild = false;

_massOffset = Vec3.ZERO;

_hfSamples = null;
_mesh = null;

_hfSampleCount = 0;
_radius = 0.5;

_hfBlockSize = 2;
_renderAsset = null;

_hfBitsPerSample = 8;
_shape = SHAPE_BOX;

_hfActiveEdgeCosThresholdAngle = 0.996195;
_shapePosition = Vec3.ZERO;

_hfScale = Vec3.ONE;
_shapeRotation = Quat.IDENTITY;

_hfOffset = Vec3.ZERO;
_useEntityScale = true;

/**
* Internally the convex radius will be subtracted from the half extent, so the total size will
Expand Down
Loading