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

Peer dependencies #2

Merged
merged 4 commits into from
May 2, 2024
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
29 changes: 24 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gamebop/physics",
"description": "Physics components for PlayCanvas engine",
"version": "0.2.0",
"version": "0.2.1",
"main": "index.mjs",
"author": "Gamebop",
"license": "MIT",
Expand All @@ -22,7 +22,7 @@
"files": [
"dist/*"
],
"dependencies": {
"peerDependencies": {
"playcanvas": "^1.66.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/physics/init.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Debug } from './jolt/debug.mjs';
import { JoltManager } from './jolt/front/manager.mjs';
import { JoltManager } from './jolt/manager.mjs';
import { extendPCMath } from './jolt/math.mjs';

/**
Expand Down
130 changes: 69 additions & 61 deletions src/physics/jolt/back/backend.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { Tracker } from './operators/tracker.mjs';
import {
BP_LAYER_MOVING, BP_LAYER_NON_MOVING, BUFFER_WRITE_BOOL, BUFFER_WRITE_FLOAT32, BUFFER_WRITE_JOLTVEC32,
BUFFER_WRITE_UINT32, BUFFER_WRITE_UINT8, BUFFER_WRITE_VEC32, CMD_REPORT_TRANSFORMS, COMPONENT_SYSTEM_BODY,
COMPONENT_SYSTEM_CHAR, COMPONENT_SYSTEM_SOFT_BODY, OBJ_LAYER_MOVING, OBJ_LAYER_NON_MOVING, OPERATOR_CREATOR
COMPONENT_SYSTEM_CHAR, COMPONENT_SYSTEM_SOFT_BODY, OBJ_LAYER_MOVING, OBJ_LAYER_NON_MOVING, OPERATOR_CLEANER,
OPERATOR_CREATOR, OPERATOR_MODIFIER, OPERATOR_QUERIER
} from '../constants.mjs';

// TODO
Expand Down Expand Up @@ -74,6 +75,7 @@ class JoltBackend {
...data.config
};
this._config = config;
this._dispatcher = messenger;
this._time = 0;
this._filterLayers = new Map();

Expand All @@ -92,67 +94,20 @@ class JoltBackend {

this._lastStamp = 0;

const loadJolt = async () => {
const module = await import(data.glueUrl);
module.default({
locateFile: () => {
return data.wasmUrl;
}
}).then(Jolt => {
this.Jolt = Jolt;

// Util
extendJoltMath(Jolt);

// Physics operators
this._creator = new Creator(this);
this._modifier = new Modifier(this);
this._cleaner = new Cleaner(this);
this._querier = new Querier(this);
this._tracker = new Tracker(Jolt);

if ($_DEBUG) {
this._drawer = new Drawer(Jolt);
}

const listener = new Listener(this);

if (config.contactEventsEnabled) {
listener.initEvents(config);
}

this._listener = listener;

this._outBuffer = new CommandsBuffer({ ...this._config, commandsBufferSize: 2000 });

this._stepTime = 0;
this._steps = 0;

// TODO
// remove softBodies default array
this._responseMessage = {
buffer: null,
inBuffer: null,
softBodies: [],
origin: 'physics-worker'
};

this._dispatcher = messenger;
this._inBuffer = null;
this._fatalError = false;

if ($_DEBUG) {
this._perfIndex = null;
}

this._exposeConstants();

if ($_DEBUG) {
// console.log('Jolt Physics:', joltInfo.version);
}
});
if (data.glueUrl && data.wasmUrl) {
const loadJolt = async () => {
const module = await import(data.glueUrl);
module.default({
locateFile: () => {
return data.wasmUrl;
}
}).then(Jolt => {
this.Jolt = Jolt;
this.onLibLoad(Jolt);
});
}
loadJolt();
}
loadJolt();
}

set joltInterface(joltInterface) {
Expand Down Expand Up @@ -255,6 +210,59 @@ class JoltBackend {
this._updateCallback = func;
}

onLibLoad(Jolt) {
// Util
extendJoltMath(Jolt);

// Physics operators
this._creator = new Creator(this);
this._modifier = new Modifier(this);
this._cleaner = new Cleaner(this);
this._querier = new Querier(this);
this._tracker = new Tracker(Jolt);

if ($_DEBUG) {
this._drawer = new Drawer(Jolt);
}

const listener = new Listener(this);

if (config.contactEventsEnabled) {
listener.initEvents(config);
}

this._listener = listener;

this._outBuffer = new CommandsBuffer({ ...this._config, commandsBufferSize: 2000 });

this._stepTime = 0;
this._steps = 0;

// TODO
// remove softBodies default array
this._responseMessage = {
buffer: null,
inBuffer: null,
softBodies: [],
origin: 'physics-worker'
};

this._inBuffer = null;
this._fatalError = false;

if ($_DEBUG) {
this._perfIndex = null;
}

// TODO
// remove
this._exposeConstants();

if ($_DEBUG) {
// console.log('Jolt Physics:', joltInfo.version);
}
}

step(data) {
if (this._fatalError) return;

Expand Down
1 change: 1 addition & 0 deletions src/physics/jolt/back/operators/drawer.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { FLOAT32_SIZE } from '../../constants.mjs';
import { Debug } from '../../debug.mjs';

class Drawer {
Expand Down
34 changes: 17 additions & 17 deletions src/physics/jolt/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const ALLOWED_DOFS_ROTATION_Z = 5;
export const ALLOWED_DOFS_PLANE_2D = 6;
export const ALLOWED_DOFS_ALL = 7;

export const OMP_CALCULATE_INERTIA = 0;
export const OMP_CALCULATE_MASS_AND_INERTIA = 1;
export const OMP_CALCULATE_MASS_AND_INERTIA = 0;
export const OMP_CALCULATE_INERTIA = 1;
export const OMP_MASS_AND_INERTIA_PROVIDED = 2;

export const BFM_IGNORE_BACK_FACES = 0;
Expand Down Expand Up @@ -104,21 +104,21 @@ export const UINT32_SIZE = Uint32Array.BYTES_PER_ELEMENT;
export const UINT16_SIZE = Uint16Array.BYTES_PER_ELEMENT;
export const UINT8_SIZE = Uint8Array.BYTES_PER_ELEMENT;

export const BUFFER_WRITE_UINT8 = JSON.stringify('writeUint8');
export const BUFFER_WRITE_UINT16 = JSON.stringify('writeUint16');
export const BUFFER_WRITE_UINT32 = JSON.stringify('writeUint32');
export const BUFFER_WRITE_INT32 = JSON.stringify('writeInt32');
export const BUFFER_WRITE_VEC32 = JSON.stringify('writeVector32');
export const BUFFER_WRITE_FLOAT32 = JSON.stringify('writeFloat32');
export const BUFFER_WRITE_BOOL = JSON.stringify('writeBool');
export const BUFFER_WRITE_PLANE = JSON.stringify('writePlane');
export const BUFFER_WRITE_JOLTVEC32 = JSON.stringify('writeJoltVec32');
export const BUFFER_READ_UINT8 = JSON.stringify('readUint8');
export const BUFFER_READ_UINT16 = JSON.stringify('readUint16');
export const BUFFER_READ_UINT32 = JSON.stringify('readUint32');
export const BUFFER_READ_INT32 = JSON.stringify('readInt32');
export const BUFFER_READ_FLOAT32 = JSON.stringify('readFloat32');
export const BUFFER_READ_BOOL = JSON.stringify('readBool');
export const BUFFER_WRITE_UINT8 = 'writeUint8';
export const BUFFER_WRITE_UINT16 = 'writeUint16';
export const BUFFER_WRITE_UINT32 = 'writeUint32';
export const BUFFER_WRITE_INT32 = 'writeInt32';
export const BUFFER_WRITE_VEC32 = 'writeVector32';
export const BUFFER_WRITE_FLOAT32 = 'writeFloat32';
export const BUFFER_WRITE_BOOL = 'writeBool';
export const BUFFER_WRITE_PLANE = 'writePlane';
export const BUFFER_WRITE_JOLTVEC32 = 'writeJoltVec32';
export const BUFFER_READ_UINT8 = 'readUint8';
export const BUFFER_READ_UINT16 = 'readUint16';
export const BUFFER_READ_UINT32 = 'readUint32';
export const BUFFER_READ_INT32 = 'readInt32';
export const BUFFER_READ_FLOAT32 = 'readFloat32';
export const BUFFER_READ_BOOL = 'readBool';

export const CMD_CREATE_BODY = 0;
export const CMD_CREATE_CHAR = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/physics/jolt/front/constraint/types/constraint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ class Constraint {

constructor(entity1, entity2, opts = {}) {
if ($_DEBUG) {
let ok = Debug.assert(!!entity1 && entity1 instanceof Entity && !!entity1.body,
let ok = Debug.assert(!!entity1 && !!entity1.body,
'Invalid entity1 when adding a constraint', entity1);
ok = ok && Debug.assert(!!entity2 && entity2 instanceof Entity && !!entity2.body,
ok = ok && Debug.assert(!!entity2 && !!entity2.body,
'Invalid entity1 when adding a constraint', entity2);
if (opts.point1) {
ok = ok && Debug.assert(opts.point1 instanceof Vec3,
Expand Down
Loading
Loading