Skip to content

Commit

Permalink
Added support for MutableCompoundShape
Browse files Browse the repository at this point in the history
  • Loading branch information
jrouwe committed May 29, 2024
1 parent 7b1c6bf commit fcf5f5d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
19 changes: 16 additions & 3 deletions Examples/falling_shapes.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@

function generateObject() {

let numTypes = 8;
let numTypes = 9;
let objectType = Math.ceil(Math.random() * numTypes);

let shape = null;

let colors = [0xff0000, 0xd9b1a3, 0x4d4139, 0xccad33, 0xf2ff40, 0x00ff00, 0x165943, 0x567371, 0x80d5ff, 0x69778c, 0xbeb6f2, 0x7159b3, 0x73004d, 0xd90074, 0xff8091, 0xbf3030, 0x592400, 0xa66c29, 0xb3aa86, 0x296600, 0x00e600, 0x66ccaa, 0x00eeff, 0x3d9df2, 0x000e33, 0x3d00e6, 0xb300a7, 0xff80d5, 0x330d17, 0x59332d, 0xff8c40, 0x33210d, 0x403c00, 0x89d96c, 0x0d3312, 0x0d3330, 0x005c73, 0x0066ff, 0x334166, 0x1b0066, 0x4d3949, 0xbf8faf, 0x59000c]
let colors = [0xff0000, 0xd9b1a3, 0x4d4139, 0xccad33, 0xf2ff40, 0x00ff00, 0x165943, 0x567371, 0x80d5ff, 0x69778c, 0xbeb6f2, 0x7159b3, 0x73004d, 0xd90074, 0xff8091, 0xbf3030, 0x592400, 0xa66c29, 0xb3aa86, 0x296600, 0x00e600, 0x66ccaa, 0x00eeff, 0x3d9df2, 0x000e33, 0x3d00e6, 0xb300a7, 0xff80d5, 0x330d17, 0x59332d, 0xff8c40, 0x33210d, 0x403c00, 0x89d96c, 0x0d3312, 0x0d3330, 0x005c73, 0x0066ff, 0x334166, 0x1b0066, 0x4d3949, 0xbf8faf, 0x59000c, 0x0000ff]

switch (objectType) {
case 1: {
Expand Down Expand Up @@ -97,7 +97,7 @@
}

case 7: {
// Compound shape
// Static compound shape
let shapeSettings = new Jolt.StaticCompoundShapeSettings();
let l = 1.0 + Math.random();
let r2 = 0.5 + 0.5 * Math.random();
Expand All @@ -110,6 +110,19 @@
}

case 8: {
// Mutable compound shape
let shapeSettings = new Jolt.MutableCompoundShapeSettings();
let l = 1.0 + Math.random();
let r2 = 0.5 + 0.5 * Math.random();
let r1 = 0.5 * r2;
shapeSettings.AddShape(new Jolt.Vec3(-l, 0, 0), Jolt.Quat.prototype.sIdentity(), new Jolt.SphereShapeSettings(r2));
shapeSettings.AddShape(new Jolt.Vec3(l, 0, 0), Jolt.Quat.prototype.sIdentity(), new Jolt.BoxShapeSettings(Jolt.Vec3.prototype.sReplicate(r2)));
shapeSettings.AddShape(new Jolt.Vec3(0, 0, 0), Jolt.Quat.prototype.sRotation(new Jolt.Vec3(0, 0, 1), 0.5 * Math.PI), new Jolt.CapsuleShapeSettings(l, r1));
shape = shapeSettings.Create().Get();
break;
}

case 9: {
// Sphere with COM offset
let radius = 0.5;
shape = new Jolt.OffsetCenterOfMassShapeSettings(new Jolt.Vec3(0, -0.1 * radius, 0), new Jolt.SphereShapeSettings(radius, null)).Create().Get();
Expand Down
3 changes: 3 additions & 0 deletions JoltJS.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "Jolt/Physics/Collision/Shape/CylinderShape.h"
#include "Jolt/Physics/Collision/Shape/ConvexHullShape.h"
#include "Jolt/Physics/Collision/Shape/StaticCompoundShape.h"
#include "Jolt/Physics/Collision/Shape/MutableCompoundShape.h"
#include "Jolt/Physics/Collision/Shape/ScaledShape.h"
#include "Jolt/Physics/Collision/Shape/OffsetCenterOfMassShape.h"
#include "Jolt/Physics/Collision/Shape/RotatedTranslatedShape.h"
Expand Down Expand Up @@ -89,6 +90,8 @@ using ArrayFloat = Array<float>;
using ArrayUint = Array<uint>;
using ArrayUint8 = Array<uint8>;
using Vec3MemRef = Vec3;
using QuatMemRef = Quat;
using ArrayQuat = Array<Quat>;
using Mat44MemRef = Mat44;
using ArrayMat44 = Array<Mat44>;
using FloatMemRef = float;
Expand Down
41 changes: 39 additions & 2 deletions JoltJS.idl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ interface ArrayVec3 {
Vec3MemRef data();
};

interface ArrayQuat {
boolean empty();
long size();
[Ref] Quat at(long inIndex);
void push_back([Const, Ref] Quat inValue);
void reserve(unsigned long inSize);
void resize(unsigned long inSize);
void clear();
QuatMemRef data();
};

interface ArrayMat44 {
boolean empty();
long size();
Expand Down Expand Up @@ -219,6 +230,9 @@ enum SoftBodySharedSettings_ELRAType {
interface Vec3MemRef {
};

interface QuatMemRef {
};

interface Mat44MemRef {
};

Expand Down Expand Up @@ -838,6 +852,12 @@ interface ConvexHullShape {
ConvexHullShape implements ConvexShape;

// Compound shape
interface CompoundShapeSettings {
void AddShape([Const, Ref] Vec3 inPosition, [Const, Ref] Quat inRotation, [Const] ShapeSettings inShape, unsigned long inUserData);
};

CompoundShapeSettings implements ShapeSettings;

interface CompoundShapeSubShape {
[Value] Vec3 GetPositionCOM();
[Value] Quat GetRotation();
Expand All @@ -856,16 +876,33 @@ CompoundShape implements Shape;
// Static compound
interface StaticCompoundShapeSettings {
void StaticCompoundShapeSettings();
void AddShape([Const, Ref] Vec3 inPosition, [Const, Ref] Quat inRotation, [Const] ShapeSettings inShape, unsigned long inUserData);
};

StaticCompoundShapeSettings implements ShapeSettings;
StaticCompoundShapeSettings implements CompoundShapeSettings;

interface StaticCompoundShape {
};

StaticCompoundShape implements CompoundShape;

// Mutable compound
interface MutableCompoundShapeSettings {
void MutableCompoundShapeSettings();
};

MutableCompoundShapeSettings implements CompoundShapeSettings;

interface MutableCompoundShape {
unsigned long AddShape([Const, Ref] Vec3 inPosition, [Const, Ref] Quat inRotation, Shape inShape, unsigned long inUserData);
void RemoveShape(unsigned long inIndex);
void ModifyShape(unsigned long inIndex, [Const, Ref] Vec3 inPosition, [Const, Ref] Quat inRotation);
void ModifyShape(unsigned long inIndex, [Const, Ref] Vec3 inPosition, [Const, Ref] Quat inRotation, Shape inShape);
void ModifyShapes(unsigned long inStartIndex, unsigned long inNumber, Vec3MemRef inPositions, QuatMemRef inRotations);
void AdjustCenterOfMass();
};

MutableCompoundShape implements CompoundShape;

// Decorated shape
interface DecoratedShapeSettings {
};
Expand Down

0 comments on commit fcf5f5d

Please sign in to comment.