Skip to content

Commit a0b6ec7

Browse files
committed
Exposing operator* for Quat
Temporarily copying webidl_binder.py to this repository. Fixes #185
1 parent ab7fc5c commit a0b6ec7

File tree

15 files changed

+11718
-21
lines changed

15 files changed

+11718
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Build/
22
dist/
33
node_modules
44
Examples/js/jolt-physics.*.js
5+
__pycache__

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ FIND_PACKAGE(Python3)
55
set(PYTHON ${Python3_EXECUTABLE} CACHE STRING "Python path")
66
set(EMSCRIPTEN_ROOT $ENV{EMSDK}/upstream/emscripten CACHE STRING "Emscripten path")
77
set(CMAKE_TOOLCHAIN_FILE ${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake)
8-
set(WEBIDL_BINDER_SCRIPT ${EMSCRIPTEN_ROOT}/tools/webidl_binder.py)
8+
set(WEBIDL_BINDER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/tools/webidl_binder.py)
99
set(JOLT_FRONT_MATTER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/front-matter.js)
1010
set(JOLT_HEADER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/JoltJS.h)
1111
set(JOLT_IDL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/JoltJS.idl)

Examples/conveyor_belt.html

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
cargo.SetFriction(Math.max((0.0, 1.0 - 0.1 * i)));
8585
}
8686

87+
const cLocalSpaceVelocity = new Jolt.Vec3(0, 0, -10.0);
88+
const cLocalSpaceAngularVelocity = new Jolt.Vec3(0, DegreesToRadians(10.0), 0);
89+
8790
// Register contact listener
8891
const contactListener = new Jolt.ContactListenerJS();
8992
contactListener.OnContactAdded = (body1, body2, manifold, settings) => {
@@ -94,44 +97,39 @@
9497

9598
const body1ID = body1.GetID().GetIndexAndSequenceNumber();
9699
const body2ID = body2.GetID().GetIndexAndSequenceNumber();
97-
const rotation1 = wrapQuat(body1.GetRotation());
98-
const rotation2 = wrapQuat(body2.GetRotation());
100+
const rotation1 = body1.GetRotation().Clone(); // Next call to GetRotation() will overwrite rotation1
101+
const rotation2 = body2.GetRotation();
99102

100103
const body1LinearBelt = linearBelts.find(belt => belt.GetID().GetIndexAndSequenceNumber() == body1ID)
101104
const body2LinearBelt = linearBelts.find(belt => belt.GetID().GetIndexAndSequenceNumber() == body2ID)
102105
if (body1LinearBelt || body2LinearBelt) {
103106
// Determine the world space surface velocity of both bodies
104-
const cLocalSpaceVelocity = new THREE.Vector3(0, 0, -10.0);
105-
const body1LinearSurfaceVelocity = body1LinearBelt ? cLocalSpaceVelocity.applyQuaternion(rotation1) : new THREE.Vector3(0, 0, 0);
106-
const body2LinearSurfaceVelocity = body2LinearBelt ? cLocalSpaceVelocity.applyQuaternion(rotation2) : new THREE.Vector3(0, 0, 0);
107+
const body1LinearSurfaceVelocity = body1LinearBelt ? rotation1.MulVec3(cLocalSpaceVelocity).Clone() : new Jolt.Vec3(0, 0, 0);
108+
const body2LinearSurfaceVelocity = body2LinearBelt ? rotation2.MulVec3(cLocalSpaceVelocity).Clone() : new Jolt.Vec3(0, 0, 0);
107109

108110
// Calculate the relative surface velocity
109-
const v = body2LinearSurfaceVelocity.sub(body1LinearSurfaceVelocity);
110-
settings.mRelativeLinearSurfaceVelocity.Set(v.x, v.y, v.z);
111+
body2LinearSurfaceVelocity.Sub(body1LinearSurfaceVelocity);
112+
settings.mRelativeLinearSurfaceVelocity = body2LinearSurfaceVelocity;
111113
}
112114

113115
const angularBodyId = angularBelt.GetID().GetIndexAndSequenceNumber();
114116
const body1Angular = body1ID == angularBodyId;
115117
const body2Angular = body2ID == angularBodyId;
116118
if (body1Angular || body2Angular) {
117119
// Determine the world space angular surface velocity of both bodies
118-
const cLocalSpaceAngularVelocity = new THREE.Vector3(0, DegreesToRadians(10.0), 0);
119-
const body1AngularSurfaceVelocity = body1Angular ? cLocalSpaceAngularVelocity.applyQuaternion(rotation1) : new THREE.Vector3(0, 0, 0);
120-
const body2AngularSurfaceVelocity = body2Angular ? cLocalSpaceAngularVelocity.applyQuaternion(rotation2) : new THREE.Vector3(0, 0, 0);
120+
const body1AngularSurfaceVelocity = body1Angular ? rotation1.MulVec3(cLocalSpaceAngularVelocity).Clone() : new Jolt.Vec3(0, 0, 0);
121+
const body2AngularSurfaceVelocity = body2Angular ? rotation2.MulVec3(cLocalSpaceAngularVelocity).Clone() : new Jolt.Vec3(0, 0, 0);
121122

122123
// Note that the angular velocity is the angular velocity around body 1's center of mass, so we need to add the linear velocity of body 2's center of mass
123-
const COM1 = wrapVec3(body1.GetCenterOfMassPosition());
124-
const COM2 = wrapVec3(body2.GetCenterOfMassPosition());
125-
const body2LinearSurfaceVelocity = body2Angular ?
126-
body2AngularSurfaceVelocity.cross(COM1.clone().sub(COM2)) : new THREE.Vector3(0, 0, 0);
124+
const COM1 = body1.GetCenterOfMassPosition().Clone();
125+
const COM2 = body2.GetCenterOfMassPosition();
126+
const body2LinearSurfaceVelocity = body2Angular ? body2AngularSurfaceVelocity.Cross(COM1.Sub(COM2)).Clone() : new Jolt.Vec3(0, 0, 0);
127127

128128
// Calculate the relative angular surface velocity
129-
const rls = body2LinearSurfaceVelocity;
130-
settings.mRelativeLinearSurfaceVelocity.Set(rls.x, rls.y, rls.z);
131-
const ras = body2AngularSurfaceVelocity.sub(body1AngularSurfaceVelocity);
132-
settings.mRelativeAngularSurfaceVelocity.Set(ras.x, ras.y, ras.z);
129+
settings.mRelativeLinearSurfaceVelocity = body2LinearSurfaceVelocity;
130+
body2AngularSurfaceVelocity.Sub(body1AngularSurfaceVelocity);
131+
settings.mRelativeAngularSurfaceVelocity = body2AngularSurfaceVelocity;
133132
}
134-
135133
};
136134
contactListener.OnContactPersisted = (body1, body2, manifold, settings) => {
137135
// Same behavior as contact added

JoltJS.idl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ interface Quat {
379379
[Value] static Quat sFromTo([Const, Ref] Vec3 inFrom, [Const, Ref] Vec3 inTo);
380380
[Operator="=="] boolean Equals([Const, Ref] Quat inQ);
381381
[Operator="!="] boolean NotEquals([Const, Ref] Quat inQ);
382+
[Operator="*", Value] Quat MulQuat([Const, Ref] Quat inQ);
383+
[Operator="*", Value] Vec3 MulVec3([Const, Ref] Vec3 inV);
384+
[Operator="*", Value] Quat MulFloat(float inV);
382385
boolean IsClose([Const, Ref] Quat inQ, optional float inMaxDistSq);
383386
boolean IsNormalized(optional float inTolerance);
384387
float Length();

ci/install-emsdk.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
EMSDK_VERSION=3.1.64
3+
EMSDK_VERSION=3.1.69
44

55
git clone https://github.com/emscripten-core/emsdk.git
66

tools/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The files in this folder are modified versions of https://github.com/emscripten-core/emscripten/tree/main/tools and https://github.com/emscripten-core/emscripten/tree/main/third_party at version 10cb9d46cdd17e7a96de68137c9649d9a630fbc7
2+
3+
They are here until this PR is merged: https://github.com/emscripten-core/emscripten/pull/22770

0 commit comments

Comments
 (0)