diff --git a/base/plugins/phys_jolt/phys_jolt.cpp b/base/plugins/phys_jolt/phys_jolt.cpp index 6b329c4a..8bceecd7 100644 --- a/base/plugins/phys_jolt/phys_jolt.cpp +++ b/base/plugins/phys_jolt/phys_jolt.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -156,27 +157,22 @@ void _jolt_world_destroy() { Factory::sInstance = nullptr; } -void *_jolt_body_create(int shape, float mass, float dimx, float x, float y, float z, void *f32a_triangles) { +void *_jolt_body_create(int shape, float mass, float dimx, float dimy, float dimz, float x, float y, float z, void *f32a_triangles) { BodyInterface &body_interface = physics_system->GetBodyInterface(); Body *body; + ShapeSettings::ShapeResult result; if (shape == 0) { + // Box + BoxShapeSettings shape_settings(RVec3(dimx, dimy, dimz)); + shape_settings.SetEmbedded(); + result = shape_settings.Create(); + } + else if (shape == 1) { // Sphere SphereShapeSettings shape_settings(dimx); shape_settings.SetEmbedded(); - ShapeSettings::ShapeResult result = shape_settings.Create(); - ShapeRefC shape = result.Get(); - BodyCreationSettings settings(shape, RVec3(x, y, z), Quat::sIdentity(), EMotionType::Dynamic, Layers::MOVING); - - settings.mMotionQuality = EMotionQuality::LinearCast; // CCD - - MassProperties mass_prop; - mass_prop.ScaleToMass(mass); - settings.mMassPropertiesOverride = mass_prop; - settings.mOverrideMassProperties = EOverrideMassProperties::CalculateInertia; - - body = body_interface.CreateBody(settings); - body_interface.AddBody(body->GetID(), EActivation::Activate); + result = shape_settings.Create(); } else { // Mesh @@ -191,14 +187,26 @@ void *_jolt_body_create(int shape, float mass, float dimx, float x, float y, flo } MeshShapeSettings shape_settings(triangles); shape_settings.SetEmbedded(); - ShapeSettings::ShapeResult result = shape_settings.Create(); - ShapeRefC shape = result.Get(); - BodyCreationSettings settings(shape, RVec3(x, y, z), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING); - - body = body_interface.CreateBody(settings); - body_interface.AddBody(body->GetID(), EActivation::Activate); + result = shape_settings.Create(); } + ShapeRefC shape_c = result.Get(); + BodyCreationSettings settings(shape_c, RVec3(x, y, z), Quat::sIdentity(), mass == 0 ? EMotionType::Static : EMotionType::Dynamic, + mass == 0 ? Layers::NON_MOVING : Layers::MOVING); + + // if (ccd) { + if (shape != 2) { // != Mesh + settings.mMotionQuality = EMotionQuality::LinearCast; + } + + MassProperties mass_prop; + mass_prop.ScaleToMass(mass); + settings.mMassPropertiesOverride = mass_prop; + settings.mOverrideMassProperties = EOverrideMassProperties::CalculateInertia; + + body = body_interface.CreateBody(settings); + body_interface.AddBody(body->GetID(), EActivation::Activate); + return body; } @@ -246,8 +254,8 @@ extern "C" { _jolt_world_destroy(); } - void *jolt_body_create(int shape, float mass, float dimx, float x, float y, float z, void *f32a_triangles) { - return _jolt_body_create(shape, mass, dimx, x, y, z, f32a_triangles); + void *jolt_body_create(int shape, float mass, float dimx, float dimy, float dimz, float x, float y, float z, void *f32a_triangles) { + return _jolt_body_create(shape, mass, dimx, dimy, dimz, x, y, z, f32a_triangles); } void jolt_body_apply_impulse(void *body, float x, float y, float z) { diff --git a/base/plugins/phys_jolt/phys_jolt.h b/base/plugins/phys_jolt/phys_jolt.h index 2a04aae5..a36b061f 100644 --- a/base/plugins/phys_jolt/phys_jolt.h +++ b/base/plugins/phys_jolt/phys_jolt.h @@ -16,7 +16,7 @@ void jolt_world_update(); physics_pair_t *jolt_world_get_contact_pairs(); void jolt_world_destroy(); -void* jolt_body_create(int shape, float mass, float dimx, float x, float y, float z, void *f32a_triangles); +void* jolt_body_create(int shape, float mass, float dimx, float dimy, float dimz, float x, float y, float z, void *f32a_triangles); void jolt_body_apply_impulse(void *b, float x, float y, float z); void jolt_body_get_pos(void *b, void *p); void jolt_body_get_rot(void *b, void *r); diff --git a/base/sources/physics_body.ts b/base/sources/physics_body.ts index 62a52908..e21bdb49 100644 --- a/base/sources/physics_body.ts +++ b/base/sources/physics_body.ts @@ -3,7 +3,7 @@ ///include -declare function jolt_body_create(shape: i32, mass: f32, dimx: f32, x: f32, y: f32, z: f32, triangles: f32[]): any; +declare function jolt_body_create(shape: i32, mass: f32, dimx: f32, dimy: f32, dimz: f32, x: f32, y: f32, z: f32, triangles: f32[]): any; declare function jolt_body_apply_impulse(body: any, x: f32, y: f32, z: f32): void; declare function jolt_body_get_pos(body: any, pos: vec4_t): void; declare function jolt_body_get_rot(body: any, rot: quat_t): void; @@ -13,12 +13,15 @@ type physics_body_t = { shape?: physics_shape_t; mass?: f32; dimx?: f32; + dimy?: f32; + dimz?: f32; obj?: object_t; }; enum physics_shape_t { - SPHERE = 0, - MESH = 1, + BOX = 0, + SPHERE = 1, + MESH = 2, } let physics_body_object_map: map_t = map_create(); @@ -69,7 +72,7 @@ function physics_body_init(body: physics_body_t, obj: object_t) { } let loc: vec4_t = obj.transform.loc; - body._body = jolt_body_create(body.shape, body.mass, body.dimx, loc.x, loc.y, loc.z, triangles); + body._body = jolt_body_create(body.shape, body.mass, body.dimx, body.dimy, body.dimz, loc.x, loc.y, loc.z, triangles); } function physics_body_apply_impulse(body: physics_body_t, dir: vec4_t) {