Skip to content

Commit

Permalink
Updated to latest Jolt
Browse files Browse the repository at this point in the history
- Adds support for CharacterVirtual vs CharacterVirtual collision
- Adds MakeScaleValid function
  • Loading branch information
jrouwe committed Jul 12, 2024
1 parent abec584 commit 2f4fc67
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ include(FetchContent)
FetchContent_Declare(
JoltPhysics
GIT_REPOSITORY "https://github.com/jrouwe/JoltPhysics"
GIT_TAG "bac9d7301d28280e69062afd9e2705821435b4f9"
GIT_TAG "6e0b867a246731d69e7535440aff436e54dc99bf"
SOURCE_SUBDIR "Build"
)
FetchContent_MakeAvailable(JoltPhysics)
Expand Down
7 changes: 7 additions & 0 deletions Examples/character_virtual.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@
isInLava = true; // Can't modify velocity or position at this point, marking that we want to teleport
return true;
}
characterContactListener.OnCharacterContactValidate = (character, otherCharacter, subShapeID2) => {
return true;
}
characterContactListener.OnContactAdded = (character, bodyID2, subShapeID2, contactPosition, contactNormal, settings) => {
}
characterContactListener.OnCharacterContactAdded = (character, otherCharacter, subShapeID2, contactPosition, contactNormal, settings) => {
}
characterContactListener.OnContactSolve = (character, bodyID2, subShapeID2, contactPosition, contactNormal, contactVelocity, contactMaterial, characterVelocity, newCharacterVelocity) => {
// Don't allow the player to slide down static not-too-steep surfaces when not actively moving and when not on a moving platform
character = Jolt.wrapPointer(character, Jolt.CharacterVirtual);
Expand All @@ -150,6 +155,8 @@
newCharacterVelocity.SetZ(0);
}
}
characterContactListener.OnCharacterContactSolve = (character, otherCharacter, subShapeID2, contactPosition, contactNormal, contactVelocity, contactMaterial, characterVelocity, newCharacterVelocity) => {
}

const _tmpVec3 = new Jolt.Vec3();
const _tmpRVec3 = new Jolt.RVec3();
Expand Down
12 changes: 12 additions & 0 deletions JoltJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -581,18 +581,30 @@ class CharacterContactListenerEm: public CharacterContactListener
public:
// JavaScript compatible virtual functions
virtual void OnContactAdded(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, const RVec3 *inContactPosition, const Vec3 *inContactNormal, CharacterContactSettings &ioSettings) = 0;
virtual void OnCharacterContactAdded(const CharacterVirtual *inCharacter, const CharacterVirtual *inOtherCharacter, const SubShapeID &inSubShapeID2, const RVec3 *inContactPosition, const Vec3 *inContactNormal, CharacterContactSettings &ioSettings) = 0;
virtual void OnContactSolve(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, const RVec3 *inContactPosition, const Vec3 *inContactNormal, const Vec3 *inContactVelocity, const PhysicsMaterial *inContactMaterial, const Vec3 *inCharacterVelocity, Vec3 &ioNewCharacterVelocity) = 0;
virtual void OnCharacterContactSolve(const CharacterVirtual *inCharacter, const CharacterVirtual *inOtherCharacter, const SubShapeID &inSubShapeID2, const RVec3 *inContactPosition, const Vec3 *inContactNormal, const Vec3 *inContactVelocity, const PhysicsMaterial *inContactMaterial, const Vec3 *inCharacterVelocity, Vec3 &ioNewCharacterVelocity) = 0;

// Functions that call the JavaScript compatible virtual functions
virtual void OnContactAdded(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings) override
{
OnContactAdded(inCharacter, inBodyID2, inSubShapeID2, &inContactPosition, &inContactNormal, ioSettings);
}

virtual void OnCharacterContactAdded(const CharacterVirtual *inCharacter, const CharacterVirtual *inOtherCharacter, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, CharacterContactSettings &ioSettings) override
{
OnCharacterContactAdded(inCharacter, inOtherCharacter, inSubShapeID2, &inContactPosition, &inContactNormal, ioSettings);
}

virtual void OnContactSolve(const CharacterVirtual *inCharacter, const BodyID &inBodyID2, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, Vec3Arg inContactVelocity, const PhysicsMaterial *inContactMaterial, Vec3Arg inCharacterVelocity, Vec3 &ioNewCharacterVelocity) override
{
OnContactSolve(inCharacter, inBodyID2, inSubShapeID2, &inContactPosition, &inContactNormal, &inContactVelocity, inContactMaterial, &inCharacterVelocity, ioNewCharacterVelocity);
}

virtual void OnCharacterContactSolve(const CharacterVirtual *inCharacter, const CharacterVirtual *inOtherCharacter, const SubShapeID &inSubShapeID2, RVec3Arg inContactPosition, Vec3Arg inContactNormal, Vec3Arg inContactVelocity, const PhysicsMaterial *inContactMaterial, Vec3Arg inCharacterVelocity, Vec3 &ioNewCharacterVelocity) override
{
OnCharacterContactSolve(inCharacter, inOtherCharacter, inSubShapeID2, &inContactPosition, &inContactNormal, &inContactVelocity, inContactMaterial, &inCharacterVelocity, ioNewCharacterVelocity);
}
};

/// A wrapper around the physics step listener that is compatible with JavaScript (JS doesn't like multiple inheritance)
Expand Down
17 changes: 17 additions & 0 deletions JoltJS.idl
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ interface Shape {
[Value] TransformedShape GetSubShapeTransformedShape([Const, Ref] SubShapeID inSubShapeID, [Const, Ref] Vec3 inPositionCOM, [Const, Ref] Quat inRotation, [Const, Ref] Vec3 inScale, [Ref] SubShapeID outRemainder);
float GetVolume();
boolean IsValidScale([Const, Ref] Vec3 inScale);
[Value] Vec3 MakeScaleValid([Const, Ref] Vec3 inScale);
[Value] ShapeResult ScaleShape([Const, Ref] Vec3 inScale);
};

Expand Down Expand Up @@ -996,6 +997,7 @@ interface HeightFieldShapeSettings {
attribute long mSampleCount;
attribute float mMinHeightValue;
attribute float mMaxHeightValue;
attribute unsigned long mMaterialsCapacity;
attribute long mBlockSize;
attribute long mBitsPerSample;
[Value] attribute ArrayFloat mHeightSamples;
Expand Down Expand Up @@ -1591,6 +1593,7 @@ interface CollisionGroup {
unsigned long GetSubGroupID();
};

[NoDelete]
interface Body {
[Const, Ref] BodyID GetID();
boolean IsActive();
Expand Down Expand Up @@ -2714,10 +2717,23 @@ interface CharacterContactListenerJS {
void CharacterContactListenerJS();
void OnAdjustBodyVelocity([Const] CharacterVirtual inCharacter, [Const, Ref] Body inBody2, [Ref] Vec3 ioLinearVelocity, [Ref] Vec3 ioAngularVelocity);
boolean OnContactValidate([Const] CharacterVirtual inCharacter, [Const, Ref] BodyID inBodyID2, [Const, Ref] SubShapeID inSubShapeID2);
boolean OnCharacterContactValidate([Const] CharacterVirtual inCharacter, [Const] CharacterVirtual inOtherCharacter, [Const, Ref] SubShapeID inSubShapeID2);
void OnContactAdded([Const] CharacterVirtual inCharacter, [Const, Ref] BodyID inBodyID2, [Const, Ref] SubShapeID inSubShapeID2, [Const] RVec3 inContactPosition, [Const] Vec3 inContactNormal, [Ref] CharacterContactSettings ioSettings);
void OnCharacterContactAdded([Const] CharacterVirtual inCharacter, [Const] CharacterVirtual inOtherCharacter, [Const, Ref] SubShapeID inSubShapeID2, [Const] RVec3 inContactPosition, [Const] Vec3 inContactNormal, [Ref] CharacterContactSettings ioSettings);
void OnContactSolve([Const] CharacterVirtual inCharacter, [Const, Ref] BodyID inBodyID2, [Const, Ref] SubShapeID inSubShapeID2, [Const] RVec3 inContactPosition, [Const] Vec3 inContactNormal, [Const] Vec3 inContactVelocity, [Const] PhysicsMaterial inContactMaterial, [Const] Vec3 inCharacterVelocity, [Ref] Vec3 ioNewCharacterVelocity);
void OnCharacterContactSolve([Const] CharacterVirtual inCharacter, [Const] CharacterVirtual inOtherCharacter, [Const, Ref] SubShapeID inSubShapeID2, [Const] RVec3 inContactPosition, [Const] Vec3 inContactNormal, [Const] Vec3 inContactVelocity, [Const] PhysicsMaterial inContactMaterial, [Const] Vec3 inCharacterVelocity, [Ref] Vec3 ioNewCharacterVelocity);
};

interface CharacterVsCharacterCollision {
};

interface CharacterVsCharacterCollisionSimple {
void Add(CharacterVirtual inCharacter);
void Remove(CharacterVirtual inCharacter);
};

CharacterVsCharacterCollisionSimple implements CharacterVsCharacterCollision;

[Prefix="CharacterVirtual::"]
interface ExtendedUpdateSettings {
void ExtendedUpdateSettings();
Expand Down Expand Up @@ -2855,6 +2871,7 @@ interface CharacterBase {
interface CharacterVirtual {
void CharacterVirtual([Const] CharacterVirtualSettings inSettings, [Ref] RVec3 inPosition, [Ref] Quat inRotation, PhysicsSystem inSystem);
void SetListener(CharacterContactListener inListener);
void SetCharacterVsCharacterCollision(CharacterVsCharacterCollision inCharacterVsCharacterCollision);
CharacterContactListener GetListener();
[Value] Vec3 GetLinearVelocity();
void SetLinearVelocity([Const, Ref] Vec3 inLinearVelocity);
Expand Down

0 comments on commit 2f4fc67

Please sign in to comment.