@perplexdotgg/bounce 1.2.5 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bounce.d.ts +31 -21
- package/build/bounce.js +56 -90
- package/docs/documentation.md +10 -3
- package/package.json +1 -1
package/build/bounce.d.ts
CHANGED
|
@@ -272,7 +272,7 @@ readonly scale: 1;
|
|
|
272
272
|
declare class Body_2 extends Body_base {
|
|
273
273
|
world: World | null;
|
|
274
274
|
get shape(): Shape | null;
|
|
275
|
-
set shape(
|
|
275
|
+
set shape(newShape: Shape);
|
|
276
276
|
/**
|
|
277
277
|
* integrates the linear velocity of a body
|
|
278
278
|
*/
|
|
@@ -318,7 +318,7 @@ declare class Body_2 extends Body_base {
|
|
|
318
318
|
}
|
|
319
319
|
export { Body_2 as Body }
|
|
320
320
|
|
|
321
|
-
declare const Body_base: Monomorph<Body_2, ConvertedInputPropertyDefinitionMap<
|
|
321
|
+
declare const Body_base: Monomorph<Body_2, ConvertedInputPropertyDefinitionMap<{
|
|
322
322
|
readonly type: PropertyDefinition_2<BodyType, true>;
|
|
323
323
|
readonly position: typeof Vec3;
|
|
324
324
|
readonly orientation: typeof Quat;
|
|
@@ -329,7 +329,7 @@ x?: number;
|
|
|
329
329
|
y?: number;
|
|
330
330
|
z?: number;
|
|
331
331
|
} | undefined>, true, typeof Vec3>;
|
|
332
|
-
readonly computedBounds: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<
|
|
332
|
+
readonly computedBounds: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<{
|
|
333
333
|
readonly min: typeof Vec3;
|
|
334
334
|
readonly max: typeof Vec3;
|
|
335
335
|
readonly centroid: PropertyDefinition_2<NoInfer<number[] | {
|
|
@@ -358,7 +358,7 @@ readonly restitutionFunction: PropertyDefinition_2<CoefficientFunctionType, true
|
|
|
358
358
|
readonly mass: 0;
|
|
359
359
|
readonly density: 0;
|
|
360
360
|
readonly inverseMass: PropertyDefinitionNumber<true>;
|
|
361
|
-
readonly computedLocalInverseInertia: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<
|
|
361
|
+
readonly computedLocalInverseInertia: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<{
|
|
362
362
|
readonly e0: 0;
|
|
363
363
|
readonly e1: 0;
|
|
364
364
|
readonly e2: 0;
|
|
@@ -369,7 +369,7 @@ readonly e6: 0;
|
|
|
369
369
|
readonly e7: 0;
|
|
370
370
|
readonly e8: 0;
|
|
371
371
|
}>> | undefined>, true, typeof Mat3>;
|
|
372
|
-
readonly computedWorldInverseInertia: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<
|
|
372
|
+
readonly computedWorldInverseInertia: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<{
|
|
373
373
|
readonly e0: 0;
|
|
374
374
|
readonly e1: 0;
|
|
375
375
|
readonly e2: 0;
|
|
@@ -411,7 +411,7 @@ readonly linearDamping: -1;
|
|
|
411
411
|
readonly angularDamping: -1;
|
|
412
412
|
readonly firstPotentialConstraintPairEdge: PropertyDefinitionReference<ConstraintPairEdge | null, true>;
|
|
413
413
|
readonly visitGeneration: PropertyDefinitionNumber<true>;
|
|
414
|
-
}>, PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<
|
|
414
|
+
}>, PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<{
|
|
415
415
|
readonly type: PropertyDefinition_2<BodyType, true>;
|
|
416
416
|
readonly position: typeof Vec3;
|
|
417
417
|
readonly orientation: typeof Quat;
|
|
@@ -422,7 +422,7 @@ x?: number;
|
|
|
422
422
|
y?: number;
|
|
423
423
|
z?: number;
|
|
424
424
|
} | undefined>, true, typeof Vec3>;
|
|
425
|
-
readonly computedBounds: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<
|
|
425
|
+
readonly computedBounds: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<{
|
|
426
426
|
readonly min: typeof Vec3;
|
|
427
427
|
readonly max: typeof Vec3;
|
|
428
428
|
readonly centroid: PropertyDefinition_2<NoInfer<number[] | {
|
|
@@ -451,7 +451,7 @@ readonly restitutionFunction: PropertyDefinition_2<CoefficientFunctionType, true
|
|
|
451
451
|
readonly mass: 0;
|
|
452
452
|
readonly density: 0;
|
|
453
453
|
readonly inverseMass: PropertyDefinitionNumber<true>;
|
|
454
|
-
readonly computedLocalInverseInertia: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<
|
|
454
|
+
readonly computedLocalInverseInertia: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<{
|
|
455
455
|
readonly e0: 0;
|
|
456
456
|
readonly e1: 0;
|
|
457
457
|
readonly e2: 0;
|
|
@@ -462,7 +462,7 @@ readonly e6: 0;
|
|
|
462
462
|
readonly e7: 0;
|
|
463
463
|
readonly e8: 0;
|
|
464
464
|
}>> | undefined>, true, typeof Mat3>;
|
|
465
|
-
readonly computedWorldInverseInertia: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<
|
|
465
|
+
readonly computedWorldInverseInertia: PropertyDefinition_2<NoInfer<PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap<{
|
|
466
466
|
readonly e0: 0;
|
|
467
467
|
readonly e1: 0;
|
|
468
468
|
readonly e2: 0;
|
|
@@ -504,7 +504,9 @@ readonly linearDamping: -1;
|
|
|
504
504
|
readonly angularDamping: -1;
|
|
505
505
|
readonly firstPotentialConstraintPairEdge: PropertyDefinitionReference<ConstraintPairEdge | null, true>;
|
|
506
506
|
readonly visitGeneration: PropertyDefinitionNumber<true>;
|
|
507
|
-
}>>
|
|
507
|
+
}>> & {
|
|
508
|
+
world?: World | null;
|
|
509
|
+
}>;
|
|
508
510
|
|
|
509
511
|
declare class BodyPairEdge extends BodyPairEdge_base {
|
|
510
512
|
}
|
|
@@ -709,12 +711,12 @@ declare interface BuildTriangleMeshParams {
|
|
|
709
711
|
vertexPositions: Float32Array;
|
|
710
712
|
faceIndices: Uint32Array;
|
|
711
713
|
/**
|
|
712
|
-
* If true,
|
|
713
|
-
* The hull is only used for dynamic bodies, so if the trimesh is
|
|
714
|
-
* for static bodies, this can be set to true to save computation time.
|
|
715
|
-
* Also this allows for building trimeshes with more than 1k verts (hull limit)
|
|
714
|
+
* If true, forces the creation of a convex hull for the triangle mesh to estimate properties
|
|
715
|
+
* like volume and inertia tensor. The hull is only used for dynamic bodies, so if the trimesh is
|
|
716
|
+
* only intended for static bodies, this can be set to true to save computation time.
|
|
717
|
+
* Also this allows for building trimeshes with more than 1k verts (default convex hull limit)
|
|
716
718
|
*/
|
|
717
|
-
|
|
719
|
+
forceCreateConvexHull?: boolean;
|
|
718
720
|
}
|
|
719
721
|
|
|
720
722
|
declare class BvhModule {
|
|
@@ -862,7 +864,9 @@ readonly linearDamping: -1;
|
|
|
862
864
|
readonly angularDamping: -1;
|
|
863
865
|
readonly firstPotentialConstraintPairEdge: PropertyDefinitionReference<ConstraintPairEdge | null, true>;
|
|
864
866
|
readonly visitGeneration: PropertyDefinitionNumber<true>;
|
|
865
|
-
}>>
|
|
867
|
+
}>> & {
|
|
868
|
+
world?: World | null;
|
|
869
|
+
})[] | undefined;
|
|
866
870
|
maxLength?: number;
|
|
867
871
|
}>;
|
|
868
872
|
}>, PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap< {
|
|
@@ -974,7 +978,9 @@ readonly linearDamping: -1;
|
|
|
974
978
|
readonly angularDamping: -1;
|
|
975
979
|
readonly firstPotentialConstraintPairEdge: PropertyDefinitionReference<ConstraintPairEdge | null, true>;
|
|
976
980
|
readonly visitGeneration: PropertyDefinitionNumber<true>;
|
|
977
|
-
}>>
|
|
981
|
+
}>> & {
|
|
982
|
+
world?: World | null;
|
|
983
|
+
})[] | undefined;
|
|
978
984
|
maxLength?: number;
|
|
979
985
|
}>;
|
|
980
986
|
}>> | undefined>;
|
|
@@ -1105,7 +1111,9 @@ export declare class BvhTree {
|
|
|
1105
1111
|
readonly angularDamping: -1;
|
|
1106
1112
|
readonly firstPotentialConstraintPairEdge: PropertyDefinitionReference<ConstraintPairEdge | null, true>;
|
|
1107
1113
|
readonly visitGeneration: PropertyDefinitionNumber<true>;
|
|
1108
|
-
}>>
|
|
1114
|
+
}>> & {
|
|
1115
|
+
world?: World | null;
|
|
1116
|
+
})[] | undefined;
|
|
1109
1117
|
maxLength?: number;
|
|
1110
1118
|
}>;
|
|
1111
1119
|
}>, PropertyDefinitionMapInput<ConvertedInputPropertyDefinitionMap< {
|
|
@@ -1217,7 +1225,9 @@ export declare class BvhTree {
|
|
|
1217
1225
|
readonly angularDamping: -1;
|
|
1218
1226
|
readonly firstPotentialConstraintPairEdge: PropertyDefinitionReference<ConstraintPairEdge | null, true>;
|
|
1219
1227
|
readonly visitGeneration: PropertyDefinitionNumber<true>;
|
|
1220
|
-
}>>
|
|
1228
|
+
}>> & {
|
|
1229
|
+
world?: World | null;
|
|
1230
|
+
})[] | undefined;
|
|
1221
1231
|
maxLength?: number;
|
|
1222
1232
|
}>;
|
|
1223
1233
|
}>> | undefined, BvhNode>;
|
|
@@ -2207,7 +2217,7 @@ readonly copyForDiff: PropertyDefinitionReference<ConvexHull | null, true>;
|
|
|
2207
2217
|
}>> | undefined>;
|
|
2208
2218
|
|
|
2209
2219
|
declare class ConvexHullBuilder {
|
|
2210
|
-
buildFromPoints(vertices: Float32Array, convexRadius?: number, hullTolerance?: number, convexHullPool?: typeof ConvexHull.Pool, facePool?: typeof ConvexHullFace.Pool, numberValuePool?: typeof NumberValue.Pool, planePool?: typeof Plane.Pool, pointPool?: typeof ConvexHullPoint.Pool, shapeNoConvexPointsPool?: typeof Vec3.Pool): ConvexHull;
|
|
2220
|
+
buildFromPoints(vertices: Float32Array, convexRadius?: number, hullTolerance?: number, maxPoints?: number, maxVertexIndices?: number, convexHullPool?: typeof ConvexHull.Pool, facePool?: typeof ConvexHullFace.Pool, numberValuePool?: typeof NumberValue.Pool, planePool?: typeof Plane.Pool, pointPool?: typeof ConvexHullPoint.Pool, shapeNoConvexPointsPool?: typeof Vec3.Pool): ConvexHull;
|
|
2211
2221
|
}
|
|
2212
2222
|
|
|
2213
2223
|
declare class ConvexHullFace extends ConvexHullFace_base {
|
|
@@ -5200,7 +5210,7 @@ export declare class World {
|
|
|
5200
5210
|
createCylinder(options: InputType<Cylinder>): NoInfer<WithPool<Cylinder>>;
|
|
5201
5211
|
createCapsule(options: InputType<Capsule>): NoInfer<WithPool<Capsule>>;
|
|
5202
5212
|
createTriangleMesh(params: BuildTriangleMeshParams): NoInfer<WithPool<TriangleMesh>>;
|
|
5203
|
-
createConvexHull(vertices: Float32Array, convexRadius?: number, hullTolerance?: number): NoInfer<WithPool<ConvexHull>>;
|
|
5213
|
+
createConvexHull(vertices: Float32Array, convexRadius?: number, hullTolerance?: number, maxPoints?: number, maxVertexIndices?: number): NoInfer<WithPool<ConvexHull>>;
|
|
5204
5214
|
createCompoundShape(params: {
|
|
5205
5215
|
shape: Shape;
|
|
5206
5216
|
transform: InputType<BasicTransform>;
|
package/build/bounce.js
CHANGED
|
@@ -943,12 +943,16 @@ const quatProps = {
|
|
|
943
943
|
class Quat extends createClass(quatProps) {
|
|
944
944
|
constructor(data, index, pool) {
|
|
945
945
|
if (Array.isArray(data)) {
|
|
946
|
-
data
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
946
|
+
if (data.length && data.length < 4) {
|
|
947
|
+
tempQuat.setFromEulerRadians(data[0], data[1] ?? 0, data[2] ?? 0);
|
|
948
|
+
} else {
|
|
949
|
+
tempQuat.x = data[0] ?? 0;
|
|
950
|
+
tempQuat.y = data[1] ?? 0;
|
|
951
|
+
tempQuat.z = data[2] ?? 0;
|
|
952
|
+
tempQuat.w = data[3] ?? 1;
|
|
953
|
+
}
|
|
954
|
+
super(tempQuat, index, pool);
|
|
955
|
+
return;
|
|
952
956
|
}
|
|
953
957
|
super(data, index, pool);
|
|
954
958
|
}
|
|
@@ -1151,6 +1155,7 @@ class Quat extends createClass(quatProps) {
|
|
|
1151
1155
|
}
|
|
1152
1156
|
const vector = /* @__PURE__ */ Vec3.create();
|
|
1153
1157
|
const tempMat3 = /* @__PURE__ */ Mat3.create();
|
|
1158
|
+
const tempQuat = /* @__PURE__ */ Quat.create();
|
|
1154
1159
|
const rotationMatrix$2 = /* @__PURE__ */ Mat3.create();
|
|
1155
1160
|
const scaling = /* @__PURE__ */ Vec3.create();
|
|
1156
1161
|
const conjugatedRotation = /* @__PURE__ */ Quat.create();
|
|
@@ -2854,64 +2859,6 @@ class ArrayPool {
|
|
|
2854
2859
|
this._count = 0;
|
|
2855
2860
|
}
|
|
2856
2861
|
}
|
|
2857
|
-
function coerceVec3Argument(obj, key) {
|
|
2858
|
-
let value = obj[key];
|
|
2859
|
-
if (!value) {
|
|
2860
|
-
return;
|
|
2861
|
-
}
|
|
2862
|
-
if (Array.isArray(value)) {
|
|
2863
|
-
value = { x: value[0], y: value[1], z: value[2] };
|
|
2864
|
-
}
|
|
2865
|
-
obj[key] = value;
|
|
2866
|
-
}
|
|
2867
|
-
function coerceQuatArgument(obj, key) {
|
|
2868
|
-
let value = obj[key];
|
|
2869
|
-
if (!value) {
|
|
2870
|
-
return;
|
|
2871
|
-
}
|
|
2872
|
-
if (Array.isArray(value)) {
|
|
2873
|
-
if (Array.length === 3) {
|
|
2874
|
-
let x2 = value[0] * (180 / Math.PI);
|
|
2875
|
-
let y4 = value[1] * (180 / Math.PI);
|
|
2876
|
-
let z = value[2] * (180 / Math.PI);
|
|
2877
|
-
let halfToRad = Math.PI / 360;
|
|
2878
|
-
x2 *= halfToRad;
|
|
2879
|
-
z *= halfToRad;
|
|
2880
|
-
y4 *= halfToRad;
|
|
2881
|
-
let sx = Math.sin(x2);
|
|
2882
|
-
let cx = Math.cos(x2);
|
|
2883
|
-
let sy = Math.sin(y4);
|
|
2884
|
-
let cy = Math.cos(y4);
|
|
2885
|
-
let sz = Math.sin(z);
|
|
2886
|
-
let cz = Math.cos(z);
|
|
2887
|
-
value = { x: 0, y: 0, z: 0, w: 0 };
|
|
2888
|
-
value.x = sx * cy * cz + cx * sy * sz;
|
|
2889
|
-
value.y = cx * sy * cz - sx * cy * sz;
|
|
2890
|
-
value.z = cx * cy * sz + sx * sy * cz;
|
|
2891
|
-
value.w = cx * cy * cz - sx * sy * sz;
|
|
2892
|
-
}
|
|
2893
|
-
} else if (!("w" in value)) {
|
|
2894
|
-
let x2 = value.x * (180 / Math.PI);
|
|
2895
|
-
let y4 = value.y * (180 / Math.PI);
|
|
2896
|
-
let z = value.z * (180 / Math.PI);
|
|
2897
|
-
let halfToRad = Math.PI / 360;
|
|
2898
|
-
x2 *= halfToRad;
|
|
2899
|
-
z *= halfToRad;
|
|
2900
|
-
y4 *= halfToRad;
|
|
2901
|
-
let sx = Math.sin(x2);
|
|
2902
|
-
let cx = Math.cos(x2);
|
|
2903
|
-
let sy = Math.sin(y4);
|
|
2904
|
-
let cy = Math.cos(y4);
|
|
2905
|
-
let sz = Math.sin(z);
|
|
2906
|
-
let cz = Math.cos(z);
|
|
2907
|
-
value = { x: 0, y: 0, z: 0, w: 0 };
|
|
2908
|
-
value.x = sx * cy * cz + cx * sy * sz;
|
|
2909
|
-
value.y = cx * sy * cz - sx * cy * sz;
|
|
2910
|
-
value.z = cx * cy * sz + sx * sy * cz;
|
|
2911
|
-
value.w = cx * cy * cz - sx * sy * sz;
|
|
2912
|
-
}
|
|
2913
|
-
obj[key] = value;
|
|
2914
|
-
}
|
|
2915
2862
|
function getCombinedFriction(bodyA, bodyB, fallbackFrictionFunction) {
|
|
2916
2863
|
const frictionFunction = bodyA.frictionFunction !== bodyB.frictionFunction ? fallbackFrictionFunction : bodyA.frictionFunction;
|
|
2917
2864
|
return coefficientFunctions[frictionFunction](bodyA.friction, bodyB.friction);
|
|
@@ -8094,10 +8041,28 @@ class Body extends createClass(bodyProps, { afterConstructorCode }) {
|
|
|
8094
8041
|
get shape() {
|
|
8095
8042
|
return this["shape" + this.shapeType];
|
|
8096
8043
|
}
|
|
8097
|
-
set shape(
|
|
8044
|
+
set shape(newShape) {
|
|
8098
8045
|
this["shape" + this.shapeType] = null;
|
|
8099
|
-
this["shape" +
|
|
8100
|
-
this.shapeType =
|
|
8046
|
+
this["shape" + newShape.type] = newShape;
|
|
8047
|
+
this.shapeType = newShape.type;
|
|
8048
|
+
if (newShape.type === ShapeType.triangleMesh && this.type === 0 && !newShape.computedVolume) {
|
|
8049
|
+
const float32Array = new Float32Array(newShape.vertexPositions.length * 3);
|
|
8050
|
+
let index = 0;
|
|
8051
|
+
for (const vertexPosition of newShape.vertexPositions) {
|
|
8052
|
+
float32Array[index++] = vertexPosition.x;
|
|
8053
|
+
float32Array[index++] = vertexPosition.y;
|
|
8054
|
+
float32Array[index++] = vertexPosition.z;
|
|
8055
|
+
}
|
|
8056
|
+
const hull = this.world.triangleMeshBuilder.convexHullBuilder.buildFromPoints(
|
|
8057
|
+
float32Array,
|
|
8058
|
+
0.02,
|
|
8059
|
+
1e-3,
|
|
8060
|
+
Infinity,
|
|
8061
|
+
Infinity
|
|
8062
|
+
);
|
|
8063
|
+
newShape.computedVolume = hull.computedVolume;
|
|
8064
|
+
newShape.inertia.copy(hull.inertia);
|
|
8065
|
+
}
|
|
8101
8066
|
updateBody(this);
|
|
8102
8067
|
}
|
|
8103
8068
|
// physics integration functions
|
|
@@ -8350,6 +8315,21 @@ class Body extends createClass(bodyProps, { afterConstructorCode }) {
|
|
|
8350
8315
|
this.world.broadphase.markDynamicBodyAsDirty(this);
|
|
8351
8316
|
}
|
|
8352
8317
|
}
|
|
8318
|
+
const oldCreate$1 = Body.create;
|
|
8319
|
+
Body.create = function() {
|
|
8320
|
+
const data = arguments[0];
|
|
8321
|
+
const body2 = oldCreate$1.apply(this, arguments);
|
|
8322
|
+
body2.orientation.normalize();
|
|
8323
|
+
body2.previousPosition.copy(body2.position);
|
|
8324
|
+
body2.previousOrientation.copy(body2.orientation);
|
|
8325
|
+
if (data.world) {
|
|
8326
|
+
body2.world = data.world;
|
|
8327
|
+
}
|
|
8328
|
+
if (data.shape) {
|
|
8329
|
+
body2.shape = data.shape;
|
|
8330
|
+
}
|
|
8331
|
+
return body2;
|
|
8332
|
+
};
|
|
8353
8333
|
const forcePointInWorldSpace = /* @__PURE__ */ Vec3.create();
|
|
8354
8334
|
const impulsePointInWorldSpace = /* @__PURE__ */ Vec3.create();
|
|
8355
8335
|
const angularDofsMask = /* @__PURE__ */ Vec3.create();
|
|
@@ -8364,20 +8344,6 @@ const deltaVelocity = /* @__PURE__ */ Vec3.create();
|
|
|
8364
8344
|
const angularInverseMass = /* @__PURE__ */ Vec3.create();
|
|
8365
8345
|
const rotationDelta = /* @__PURE__ */ Vec3.create();
|
|
8366
8346
|
const isometry$1 = /* @__PURE__ */ Isometry.create();
|
|
8367
|
-
const oldCreate$1 = Body.create;
|
|
8368
|
-
Body.create = function() {
|
|
8369
|
-
const data = arguments[0];
|
|
8370
|
-
coerceVec3Argument(data, "position");
|
|
8371
|
-
coerceQuatArgument(data, "orientation");
|
|
8372
|
-
const body2 = oldCreate$1.apply(this, arguments);
|
|
8373
|
-
body2.orientation.normalize();
|
|
8374
|
-
body2.previousPosition.copy(body2.position);
|
|
8375
|
-
body2.previousOrientation.copy(body2.orientation);
|
|
8376
|
-
if (data.shape) {
|
|
8377
|
-
body2.shape = data.shape;
|
|
8378
|
-
}
|
|
8379
|
-
return body2;
|
|
8380
|
-
};
|
|
8381
8347
|
function updateCenterOfMassPosition(body2) {
|
|
8382
8348
|
shapeCenterOfMassInWorldSpace$1.copy(body2.shape.computedCenterOfMass);
|
|
8383
8349
|
shapeCenterOfMassInWorldSpace$1.transformByQuat(body2.orientation);
|
|
@@ -14852,9 +14818,7 @@ const n = /* @__PURE__ */ Mat3.create();
|
|
|
14852
14818
|
const adj_n = /* @__PURE__ */ Mat3.create();
|
|
14853
14819
|
const transformedOffset = /* @__PURE__ */ Vec3.create();
|
|
14854
14820
|
class ConvexHullBuilder {
|
|
14855
|
-
buildFromPoints(vertices, convexRadius = 0.02, hullTolerance = 1e-3, convexHullPool = new ConvexHull.Pool(), facePool = new ConvexHullFace.Pool(), numberValuePool = new NumberValue.Pool(), planePool = new Plane.Pool(), pointPool = new ConvexHullPoint.Pool(), shapeNoConvexPointsPool = new Vec3.Pool()) {
|
|
14856
|
-
const maxPoints = 1e3;
|
|
14857
|
-
const maxVertexIndices = 1e3;
|
|
14821
|
+
buildFromPoints(vertices, convexRadius = 0.02, hullTolerance = 1e-3, maxPoints = 1e3, maxVertexIndices = 1e3, convexHullPool = new ConvexHull.Pool(), facePool = new ConvexHullFace.Pool(), numberValuePool = new NumberValue.Pool(), planePool = new Plane.Pool(), pointPool = new ConvexHullPoint.Pool(), shapeNoConvexPointsPool = new Vec3.Pool()) {
|
|
14858
14822
|
const hull = ConvexHull.create({
|
|
14859
14823
|
convexRadius,
|
|
14860
14824
|
faces: { pool: facePool },
|
|
@@ -15130,8 +15094,8 @@ class TriangleMeshBuilder {
|
|
|
15130
15094
|
nodes: { pool: nodes }
|
|
15131
15095
|
}, bvhTreePool);
|
|
15132
15096
|
mesh.bvh.build(mesh, triangles);
|
|
15133
|
-
if (
|
|
15134
|
-
const hull = this.convexHullBuilder.buildFromPoints(params.vertexPositions, 0, 1e-3);
|
|
15097
|
+
if (params.forceCreateConvexHull) {
|
|
15098
|
+
const hull = this.convexHullBuilder.buildFromPoints(params.vertexPositions, 0, 1e-3, Infinity, Infinity);
|
|
15135
15099
|
mesh.computedVolume = hull.computedVolume;
|
|
15136
15100
|
mesh.inertia.copy(hull.inertia);
|
|
15137
15101
|
}
|
|
@@ -15624,11 +15588,13 @@ class World {
|
|
|
15624
15588
|
shape.world = this;
|
|
15625
15589
|
return shape;
|
|
15626
15590
|
}
|
|
15627
|
-
createConvexHull(vertices, convexRadius = 0.02, hullTolerance = 1e-3) {
|
|
15591
|
+
createConvexHull(vertices, convexRadius = 0.02, hullTolerance = 1e-3, maxPoints = 1e3, maxVertexIndices = 1e3) {
|
|
15628
15592
|
const shape = this.convexHullBuilder.buildFromPoints(
|
|
15629
15593
|
vertices,
|
|
15630
15594
|
convexRadius,
|
|
15631
15595
|
hullTolerance,
|
|
15596
|
+
maxPoints,
|
|
15597
|
+
maxVertexIndices,
|
|
15632
15598
|
this.pools.convexHull,
|
|
15633
15599
|
this.pools.convexHullFace,
|
|
15634
15600
|
this.pools.convexHullNumberValue,
|
|
@@ -15698,33 +15664,33 @@ class World {
|
|
|
15698
15664
|
createStaticBody(options) {
|
|
15699
15665
|
options = options ?? {};
|
|
15700
15666
|
options.type = BodyType.static;
|
|
15667
|
+
options.world = this;
|
|
15701
15668
|
const body2 = this.staticBodies.create(options);
|
|
15702
15669
|
const bodyCopy = this.staticBodyCopies.create(options);
|
|
15703
15670
|
bodyCopy.copy(body2);
|
|
15704
15671
|
body2.copyForDiff = bodyCopy;
|
|
15705
|
-
body2.world = this;
|
|
15706
15672
|
this.broadphase.addStaticBody(body2);
|
|
15707
15673
|
return body2;
|
|
15708
15674
|
}
|
|
15709
15675
|
createDynamicBody(options) {
|
|
15710
15676
|
options = options ?? {};
|
|
15711
15677
|
options.type = BodyType.dynamic;
|
|
15678
|
+
options.world = this;
|
|
15712
15679
|
const body2 = this.dynamicBodies.create(options);
|
|
15713
15680
|
const bodyCopy = this.dynamicBodyCopies.create(options);
|
|
15714
15681
|
bodyCopy.copy(body2);
|
|
15715
15682
|
body2.copyForDiff = bodyCopy;
|
|
15716
|
-
body2.world = this;
|
|
15717
15683
|
this.broadphase.addDynamicBody(body2);
|
|
15718
15684
|
return body2;
|
|
15719
15685
|
}
|
|
15720
15686
|
createKinematicBody(options) {
|
|
15721
15687
|
options = options ?? {};
|
|
15722
15688
|
options.type = BodyType.kinematic;
|
|
15689
|
+
options.world = this;
|
|
15723
15690
|
const body2 = this.kinematicBodies.create(options);
|
|
15724
15691
|
const bodyCopy = this.kinematicBodyCopies.create(options);
|
|
15725
15692
|
bodyCopy.copy(body2);
|
|
15726
15693
|
body2.copyForDiff = bodyCopy;
|
|
15727
|
-
body2.world = this;
|
|
15728
15694
|
this.broadphase.addKinematicBody(body2);
|
|
15729
15695
|
return body2;
|
|
15730
15696
|
}
|
package/docs/documentation.md
CHANGED
|
@@ -99,9 +99,10 @@ const world = new World({
|
|
|
99
99
|
isWarmStartingEnabled: true,
|
|
100
100
|
|
|
101
101
|
// contact manifold limits
|
|
102
|
-
// by default since
|
|
102
|
+
// by default since v1.3.0, these are unlimited
|
|
103
103
|
// if set to a finite amount, an error is thrown when an allocation is attempted past the limit
|
|
104
104
|
// this may be desired during development to stay within a strict memory budget, for example
|
|
105
|
+
// 1024 is a reasonable limit for many use cases (it was the default prior to v1.3.0)
|
|
105
106
|
contactManifoldOptions: {
|
|
106
107
|
maxContactManifolds: Infinity,
|
|
107
108
|
maxContactPairs: Infinity,
|
|
@@ -142,7 +143,9 @@ const vertexPositions = new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]);
|
|
|
142
143
|
const shape = world.createConvexHull(
|
|
143
144
|
vertexPositions, // Float32Array of vertex positions
|
|
144
145
|
0.02, // convexRadius (optional, default 0.02)
|
|
145
|
-
1e-3 // hullTolerance (optional, default 1e-3)
|
|
146
|
+
1e-3, // hullTolerance (optional, default 1e-3 = 0.001)
|
|
147
|
+
1000, // maxPoints (optional, default 1000)
|
|
148
|
+
1000 // maxVertexIndices (optional, default 1000)
|
|
146
149
|
);
|
|
147
150
|
|
|
148
151
|
const body = world.createDynamicBody({ shape: shape, position: [0, 0, 5] });
|
|
@@ -169,7 +172,11 @@ const indices = new Uint32Array([
|
|
|
169
172
|
const shape = world.createTriangleMesh({
|
|
170
173
|
vertexPositions: vertices,
|
|
171
174
|
faceIndices: indices,
|
|
172
|
-
|
|
175
|
+
|
|
176
|
+
// optional, if you want to estimate the volume or inertia tensor based on the convex hull
|
|
177
|
+
// note that a convex hull is automatically created if a triangle mesh is used as a dynamic body
|
|
178
|
+
// that said, triangle meshes are generally not recommended as dynamic bodies, for performance reasons
|
|
179
|
+
forceCreateConvexHull: false,
|
|
173
180
|
});
|
|
174
181
|
|
|
175
182
|
const body = world.createStaticBody({ shape: shape });
|