forked from LeenkxTeam/LNXSDK
Jolt Patch
This commit is contained in:
@ -101,6 +101,15 @@ class Starter {
|
|||||||
kha.Assets.loadBlobFromPath(name, function(b: kha.Blob) {
|
kha.Assets.loadBlobFromPath(name, function(b: kha.Blob) {
|
||||||
js.Syntax.code("(1,eval)({0})", b.toString());
|
js.Syntax.code("(1,eval)({0})", b.toString());
|
||||||
#if kha_krom
|
#if kha_krom
|
||||||
|
#if lnx_jolt_mt
|
||||||
|
js.Syntax.code("Jolt({print:function(s){iron.log(s);},instantiateWasm:function(imports,successCallback) {
|
||||||
|
var wasmbin = Krom.loadBlob('jolt.mt.wasm.wasm');
|
||||||
|
var module = new WebAssembly.Module(wasmbin);
|
||||||
|
var inst = new WebAssembly.Instance(module,imports);
|
||||||
|
successCallback(inst,module);
|
||||||
|
return inst.exports;
|
||||||
|
}}).then(function(m){ Jolt=m; tasks--; start();})");
|
||||||
|
#else
|
||||||
js.Syntax.code("Jolt({print:function(s){iron.log(s);},instantiateWasm:function(imports,successCallback) {
|
js.Syntax.code("Jolt({print:function(s){iron.log(s);},instantiateWasm:function(imports,successCallback) {
|
||||||
var wasmbin = Krom.loadBlob('jolt.wasm.wasm');
|
var wasmbin = Krom.loadBlob('jolt.wasm.wasm');
|
||||||
var module = new WebAssembly.Module(wasmbin);
|
var module = new WebAssembly.Module(wasmbin);
|
||||||
@ -108,6 +117,7 @@ class Starter {
|
|||||||
successCallback(inst);
|
successCallback(inst);
|
||||||
return inst.exports;
|
return inst.exports;
|
||||||
}}).then(function(m){ Jolt=m; tasks--; start();})");
|
}}).then(function(m){ Jolt=m; tasks--; start();})");
|
||||||
|
#end
|
||||||
#else
|
#else
|
||||||
js.Syntax.code("Jolt({print:function(s){iron.log(s);},locateFile:function(f){return 'jolt.wasm.wasm';}}).then(function(m){ Jolt=m; tasks--; start();})");
|
js.Syntax.code("Jolt({print:function(s){iron.log(s);},locateFile:function(f){return 'jolt.wasm.wasm';}}).then(function(m){ Jolt=m; tasks--; start();})");
|
||||||
#end
|
#end
|
||||||
@ -147,8 +157,12 @@ class Starter {
|
|||||||
|
|
||||||
#if (js && lnx_jolt)
|
#if (js && lnx_jolt)
|
||||||
tasks++;
|
tasks++;
|
||||||
|
#if lnx_jolt_mt
|
||||||
|
loadLibJolt("jolt.mt.wasm.js");
|
||||||
|
#else
|
||||||
loadLibJolt("jolt.wasm.js");
|
loadLibJolt("jolt.wasm.js");
|
||||||
#end
|
#end
|
||||||
|
#end
|
||||||
|
|
||||||
#if (js && lnx_navigation)
|
#if (js && lnx_navigation)
|
||||||
tasks++;
|
tasks++;
|
||||||
|
|||||||
@ -6,14 +6,14 @@ import iron.Trait;
|
|||||||
import iron.object.MeshObject;
|
import iron.object.MeshObject;
|
||||||
import iron.data.MeshData;
|
import iron.data.MeshData;
|
||||||
import iron.data.SceneFormat;
|
import iron.data.SceneFormat;
|
||||||
#if (lnx_bullet || lnx_oimo)
|
#if lnx_physics
|
||||||
import leenkx.trait.physics.RigidBody;
|
import leenkx.trait.physics.RigidBody;
|
||||||
import leenkx.trait.physics.PhysicsWorld;
|
import leenkx.trait.physics.PhysicsWorld;
|
||||||
#end
|
#end
|
||||||
|
|
||||||
class PhysicsBreak extends Trait {
|
class PhysicsBreak extends Trait {
|
||||||
|
|
||||||
#if (!lnx_bullet && !lnx_oimo)
|
#if (!lnx_physics)
|
||||||
public function new() { super(); }
|
public function new() { super(); }
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@ -74,14 +74,16 @@ class PhysicsBreak extends Trait {
|
|||||||
impactNormal = p.normOnB;
|
impactNormal = p.normOnB;
|
||||||
#elseif lnx_oimo
|
#elseif lnx_oimo
|
||||||
impactNormal = p.nor;
|
impactNormal = p.nor;
|
||||||
|
#else
|
||||||
|
impactNormal = p.normOnB;
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if lnx_bullet
|
#if lnx_oimo
|
||||||
var fractureImpulse = 4.0;
|
|
||||||
#elseif lnx_oimo
|
|
||||||
var fractureImpulse = 1.0;
|
var fractureImpulse = 1.0;
|
||||||
|
#else
|
||||||
|
var fractureImpulse = 4.0;
|
||||||
#end
|
#end
|
||||||
if (maxImpulse > fractureImpulse && impactPoint != null && impactNormal != null) {
|
if (maxImpulse > fractureImpulse && impactPoint != null && impactNormal != null) {
|
||||||
var radialIter = 1;
|
var radialIter = 1;
|
||||||
|
|||||||
@ -11,25 +11,38 @@ import leenkx.trait.physics.PhysicsWorld;
|
|||||||
|
|
||||||
class PhysicsDrag extends Trait {
|
class PhysicsDrag extends Trait {
|
||||||
|
|
||||||
#if (!lnx_bullet)
|
#if (!lnx_physics)
|
||||||
public function new() { super(); }
|
public function new() { super(); }
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#if lnx_bullet
|
||||||
@prop public var linearLowerLimit = new Vec3(0,0,0);
|
@prop public var linearLowerLimit = new Vec3(0,0,0);
|
||||||
@prop public var linearUpperLimit = new Vec3(0,0,0);
|
@prop public var linearUpperLimit = new Vec3(0,0,0);
|
||||||
@prop public var angularLowerLimit = new Vec3(-10,-10,-10);
|
@prop public var angularLowerLimit = new Vec3(-10,-10,-10);
|
||||||
@prop public var angularUpperLimit = new Vec3(10,10,10);
|
@prop public var angularUpperLimit = new Vec3(10,10,10);
|
||||||
|
|
||||||
var pickConstraint: bullet.Bt.Generic6DofConstraint = null;
|
var pickConstraint: bullet.Bt.Generic6DofConstraint = null;
|
||||||
var pickDist: Float;
|
|
||||||
var pickedBody: RigidBody = null;
|
|
||||||
|
|
||||||
var rayFrom: bullet.Bt.Vector3;
|
var rayFrom: bullet.Bt.Vector3;
|
||||||
var rayTo: bullet.Bt.Vector3;
|
var rayTo: bullet.Bt.Vector3;
|
||||||
|
#end
|
||||||
|
#if lnx_jolt
|
||||||
|
var pickConstraint:jolt.Jt.TwoBodyConstraint = null;
|
||||||
|
var anchorBody:jolt.Jt.Body = null;
|
||||||
|
var anchorBodyId:jolt.Jt.BodyID = null;
|
||||||
|
var localPivot:Vec4 = null;
|
||||||
|
#end
|
||||||
|
|
||||||
|
var pickDist:Float;
|
||||||
|
var pickedBody:RigidBody = null;
|
||||||
|
|
||||||
static var v = new Vec4();
|
static var v = new Vec4();
|
||||||
static var m = Mat4.identity();
|
static var m = Mat4.identity();
|
||||||
static var first = true;
|
static var first = true;
|
||||||
|
static var start = new Vec4();
|
||||||
|
static var end = new Vec4();
|
||||||
|
#if lnx_jolt
|
||||||
|
static var anchorPos:jolt.Jt.RVec3 = null;
|
||||||
|
static var anchorRot:jolt.Jt.Quat = null;
|
||||||
|
#end
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
super();
|
super();
|
||||||
@ -45,81 +58,135 @@ class PhysicsDrag extends Trait {
|
|||||||
|
|
||||||
var mouse = Input.getMouse();
|
var mouse = Input.getMouse();
|
||||||
if (mouse.started()) {
|
if (mouse.started()) {
|
||||||
|
|
||||||
var b = physics.pickClosest(mouse.x, mouse.y);
|
var b = physics.pickClosest(mouse.x, mouse.y);
|
||||||
if (b != null && b.mass > 0 && !b.body.isKinematicObject() && b.object.getTrait(PhysicsDrag) != null) {
|
if (b != null && b.mass > 0 && isDraggable(b) && b.object.getTrait(PhysicsDrag) != null) {
|
||||||
|
|
||||||
setRays();
|
|
||||||
pickedBody = b;
|
pickedBody = b;
|
||||||
|
|
||||||
m.getInverse(b.object.transform.world);
|
|
||||||
var hit = physics.hitPointWorld;
|
var hit = physics.hitPointWorld;
|
||||||
|
var camera = iron.Scene.active.camera;
|
||||||
|
var camLoc = camera.transform.world.getLoc();
|
||||||
|
pickDist = v.set(hit.x - camLoc.x, hit.y - camLoc.y, hit.z - camLoc.z).length();
|
||||||
|
|
||||||
|
#if lnx_bullet
|
||||||
|
setRays();
|
||||||
|
m.getInverse(b.object.transform.world);
|
||||||
v.setFrom(hit);
|
v.setFrom(hit);
|
||||||
v.applymat4(m);
|
v.applymat4(m);
|
||||||
var localPivot = new bullet.Bt.Vector3(v.x, v.y, v.z);
|
var localPivot = new bullet.Bt.Vector3(v.x, v.y, v.z);
|
||||||
var tr = new bullet.Bt.Transform();
|
var tr = new bullet.Bt.Transform();
|
||||||
tr.setIdentity();
|
tr.setIdentity();
|
||||||
tr.setOrigin(localPivot);
|
tr.setOrigin(localPivot);
|
||||||
|
|
||||||
pickConstraint = new bullet.Bt.Generic6DofConstraint(b.body, tr, false);
|
pickConstraint = new bullet.Bt.Generic6DofConstraint(b.body, tr, false);
|
||||||
pickConstraint.setLinearLowerLimit(new bullet.Bt.Vector3(linearLowerLimit.x, linearLowerLimit.y, linearLowerLimit.z));
|
pickConstraint.setLinearLowerLimit(new bullet.Bt.Vector3(linearLowerLimit.x, linearLowerLimit.y, linearLowerLimit.z));
|
||||||
pickConstraint.setLinearUpperLimit(new bullet.Bt.Vector3(linearUpperLimit.x, linearUpperLimit.y, linearUpperLimit.z));
|
pickConstraint.setLinearUpperLimit(new bullet.Bt.Vector3(linearUpperLimit.x, linearUpperLimit.y, linearUpperLimit.z));
|
||||||
pickConstraint.setAngularLowerLimit(new bullet.Bt.Vector3(angularLowerLimit.x, angularLowerLimit.y, angularLowerLimit.z));
|
pickConstraint.setAngularLowerLimit(new bullet.Bt.Vector3(angularLowerLimit.x, angularLowerLimit.y, angularLowerLimit.z));
|
||||||
pickConstraint.setAngularUpperLimit(new bullet.Bt.Vector3(angularUpperLimit.x, angularUpperLimit.y, angularUpperLimit.z));
|
pickConstraint.setAngularUpperLimit(new bullet.Bt.Vector3(angularUpperLimit.x, angularUpperLimit.y, angularUpperLimit.z));
|
||||||
physics.world.addConstraint(pickConstraint, false);
|
physics.world.addConstraint(pickConstraint, false);
|
||||||
|
#elseif lnx_jolt
|
||||||
|
// Compute local pivot on the body (world hit -> body local)
|
||||||
|
m.getInverse(b.object.transform.world);
|
||||||
|
localPivot = new Vec4();
|
||||||
|
localPivot.setFrom(hit);
|
||||||
|
localPivot.applymat4(m);
|
||||||
|
|
||||||
/*pickConstraint.setParam(4, 0.8, 0);
|
// Create a small kinematic anchor body at the hit point
|
||||||
pickConstraint.setParam(4, 0.8, 1);
|
var aPos = new jolt.Jt.RVec3(hit.x, hit.y, hit.z);
|
||||||
pickConstraint.setParam(4, 0.8, 2);
|
var aRot = new jolt.Jt.Quat(0, 0, 0, 1);
|
||||||
pickConstraint.setParam(4, 0.8, 3);
|
var anchorShape = new jolt.Jt.SphereShape(0.01);
|
||||||
pickConstraint.setParam(4, 0.8, 4);
|
var anchorSettings = new jolt.Jt.BodyCreationSettings(anchorShape, aPos, aRot, jolt.Jt.EMotionType.Kinematic, 0);
|
||||||
pickConstraint.setParam(4, 0.8, 5);
|
anchorSettings.mGravityFactor = 0.0;
|
||||||
|
anchorBody = physics.bodyInterface.CreateBody(anchorSettings);
|
||||||
|
anchorBodyId = anchorBody.GetID();
|
||||||
|
physics.bodyInterface.AddBody(anchorBodyId, jolt.Jt.EActivation.Activate);
|
||||||
|
#if hl anchorSettings.delete(); aPos.delete(); aRot.delete(); #end
|
||||||
|
|
||||||
pickConstraint.setParam(1, 0.1, 0);
|
// Create SixDOFConstraint: translation locked, rotation free
|
||||||
pickConstraint.setParam(1, 0.1, 1);
|
var sixDof = new jolt.Jt.SixDOFConstraintSettings();
|
||||||
pickConstraint.setParam(1, 0.1, 2);
|
sixDof.mSpace = 0; // LocalToBodyCOM
|
||||||
pickConstraint.setParam(1, 0.1, 3);
|
var p1 = new jolt.Jt.RVec3(localPivot.x, localPivot.y, localPivot.z);
|
||||||
pickConstraint.setParam(1, 0.1, 4);
|
var p2 = new jolt.Jt.RVec3(0, 0, 0);
|
||||||
pickConstraint.setParam(1, 0.1, 5);*/
|
var ax1 = new jolt.Jt.Vec3(1, 0, 0);
|
||||||
|
var ay1 = new jolt.Jt.Vec3(0, 1, 0);
|
||||||
pickDist = v.set(hit.x - rayFrom.x(), hit.y - rayFrom.y(), hit.z - rayFrom.z()).length();
|
var ax2 = new jolt.Jt.Vec3(1, 0, 0);
|
||||||
|
var ay2 = new jolt.Jt.Vec3(0, 1, 0);
|
||||||
|
sixDof.mPosition1 = p1;
|
||||||
|
sixDof.mPosition2 = p2;
|
||||||
|
sixDof.mAxisX1 = ax1;
|
||||||
|
sixDof.mAxisY1 = ay1;
|
||||||
|
sixDof.mAxisX2 = ax2;
|
||||||
|
sixDof.mAxisY2 = ay2;
|
||||||
|
sixDof.MakeFixedAxis(0);
|
||||||
|
sixDof.MakeFixedAxis(1);
|
||||||
|
sixDof.MakeFixedAxis(2);
|
||||||
|
sixDof.MakeFreeAxis(3);
|
||||||
|
sixDof.MakeFreeAxis(4);
|
||||||
|
sixDof.MakeFreeAxis(5);
|
||||||
|
pickConstraint = sixDof.Create(b.body, anchorBody);
|
||||||
|
physics.physicsSystem.AddConstraint(pickConstraint);
|
||||||
|
#if hl sixDof.delete(); p1.delete(); p2.delete(); ax1.delete(); ay1.delete(); ax2.delete(); ay2.delete(); #end
|
||||||
|
#end
|
||||||
|
|
||||||
Input.occupied = true;
|
Input.occupied = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (mouse.released()) {
|
else if (mouse.released()) {
|
||||||
|
#if lnx_bullet
|
||||||
if (pickConstraint != null) {
|
if (pickConstraint != null) {
|
||||||
physics.world.removeConstraint(pickConstraint);
|
physics.world.removeConstraint(pickConstraint);
|
||||||
pickConstraint = null;
|
pickConstraint = null;
|
||||||
pickedBody = null;
|
|
||||||
}
|
}
|
||||||
|
#elseif lnx_jolt
|
||||||
|
if (pickConstraint != null) {
|
||||||
|
physics.physicsSystem.RemoveConstraint(pickConstraint);
|
||||||
|
pickConstraint = null;
|
||||||
|
}
|
||||||
|
if (anchorBodyId != null) {
|
||||||
|
physics.bodyInterface.RemoveBody(anchorBodyId);
|
||||||
|
physics.bodyInterface.DestroyBody(anchorBodyId);
|
||||||
|
anchorBodyId = null;
|
||||||
|
anchorBody = null;
|
||||||
|
}
|
||||||
|
localPivot = null;
|
||||||
|
#end
|
||||||
|
pickedBody = null;
|
||||||
Input.occupied = false;
|
Input.occupied = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (mouse.down()) {
|
else if (mouse.down()) {
|
||||||
if (pickConstraint != null) {
|
if (pickedBody != null) {
|
||||||
setRays();
|
#if lnx_bullet
|
||||||
|
if (pickConstraint != null) {
|
||||||
// Keep it at the same picking distance
|
setRays();
|
||||||
var dir = new bullet.Bt.Vector3(rayTo.x() - rayFrom.x(), rayTo.y() - rayFrom.y(), rayTo.z() - rayFrom.z());
|
var dir = new bullet.Bt.Vector3(rayTo.x() - rayFrom.x(), rayTo.y() - rayFrom.y(), rayTo.z() - rayFrom.z());
|
||||||
dir.normalize();
|
dir.normalize();
|
||||||
dir.setX(dir.x() * pickDist);
|
dir.setX(dir.x() * pickDist);
|
||||||
dir.setY(dir.y() * pickDist);
|
dir.setY(dir.y() * pickDist);
|
||||||
dir.setZ(dir.z() * pickDist);
|
dir.setZ(dir.z() * pickDist);
|
||||||
var newPivotB = new bullet.Bt.Vector3(rayFrom.x() + dir.x(), rayFrom.y() + dir.y(), rayFrom.z() + dir.z());
|
var newPivotB = new bullet.Bt.Vector3(rayFrom.x() + dir.x(), rayFrom.y() + dir.y(), rayFrom.z() + dir.z());
|
||||||
|
#if (js || hl)
|
||||||
#if (js || hl)
|
pickConstraint.getFrameOffsetA().setOrigin(newPivotB);
|
||||||
pickConstraint.getFrameOffsetA().setOrigin(newPivotB);
|
#elseif cpp
|
||||||
#elseif cpp
|
pickConstraint.setFrameOffsetAOrigin(newPivotB);
|
||||||
pickConstraint.setFrameOffsetAOrigin(newPivotB);
|
#end
|
||||||
|
}
|
||||||
|
#elseif lnx_jolt
|
||||||
|
if (pickConstraint != null) {
|
||||||
|
setAnchorTarget(physics);
|
||||||
|
}
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static var start = new Vec4();
|
inline function isDraggable(b:RigidBody):Bool {
|
||||||
static var end = new Vec4();
|
#if lnx_bullet
|
||||||
|
return !b.body.isKinematicObject();
|
||||||
|
#elseif lnx_jolt
|
||||||
|
return !b.staticObj && !b.animated;
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
|
||||||
|
#if lnx_bullet
|
||||||
inline function setRays() {
|
inline function setRays() {
|
||||||
var mouse = Input.getMouse();
|
var mouse = Input.getMouse();
|
||||||
var camera = iron.Scene.active.camera;
|
var camera = iron.Scene.active.camera;
|
||||||
@ -128,5 +195,37 @@ class PhysicsDrag extends Trait {
|
|||||||
RayCaster.getDirection(start, end, mouse.x, mouse.y, camera);
|
RayCaster.getDirection(start, end, mouse.x, mouse.y, camera);
|
||||||
rayTo = new bullet.Bt.Vector3(end.x, end.y, end.z);
|
rayTo = new bullet.Bt.Vector3(end.x, end.y, end.z);
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
|
#if lnx_jolt
|
||||||
|
inline function setAnchorTarget(physics:PhysicsWorld) {
|
||||||
|
var mouse = Input.getMouse();
|
||||||
|
var camera = iron.Scene.active.camera;
|
||||||
|
var camLoc = camera.transform.world.getLoc();
|
||||||
|
RayCaster.getDirection(start, end, mouse.x, mouse.y, camera);
|
||||||
|
var dirX = end.x - camLoc.x;
|
||||||
|
var dirY = end.y - camLoc.y;
|
||||||
|
var dirZ = end.z - camLoc.z;
|
||||||
|
var len = Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
|
||||||
|
if (len > 0) { dirX /= len; dirY /= len; dirZ /= len; }
|
||||||
|
var targetX = camLoc.x + dirX * pickDist;
|
||||||
|
var targetY = camLoc.y + dirY * pickDist;
|
||||||
|
var targetZ = camLoc.z + dirZ * pickDist;
|
||||||
|
|
||||||
|
var t = iron.system.Time.fixedStep;
|
||||||
|
#if hl
|
||||||
|
RigidBody.hlPos.Set(targetX, targetY, targetZ);
|
||||||
|
physics.bodyInterface.MoveKinematic(anchorBodyId, RigidBody.hlPos, RigidBody.hlRot, t);
|
||||||
|
#else
|
||||||
|
if (anchorPos == null) {
|
||||||
|
anchorPos = new jolt.Jt.RVec3(0, 0, 0);
|
||||||
|
anchorRot = new jolt.Jt.Quat(0, 0, 0, 1);
|
||||||
|
}
|
||||||
|
anchorPos.Set(targetX, targetY, targetZ);
|
||||||
|
physics.bodyInterface.MoveKinematic(anchorBodyId, anchorPos, anchorRot, t);
|
||||||
|
#end
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,12 +7,17 @@ import iron.object.Transform;
|
|||||||
import iron.system.Time;
|
import iron.system.Time;
|
||||||
import leenkx.trait.physics.PhysicsWorld;
|
import leenkx.trait.physics.PhysicsWorld;
|
||||||
|
|
||||||
class VehicleBody extends Trait {
|
#if (!lnx_physics)
|
||||||
|
|
||||||
|
class VehicleBody extends Trait { public function new() { super(); } }
|
||||||
|
class VehicleWheel { public function new() {} }
|
||||||
|
|
||||||
#if (!lnx_bullet)
|
|
||||||
public function new() { super(); }
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
#if lnx_bullet
|
||||||
|
|
||||||
|
class VehicleBody extends Trait {
|
||||||
|
|
||||||
@prop var wheel0Name: String = "Wheel0";
|
@prop var wheel0Name: String = "Wheel0";
|
||||||
@prop var wheel1Name: String = "Wheel1";
|
@prop var wheel1Name: String = "Wheel1";
|
||||||
@prop var wheel2Name: String = "Wheel2";
|
@prop var wheel2Name: String = "Wheel2";
|
||||||
@ -232,34 +237,44 @@ class VehicleBody extends Trait {
|
|||||||
static inline var keyStrafeUp = "e";
|
static inline var keyStrafeUp = "e";
|
||||||
static inline var keyStrafeDown = "q";
|
static inline var keyStrafeDown = "q";
|
||||||
#end
|
#end
|
||||||
#end
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class VehicleWheel {
|
class VehicleWheel {
|
||||||
|
|
||||||
#if (!lnx_bullet)
|
public var isFrontWheel: Bool;
|
||||||
public function new() {}
|
public var wheelRadius: Float;
|
||||||
#else
|
public var wheelWidth: Float;
|
||||||
|
|
||||||
public var isFrontWheel: Bool;
|
var locX: Float;
|
||||||
public var wheelRadius: Float;
|
var locY: Float;
|
||||||
public var wheelWidth: Float;
|
var locZ: Float;
|
||||||
|
|
||||||
var locX: Float;
|
public function new(id: Int, transform: Transform, vehicleTransform: Transform) {
|
||||||
var locY: Float;
|
wheelRadius = transform.dim.z / 2;
|
||||||
var locZ: Float;
|
wheelWidth = transform.dim.x > transform.dim.y ? transform.dim.y : transform.dim.x;
|
||||||
|
|
||||||
public function new(id: Int, transform: Transform, vehicleTransform: Transform) {
|
locX = transform.loc.x;
|
||||||
wheelRadius = transform.dim.z / 2;
|
locY = transform.loc.y;
|
||||||
wheelWidth = transform.dim.x > transform.dim.y ? transform.dim.y : transform.dim.x;
|
locZ = vehicleTransform.dim.z / 2 + transform.loc.z;
|
||||||
|
}
|
||||||
|
|
||||||
locX = transform.loc.x;
|
public function getConnectionPoint(): bullet.Bt.Vector3 {
|
||||||
locY = transform.loc.y;
|
return new bullet.Bt.Vector3(locX, locY, locZ);
|
||||||
locZ = vehicleTransform.dim.z / 2 + transform.loc.z;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConnectionPoint(): bullet.Bt.Vector3 {
|
#end
|
||||||
return new bullet.Bt.Vector3(locX, locY, locZ);
|
|
||||||
}
|
#elseif lnx_jolt
|
||||||
|
|
||||||
|
typedef VehicleBody = leenkx.trait.physics.jolt.VehicleBody;
|
||||||
|
typedef VehicleWheel = leenkx.trait.physics.jolt.VehicleWheel;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
class VehicleBody extends Trait { public function new() { super(); } }
|
||||||
|
class VehicleWheel { public function new() {} }
|
||||||
|
|
||||||
|
#end
|
||||||
|
|
||||||
#end
|
#end
|
||||||
}
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import iron.math.Quat;
|
|||||||
import iron.math.Mat4;
|
import iron.math.Mat4;
|
||||||
import iron.object.Object;
|
import iron.object.Object;
|
||||||
|
|
||||||
@:enum abstract ConstraintType(Int) from Int to Int {
|
enum abstract ConstraintType(Int) from Int to Int {
|
||||||
var Fixed = 0;
|
var Fixed = 0;
|
||||||
var Point = 1;
|
var Point = 1;
|
||||||
var Hinge = 2;
|
var Hinge = 2;
|
||||||
@ -396,7 +396,7 @@ class PhysicsConstraint extends Trait {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@:enum abstract ConstraintAxis(Int) from Int to Int {
|
enum abstract ConstraintAxis(Int) from Int to Int {
|
||||||
var X = 0;
|
var X = 0;
|
||||||
var Y = 1;
|
var Y = 1;
|
||||||
var Z = 2;
|
var Z = 2;
|
||||||
|
|||||||
@ -59,6 +59,7 @@ class PhysicsWorld extends Trait {
|
|||||||
var contacts:Array<ContactPair>;
|
var contacts:Array<ContactPair>;
|
||||||
var preUpdates:Array<Void->Void> = null;
|
var preUpdates:Array<Void->Void> = null;
|
||||||
public var rbMap:Map<Int, RigidBody>;
|
public var rbMap:Map<Int, RigidBody>;
|
||||||
|
public var bodyIdMap:Map<Int, RigidBody>;
|
||||||
public var conMap:Map<Int, PhysicsConstraint>;
|
public var conMap:Map<Int, PhysicsConstraint>;
|
||||||
public var constraints:Array<PhysicsConstraint> = [];
|
public var constraints:Array<PhysicsConstraint> = [];
|
||||||
public var timeScale = 1.0;
|
public var timeScale = 1.0;
|
||||||
@ -77,6 +78,21 @@ class PhysicsWorld extends Trait {
|
|||||||
static var vec2:jolt.Jt.Vec3 = null;
|
static var vec2:jolt.Jt.Vec3 = null;
|
||||||
static var quat1:jolt.Jt.Quat = null;
|
static var quat1:jolt.Jt.Quat = null;
|
||||||
|
|
||||||
|
// Cached raycast objects
|
||||||
|
static var rayOrigin:jolt.Jt.RVec3 = null;
|
||||||
|
static var rayDir:jolt.Jt.Vec3 = null;
|
||||||
|
static var cachedRay:jolt.Jt.RRayCast = null;
|
||||||
|
static var rayResult:jolt.Jt.RayCastResult = null;
|
||||||
|
static var raySettings:jolt.Jt.RayCastSettings = null;
|
||||||
|
#if js
|
||||||
|
static var rayCollector:jolt.Jt.CastRayClosestHitCollisionCollector = null;
|
||||||
|
#end
|
||||||
|
static var bpFilter:jolt.Jt.BroadPhaseLayerFilter = null;
|
||||||
|
static var objFilter:jolt.Jt.ObjectLayerFilter = null;
|
||||||
|
static var bodyFilter:jolt.Jt.BodyFilter = null;
|
||||||
|
static var shapeFilter:jolt.Jt.ShapeFilter = null;
|
||||||
|
static var narrowPhaseQuery:jolt.Jt.NarrowPhaseQuery = null;
|
||||||
|
|
||||||
#if js
|
#if js
|
||||||
var joltInterface:jolt.Jt.JoltInterface;
|
var joltInterface:jolt.Jt.JoltInterface;
|
||||||
static var joltReady = false;
|
static var joltReady = false;
|
||||||
@ -110,6 +126,7 @@ class PhysicsWorld extends Trait {
|
|||||||
|
|
||||||
contacts = [];
|
contacts = [];
|
||||||
rbMap = new Map();
|
rbMap = new Map();
|
||||||
|
bodyIdMap = new Map();
|
||||||
conMap = new Map();
|
conMap = new Map();
|
||||||
active = this;
|
active = this;
|
||||||
|
|
||||||
@ -157,6 +174,7 @@ class PhysicsWorld extends Trait {
|
|||||||
#if hl
|
#if hl
|
||||||
// Must initialize Jolt allocator before ANY Jolt object creation
|
// Must initialize Jolt allocator before ANY Jolt object creation
|
||||||
hlJoltInit();
|
hlJoltInit();
|
||||||
|
RigidBody.hlInitVars();
|
||||||
#end
|
#end
|
||||||
|
|
||||||
if (nullvec) {
|
if (nullvec) {
|
||||||
@ -164,6 +182,21 @@ class PhysicsWorld extends Trait {
|
|||||||
vec1 = new jolt.Jt.Vec3(0, 0, 0);
|
vec1 = new jolt.Jt.Vec3(0, 0, 0);
|
||||||
vec2 = new jolt.Jt.Vec3(0, 0, 0);
|
vec2 = new jolt.Jt.Vec3(0, 0, 0);
|
||||||
quat1 = new jolt.Jt.Quat(0, 0, 0, 1);
|
quat1 = new jolt.Jt.Quat(0, 0, 0, 1);
|
||||||
|
rayOrigin = new jolt.Jt.RVec3(0, 0, 0);
|
||||||
|
rayDir = new jolt.Jt.Vec3(0, 0, 0);
|
||||||
|
cachedRay = new jolt.Jt.RRayCast(rayOrigin, rayDir);
|
||||||
|
rayResult = new jolt.Jt.RayCastResult();
|
||||||
|
raySettings = new jolt.Jt.RayCastSettings();
|
||||||
|
#if js
|
||||||
|
rayCollector = new jolt.Jt.CastRayClosestHitCollisionCollector();
|
||||||
|
#end
|
||||||
|
bpFilter = new jolt.Jt.BroadPhaseLayerFilter();
|
||||||
|
#if hl
|
||||||
|
objFilter = new jolt.Jt.ObjectLayerFilter();
|
||||||
|
#end
|
||||||
|
bodyFilter = new jolt.Jt.BodyFilter();
|
||||||
|
shapeFilter = new jolt.Jt.ShapeFilter();
|
||||||
|
narrowPhaseQuery = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!physicsReady) {
|
if (!physicsReady) {
|
||||||
@ -220,6 +253,10 @@ class PhysicsWorld extends Trait {
|
|||||||
joltInterface = new jolt.Jt.JoltInterface(settings);
|
joltInterface = new jolt.Jt.JoltInterface(settings);
|
||||||
physicsSystem = joltInterface.GetPhysicsSystem();
|
physicsSystem = joltInterface.GetPhysicsSystem();
|
||||||
bodyInterface = physicsSystem.GetBodyInterface();
|
bodyInterface = physicsSystem.GetBodyInterface();
|
||||||
|
|
||||||
|
if (objFilter == null) {
|
||||||
|
objFilter = new jolt.Jt.DefaultObjectLayerFilter(objectLayerPair, 0);
|
||||||
|
}
|
||||||
#end
|
#end
|
||||||
|
|
||||||
physicsReady = true;
|
physicsReady = true;
|
||||||
@ -243,8 +280,9 @@ class PhysicsWorld extends Trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function addRigidBody(body:RigidBody, activate:Bool = true) {
|
public function addRigidBody(body:RigidBody, activate:Bool = true) {
|
||||||
bodyInterface.AddBody(body.bodyId, activate ? 1 : 0);
|
bodyInterface.AddBody(body.bodyId, activate ? 0 : 1);
|
||||||
rbMap.set(body.id, body);
|
rbMap.set(body.id, body);
|
||||||
|
bodyIdMap.set(body.bodyId.GetIndex(), body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addPhysicsConstraint(constraint:PhysicsConstraint) {
|
public function addPhysicsConstraint(constraint:PhysicsConstraint) {
|
||||||
@ -262,6 +300,7 @@ class PhysicsWorld extends Trait {
|
|||||||
bodyInterface.RemoveBody(body.bodyId);
|
bodyInterface.RemoveBody(body.bodyId);
|
||||||
bodyInterface.DestroyBody(body.bodyId);
|
bodyInterface.DestroyBody(body.bodyId);
|
||||||
rbMap.remove(body.id);
|
rbMap.remove(body.id);
|
||||||
|
bodyIdMap.remove(body.bodyId.GetIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removePhysicsConstraint(constraint:PhysicsConstraint) {
|
public function removePhysicsConstraint(constraint:PhysicsConstraint) {
|
||||||
@ -354,41 +393,39 @@ class PhysicsWorld extends Trait {
|
|||||||
var dirY = to.y - from.y;
|
var dirY = to.y - from.y;
|
||||||
var dirZ = to.z - from.z;
|
var dirZ = to.z - from.z;
|
||||||
|
|
||||||
var origin = new jolt.Jt.RVec3(from.x, from.y, from.z);
|
// reuse cached objects
|
||||||
var direction = new jolt.Jt.Vec3(dirX, dirY, dirZ);
|
rayOrigin.Set(from.x, from.y, from.z);
|
||||||
var ray = new jolt.Jt.RRayCast(origin, direction);
|
rayDir.Set(dirX, dirY, dirZ);
|
||||||
var result = new jolt.Jt.RayCastResult();
|
cachedRay.mOrigin = rayOrigin;
|
||||||
|
cachedRay.mDirection = rayDir;
|
||||||
var narrowPhase = physicsSystem.GetNarrowPhaseQuery();
|
|
||||||
var didHit = narrowPhase.CastRay(ray, result);
|
|
||||||
|
|
||||||
|
if (narrowPhaseQuery == null){
|
||||||
|
narrowPhaseQuery = physicsSystem.GetNarrowPhaseQuery();
|
||||||
|
}
|
||||||
|
rayResult.mFraction = 1.0;
|
||||||
|
#if hl
|
||||||
|
var didHit = narrowPhaseQuery.CastRay(cachedRay, rayResult, raySettings, bpFilter, objFilter, bodyFilter, shapeFilter);
|
||||||
|
#else
|
||||||
|
rayCollector.Reset();
|
||||||
|
narrowPhaseQuery.CastRay(cachedRay, raySettings, rayCollector, bpFilter, objFilter, bodyFilter, shapeFilter);
|
||||||
|
var didHit = rayCollector.HadHit();
|
||||||
if (didHit) {
|
if (didHit) {
|
||||||
var bodyId = result.mBodyID;
|
var hit = rayCollector.mHit;
|
||||||
var fraction = result.mFraction;
|
rayResult.mBodyID = hit.mBodyID;
|
||||||
|
rayResult.mFraction = hit.mFraction;
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
var fraction = rayResult.mFraction;
|
||||||
|
|
||||||
|
if (didHit && fraction < 1.0) {
|
||||||
|
var bodyId = rayResult.mBodyID;
|
||||||
hitPointWorld.set(from.x + dirX * fraction, from.y + dirY * fraction, from.z + dirZ * fraction);
|
hitPointWorld.set(from.x + dirX * fraction, from.y + dirY * fraction, from.z + dirZ * fraction);
|
||||||
|
var rb = bodyIdMap.get(bodyId.GetIndex());
|
||||||
// Find rigid body by ID
|
if (rb != null) {
|
||||||
for (rb in rbMap) {
|
return new Hit(rb, hitPointWorld.clone(), hitNormalWorld.clone());
|
||||||
if (rb.bodyId.GetIndex() == bodyId.GetIndex()) {
|
|
||||||
#if hl
|
|
||||||
origin.delete();
|
|
||||||
direction.delete();
|
|
||||||
ray.delete();
|
|
||||||
result.delete();
|
|
||||||
#end
|
|
||||||
return new Hit(rb, hitPointWorld.clone(), hitNormalWorld.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if hl
|
|
||||||
origin.delete();
|
|
||||||
direction.delete();
|
|
||||||
ray.delete();
|
|
||||||
result.delete();
|
|
||||||
#end
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import iron.data.SceneFormat;
|
|||||||
import iron.object.Transform;
|
import iron.object.Transform;
|
||||||
import iron.object.MeshObject;
|
import iron.object.MeshObject;
|
||||||
|
|
||||||
@:enum abstract Shape(Int) from Int to Int {
|
enum abstract Shape(Int) from Int to Int {
|
||||||
var Box = 0;
|
var Box = 0;
|
||||||
var Sphere = 1;
|
var Sphere = 1;
|
||||||
var ConvexHull = 2;
|
var ConvexHull = 2;
|
||||||
@ -410,14 +410,14 @@ class RigidBody extends Trait {
|
|||||||
var scalePos = mo.data.scalePos;
|
var scalePos = mo.data.scalePos;
|
||||||
var numVerts = Std.int(positions.length / 4);
|
var numVerts = Std.int(positions.length / 4);
|
||||||
|
|
||||||
var settings:Dynamic = untyped __js__("new Jolt.ConvexHullShapeSettings()");
|
var settings:Dynamic = new jolt.Jt.ConvexHullShapeSettings();
|
||||||
var points:Dynamic = untyped settings.mPoints;
|
var points:Dynamic = untyped settings.mPoints;
|
||||||
points.clear();
|
points.clear();
|
||||||
for (i in 0...numVerts) {
|
for (i in 0...numVerts) {
|
||||||
var x:Float = (positions[i * 4] / 32767) * scalePos * scale.x;
|
var x:Float = (positions[i * 4] / 32767) * scalePos * scale.x;
|
||||||
var y:Float = (positions[i * 4 + 1] / 32767) * scalePos * scale.y;
|
var y:Float = (positions[i * 4 + 1] / 32767) * scalePos * scale.y;
|
||||||
var z:Float = (positions[i * 4 + 2] / 32767) * scalePos * scale.z;
|
var z:Float = (positions[i * 4 + 2] / 32767) * scalePos * scale.z;
|
||||||
var pt:Dynamic = untyped __js__("new Jolt.Vec3({0}, {1}, {2})", x, y, z);
|
var pt:Dynamic = new jolt.Jt.Vec3(x, y, z);
|
||||||
untyped points.push_back(pt);
|
untyped points.push_back(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ class RigidBody extends Trait {
|
|||||||
var scalePos = mo.data.scalePos;
|
var scalePos = mo.data.scalePos;
|
||||||
var numVerts = Std.int(positions.length / 4);
|
var numVerts = Std.int(positions.length / 4);
|
||||||
|
|
||||||
var settings:Dynamic = untyped __js__("new Jolt.MeshShapeSettings()");
|
var settings:Dynamic = new jolt.Jt.MeshShapeSettings();
|
||||||
var verts:Dynamic = untyped settings.mTriangleVertices;
|
var verts:Dynamic = untyped settings.mTriangleVertices;
|
||||||
var tris:Dynamic = untyped settings.mIndexedTriangles;
|
var tris:Dynamic = untyped settings.mIndexedTriangles;
|
||||||
verts.clear();
|
verts.clear();
|
||||||
@ -449,14 +449,14 @@ class RigidBody extends Trait {
|
|||||||
var x:Float = (positions[i * 4] / 32767) * scalePos * scale.x;
|
var x:Float = (positions[i * 4] / 32767) * scalePos * scale.x;
|
||||||
var y:Float = (positions[i * 4 + 1] / 32767) * scalePos * scale.y;
|
var y:Float = (positions[i * 4 + 1] / 32767) * scalePos * scale.y;
|
||||||
var z:Float = (positions[i * 4 + 2] / 32767) * scalePos * scale.z;
|
var z:Float = (positions[i * 4 + 2] / 32767) * scalePos * scale.z;
|
||||||
var v:Dynamic = untyped __js__("new Jolt.Float3({0}, {1}, {2})", x, y, z);
|
var v:Dynamic = new jolt.Jt.Float3(x, y, z);
|
||||||
untyped verts.push_back(v);
|
untyped verts.push_back(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (indexArray in indices) {
|
for (indexArray in indices) {
|
||||||
var numTris = Std.int(indexArray.length / 3);
|
var numTris = Std.int(indexArray.length / 3);
|
||||||
for (i in 0...numTris) {
|
for (i in 0...numTris) {
|
||||||
var tri:Dynamic = untyped __js__("new Jolt.IndexedTriangle()");
|
var tri:Dynamic = new jolt.Jt.IndexedTriangle();
|
||||||
untyped tri.set_mIdx(0, indexArray[i * 3]);
|
untyped tri.set_mIdx(0, indexArray[i * 3]);
|
||||||
untyped tri.set_mIdx(1, indexArray[i * 3 + 1]);
|
untyped tri.set_mIdx(1, indexArray[i * 3 + 1]);
|
||||||
untyped tri.set_mIdx(2, indexArray[i * 3 + 2]);
|
untyped tri.set_mIdx(2, indexArray[i * 3 + 2]);
|
||||||
@ -482,6 +482,25 @@ class RigidBody extends Trait {
|
|||||||
var currentRotZ:Float = 0;
|
var currentRotZ:Float = 0;
|
||||||
var currentRotW:Float = 1;
|
var currentRotW:Float = 1;
|
||||||
|
|
||||||
|
#if hl
|
||||||
|
public static var hlPos:jolt.Jt.RVec3 = null;
|
||||||
|
public static var hlRot:jolt.Jt.Quat = null;
|
||||||
|
public static var hlVel:jolt.Jt.Vec3 = null;
|
||||||
|
public static var hlForce:jolt.Jt.Vec3 = null;
|
||||||
|
public static var hlPosR:jolt.Jt.RVec3 = null;
|
||||||
|
public static var hlQuat:jolt.Jt.Quat = null;
|
||||||
|
|
||||||
|
public static function hlInitVars() {
|
||||||
|
if (hlPos != null) return;
|
||||||
|
hlPos = new jolt.Jt.RVec3(0, 0, 0);
|
||||||
|
hlRot = new jolt.Jt.Quat(0, 0, 0, 1);
|
||||||
|
hlVel = new jolt.Jt.Vec3(0, 0, 0);
|
||||||
|
hlForce = new jolt.Jt.Vec3(0, 0, 0);
|
||||||
|
hlPosR = new jolt.Jt.RVec3(0, 0, 0);
|
||||||
|
hlQuat = new jolt.Jt.Quat(0, 0, 0, 1);
|
||||||
|
}
|
||||||
|
#end
|
||||||
|
|
||||||
public function physicsUpdate() {
|
public function physicsUpdate() {
|
||||||
if (!ready)
|
if (!ready)
|
||||||
return;
|
return;
|
||||||
@ -494,18 +513,26 @@ class RigidBody extends Trait {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var active = physics.bodyInterface.IsActive(bodyId);
|
#if hl
|
||||||
if (!active) {
|
if (!body.IsActive())
|
||||||
// Activate body if sleeping
|
|
||||||
physics.bodyInterface.ActivateBody(bodyId);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Read position and rotation from Jolt into cached state
|
body.GetPositionInto(hlPos);
|
||||||
|
body.GetRotationInto(hlRot);
|
||||||
|
currentPosX = hlPos.GetX();
|
||||||
|
currentPosY = hlPos.GetY();
|
||||||
|
currentPosZ = hlPos.GetZ();
|
||||||
|
currentRotX = hlRot.GetX();
|
||||||
|
currentRotY = hlRot.GetY();
|
||||||
|
currentRotZ = hlRot.GetZ();
|
||||||
|
currentRotW = hlRot.GetW();
|
||||||
|
#else
|
||||||
|
// JS/WASM: re-activate sleeping bodies (Jolt deactivates even with mAllowSleeping=false in WASM)
|
||||||
|
if (!physics.bodyInterface.IsActive(bodyId))
|
||||||
|
physics.bodyInterface.ActivateBody(bodyId);
|
||||||
|
|
||||||
var p = physics.bodyInterface.GetPosition(bodyId);
|
var p = physics.bodyInterface.GetPosition(bodyId);
|
||||||
var q = physics.bodyInterface.GetRotation(bodyId);
|
var q = physics.bodyInterface.GetRotation(bodyId);
|
||||||
|
|
||||||
#if js
|
|
||||||
currentPosX = cast p.GetX();
|
currentPosX = cast p.GetX();
|
||||||
currentPosY = cast p.GetY();
|
currentPosY = cast p.GetY();
|
||||||
currentPosZ = cast p.GetZ();
|
currentPosZ = cast p.GetZ();
|
||||||
@ -513,17 +540,6 @@ class RigidBody extends Trait {
|
|||||||
currentRotY = cast q.GetY();
|
currentRotY = cast q.GetY();
|
||||||
currentRotZ = cast q.GetZ();
|
currentRotZ = cast q.GetZ();
|
||||||
currentRotW = cast q.GetW();
|
currentRotW = cast q.GetW();
|
||||||
// JS: getter return values use internal WASM wrappers - do NOT destroy
|
|
||||||
#else
|
|
||||||
currentPosX = p.GetX();
|
|
||||||
currentPosY = p.GetY();
|
|
||||||
currentPosZ = p.GetZ();
|
|
||||||
currentRotX = q.GetX();
|
|
||||||
currentRotY = q.GetY();
|
|
||||||
currentRotZ = q.GetZ();
|
|
||||||
currentRotW = q.GetW();
|
|
||||||
p.delete();
|
|
||||||
q.delete();
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,50 +570,78 @@ class RigidBody extends Trait {
|
|||||||
// Physics methods
|
// Physics methods
|
||||||
public function applyForce(force:Vec4, ?loc:Vec4) {
|
public function applyForce(force:Vec4, ?loc:Vec4) {
|
||||||
activate();
|
activate();
|
||||||
|
#if hl
|
||||||
|
hlForce.Set(force.x, force.y, force.z);
|
||||||
|
if (loc == null) {
|
||||||
|
physics.bodyInterface.AddForce(bodyId, hlForce);
|
||||||
|
} else {
|
||||||
|
hlPosR.Set(loc.x, loc.y, loc.z);
|
||||||
|
physics.bodyInterface.AddForceAtPosition(bodyId, hlForce, hlPosR);
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
var f = new jolt.Jt.Vec3(force.x, force.y, force.z);
|
var f = new jolt.Jt.Vec3(force.x, force.y, force.z);
|
||||||
physics.bodyInterface.AddForce(bodyId, f);
|
physics.bodyInterface.AddForce(bodyId, f);
|
||||||
#if hl f.delete(); #end
|
|
||||||
} else {
|
} else {
|
||||||
var f = new jolt.Jt.Vec3(force.x, force.y, force.z);
|
var f = new jolt.Jt.Vec3(force.x, force.y, force.z);
|
||||||
var l = new jolt.Jt.RVec3(loc.x, loc.y, loc.z);
|
var l = new jolt.Jt.RVec3(loc.x, loc.y, loc.z);
|
||||||
physics.bodyInterface.AddForceAtPosition(bodyId, f, l);
|
physics.bodyInterface.AddForceAtPosition(bodyId, f, l);
|
||||||
#if hl f.delete(); l.delete(); #end
|
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyImpulse(impulse:Vec4, ?loc:Vec4) {
|
public function applyImpulse(impulse:Vec4, ?loc:Vec4) {
|
||||||
activate();
|
activate();
|
||||||
|
#if hl
|
||||||
|
hlForce.Set(impulse.x, impulse.y, impulse.z);
|
||||||
|
if (loc == null) {
|
||||||
|
physics.bodyInterface.AddImpulse(bodyId, hlForce);
|
||||||
|
} else {
|
||||||
|
hlPosR.Set(loc.x, loc.y, loc.z);
|
||||||
|
physics.bodyInterface.AddImpulseAtPosition(bodyId, hlForce, hlPosR);
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
var i = new jolt.Jt.Vec3(impulse.x, impulse.y, impulse.z);
|
var i = new jolt.Jt.Vec3(impulse.x, impulse.y, impulse.z);
|
||||||
physics.bodyInterface.AddImpulse(bodyId, i);
|
physics.bodyInterface.AddImpulse(bodyId, i);
|
||||||
#if hl i.delete(); #end
|
|
||||||
} else {
|
} else {
|
||||||
var i = new jolt.Jt.Vec3(impulse.x, impulse.y, impulse.z);
|
var i = new jolt.Jt.Vec3(impulse.x, impulse.y, impulse.z);
|
||||||
var l = new jolt.Jt.RVec3(loc.x, loc.y, loc.z);
|
var l = new jolt.Jt.RVec3(loc.x, loc.y, loc.z);
|
||||||
physics.bodyInterface.AddImpulseAtPosition(bodyId, i, l);
|
physics.bodyInterface.AddImpulseAtPosition(bodyId, i, l);
|
||||||
#if hl i.delete(); l.delete(); #end
|
|
||||||
}
|
}
|
||||||
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyTorque(torque:Vec4) {
|
public function applyTorque(torque:Vec4) {
|
||||||
activate();
|
activate();
|
||||||
|
#if hl
|
||||||
|
hlForce.Set(torque.x, torque.y, torque.z);
|
||||||
|
physics.bodyInterface.AddTorque(bodyId, hlForce);
|
||||||
|
#else
|
||||||
var t = new jolt.Jt.Vec3(torque.x, torque.y, torque.z);
|
var t = new jolt.Jt.Vec3(torque.x, torque.y, torque.z);
|
||||||
physics.bodyInterface.AddTorque(bodyId, t);
|
physics.bodyInterface.AddTorque(bodyId, t);
|
||||||
#if hl t.delete(); #end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyTorqueImpulse(impulse:Vec4) {
|
public function applyTorqueImpulse(impulse:Vec4) {
|
||||||
activate();
|
activate();
|
||||||
|
#if hl
|
||||||
|
hlForce.Set(impulse.x, impulse.y, impulse.z);
|
||||||
|
physics.bodyInterface.AddAngularImpulse(bodyId, hlForce);
|
||||||
|
#else
|
||||||
var i = new jolt.Jt.Vec3(impulse.x, impulse.y, impulse.z);
|
var i = new jolt.Jt.Vec3(impulse.x, impulse.y, impulse.z);
|
||||||
physics.bodyInterface.AddAngularImpulse(bodyId, i);
|
physics.bodyInterface.AddAngularImpulse(bodyId, i);
|
||||||
#if hl i.delete(); #end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setLinearVelocity(v:Vec4) {
|
public function setLinearVelocity(v:Vec4) {
|
||||||
|
#if hl
|
||||||
|
hlVel.Set(v.x, v.y, v.z);
|
||||||
|
physics.bodyInterface.SetLinearVelocity(bodyId, hlVel);
|
||||||
|
#else
|
||||||
var vel = new jolt.Jt.Vec3(v.x, v.y, v.z);
|
var vel = new jolt.Jt.Vec3(v.x, v.y, v.z);
|
||||||
physics.bodyInterface.SetLinearVelocity(bodyId, vel);
|
physics.bodyInterface.SetLinearVelocity(bodyId, vel);
|
||||||
#if hl vel.delete(); #end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLinearVelocity():Vec4 {
|
public function getLinearVelocity():Vec4 {
|
||||||
@ -608,9 +652,13 @@ class RigidBody extends Trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setAngularVelocity(v:Vec4) {
|
public function setAngularVelocity(v:Vec4) {
|
||||||
|
#if hl
|
||||||
|
hlVel.Set(v.x, v.y, v.z);
|
||||||
|
physics.bodyInterface.SetAngularVelocity(bodyId, hlVel);
|
||||||
|
#else
|
||||||
var vel = new jolt.Jt.Vec3(v.x, v.y, v.z);
|
var vel = new jolt.Jt.Vec3(v.x, v.y, v.z);
|
||||||
physics.bodyInterface.SetAngularVelocity(bodyId, vel);
|
physics.bodyInterface.SetAngularVelocity(bodyId, vel);
|
||||||
#if hl vel.delete(); #end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAngularVelocity():Vec4 {
|
public function getAngularVelocity():Vec4 {
|
||||||
@ -643,15 +691,23 @@ class RigidBody extends Trait {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setPosition(pos:Vec4) {
|
public function setPosition(pos:Vec4) {
|
||||||
|
#if hl
|
||||||
|
hlPos.Set(pos.x, pos.y, pos.z);
|
||||||
|
physics.bodyInterface.SetPosition(bodyId, hlPos, 0);
|
||||||
|
#else
|
||||||
var p = new jolt.Jt.RVec3(pos.x, pos.y, pos.z);
|
var p = new jolt.Jt.RVec3(pos.x, pos.y, pos.z);
|
||||||
physics.bodyInterface.SetPosition(bodyId, p, 0);
|
physics.bodyInterface.SetPosition(bodyId, p, 0);
|
||||||
#if hl p.delete(); #end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setRotation(rot:Quat) {
|
public function setRotation(rot:Quat) {
|
||||||
|
#if hl
|
||||||
|
hlQuat.Set(rot.x, rot.y, rot.z, rot.w);
|
||||||
|
physics.bodyInterface.SetRotation(bodyId, hlQuat, 0);
|
||||||
|
#else
|
||||||
var q = new jolt.Jt.Quat(rot.x, rot.y, rot.z, rot.w);
|
var q = new jolt.Jt.Quat(rot.x, rot.y, rot.z, rot.w);
|
||||||
physics.bodyInterface.SetRotation(bodyId, q, 0);
|
physics.bodyInterface.SetRotation(bodyId, q, 0);
|
||||||
#if hl q.delete(); #end
|
#end
|
||||||
}
|
}
|
||||||
|
|
||||||
public function syncTransform() {
|
public function syncTransform() {
|
||||||
|
|||||||
@ -1185,6 +1185,8 @@ def build_success():
|
|||||||
if state.target == 'windows-hl':
|
if state.target == 'windows-hl':
|
||||||
vs_version_major = wrd.lnx_project_win_list_vs
|
vs_version_major = wrd.lnx_project_win_list_vs
|
||||||
build_mode = wrd.lnx_project_win_build_mode # Debug or Release
|
build_mode = wrd.lnx_project_win_build_mode # Debug or Release
|
||||||
|
if state.is_play:
|
||||||
|
build_mode = 'Debug' if wrd.lnx_debug_console else 'Release'
|
||||||
build_arch = wrd.lnx_project_win_build_arch # x64 or x86 (maps to Win32 for MSBuild)
|
build_arch = wrd.lnx_project_win_build_arch # x64 or x86 (maps to Win32 for MSBuild)
|
||||||
platform = 'x64' if build_arch == 'x64' else 'Win32' # MSBuild uses Win32 for x86
|
platform = 'x64' if build_arch == 'x64' else 'Win32' # MSBuild uses Win32 for x86
|
||||||
|
|
||||||
|
|||||||
@ -217,6 +217,11 @@ def init_properties():
|
|||||||
('Oimo', 'Oimo', 'Oimo'),
|
('Oimo', 'Oimo', 'Oimo'),
|
||||||
('Jolt', 'Jolt', 'Jolt')],
|
('Jolt', 'Jolt', 'Jolt')],
|
||||||
name="Physics Engine", default='Bullet', update=assets.invalidate_compiler_cache)
|
name="Physics Engine", default='Bullet', update=assets.invalidate_compiler_cache)
|
||||||
|
bpy.types.World.lnx_jolt_multithread = EnumProperty(
|
||||||
|
items=[('Auto', 'Auto', 'Use multithreading for krom/node targets, single-thread for html5'),
|
||||||
|
('Enabled', 'Enabled', 'Always use multithreaded Jolt build'),
|
||||||
|
('Disabled', 'Disabled', 'Always use single-threaded Jolt build')],
|
||||||
|
name="Jolt Multithreading", default='Auto', update=assets.invalidate_compiler_cache)
|
||||||
bpy.types.World.lnx_physics_fixed_step = FloatProperty(
|
bpy.types.World.lnx_physics_fixed_step = FloatProperty(
|
||||||
name="Fixed Step", default=1/60, min=0, max=1,
|
name="Fixed Step", default=1/60, min=0, max=1,
|
||||||
description="Physics steps for fixed update"
|
description="Physics steps for fixed update"
|
||||||
|
|||||||
@ -1291,6 +1291,8 @@ class LNX_PT_ProjectModulesPanel(bpy.types.Panel):
|
|||||||
layout.prop(wrd, 'lnx_physics')
|
layout.prop(wrd, 'lnx_physics')
|
||||||
if wrd.lnx_physics != 'Disabled':
|
if wrd.lnx_physics != 'Disabled':
|
||||||
layout.prop(wrd, 'lnx_physics_engine')
|
layout.prop(wrd, 'lnx_physics_engine')
|
||||||
|
if wrd.lnx_physics_engine == 'Jolt':
|
||||||
|
layout.prop(wrd, 'lnx_jolt_multithread')
|
||||||
layout.prop(wrd, 'lnx_navigation')
|
layout.prop(wrd, 'lnx_navigation')
|
||||||
if wrd.lnx_navigation != 'Disabled':
|
if wrd.lnx_navigation != 'Disabled':
|
||||||
layout.prop(wrd, 'lnx_navigation_engine')
|
layout.prop(wrd, 'lnx_navigation_engine')
|
||||||
|
|||||||
@ -290,12 +290,28 @@ let project = new Project('""" + lnx.utils.safesrc(wrd.lnx_project_name + '-' +
|
|||||||
if not os.path.exists('Libraries/haxejolt'):
|
if not os.path.exists('Libraries/haxejolt'):
|
||||||
khafile.write(add_leenkx_library(sdk_path + '/lib/', 'haxejolt', rel_path=do_relpath_sdk))
|
khafile.write(add_leenkx_library(sdk_path + '/lib/', 'haxejolt', rel_path=do_relpath_sdk))
|
||||||
if state.target.startswith('krom') or state.target == 'html5' or state.target == 'node':
|
if state.target.startswith('krom') or state.target == 'html5' or state.target == 'node':
|
||||||
joltjs_path = sdk_path + '/lib/haxejolt/jolt/jolt.wasm.js'
|
jolt_mt = wrd.lnx_jolt_multithread
|
||||||
joltjs_path = joltjs_path.replace('\\', '/').replace('//', '/')
|
multithread = False
|
||||||
khafile.write(add_assets(joltjs_path, rel_path=do_relpath_sdk))
|
if jolt_mt == 'Enabled':
|
||||||
joltjs_wasm_path = sdk_path + '/lib/haxejolt/jolt/jolt.wasm.wasm'
|
multithread = True
|
||||||
joltjs_wasm_path = joltjs_wasm_path.replace('\\', '/').replace('//', '/')
|
elif jolt_mt == 'Auto':
|
||||||
khafile.write(add_assets(joltjs_wasm_path, rel_path=do_relpath_sdk))
|
if state.target.startswith('krom') or state.target == 'node':
|
||||||
|
multithread = True
|
||||||
|
if multithread:
|
||||||
|
assets.add_khafile_def('lnx_jolt_mt')
|
||||||
|
joltjs_path = sdk_path + '/lib/haxejolt/jolt/jolt.mt.wasm.js'
|
||||||
|
joltjs_path = joltjs_path.replace('\\', '/').replace('//', '/')
|
||||||
|
khafile.write(add_assets(joltjs_path, rel_path=do_relpath_sdk))
|
||||||
|
joltjs_wasm_path = sdk_path + '/lib/haxejolt/jolt/jolt.mt.wasm.wasm'
|
||||||
|
joltjs_wasm_path = joltjs_wasm_path.replace('\\', '/').replace('//', '/')
|
||||||
|
khafile.write(add_assets(joltjs_wasm_path, rel_path=do_relpath_sdk))
|
||||||
|
else:
|
||||||
|
joltjs_path = sdk_path + '/lib/haxejolt/jolt/jolt.wasm.js'
|
||||||
|
joltjs_path = joltjs_path.replace('\\', '/').replace('//', '/')
|
||||||
|
khafile.write(add_assets(joltjs_path, rel_path=do_relpath_sdk))
|
||||||
|
joltjs_wasm_path = sdk_path + '/lib/haxejolt/jolt/jolt.wasm.wasm'
|
||||||
|
joltjs_wasm_path = joltjs_wasm_path.replace('\\', '/').replace('//', '/')
|
||||||
|
khafile.write(add_assets(joltjs_wasm_path, rel_path=do_relpath_sdk))
|
||||||
|
|
||||||
if export_navigation:
|
if export_navigation:
|
||||||
assets.add_khafile_def('lnx_navigation')
|
assets.add_khafile_def('lnx_navigation')
|
||||||
|
|||||||
@ -158,7 +158,9 @@ extern class Body {
|
|||||||
public function IsSensor():Bool;
|
public function IsSensor():Bool;
|
||||||
public function SetIsSensor(sensor:Bool):Void;
|
public function SetIsSensor(sensor:Bool):Void;
|
||||||
public function GetPosition():RVec3;
|
public function GetPosition():RVec3;
|
||||||
|
public function GetPositionInto(out:RVec3):Void;
|
||||||
public function GetRotation():Quat;
|
public function GetRotation():Quat;
|
||||||
|
public function GetRotationInto(out:Quat):Void;
|
||||||
public function GetWorldTransform():Mat44;
|
public function GetWorldTransform():Mat44;
|
||||||
public function GetCenterOfMassPosition():RVec3;
|
public function GetCenterOfMassPosition():RVec3;
|
||||||
public function GetCenterOfMassTransform():Mat44;
|
public function GetCenterOfMassTransform():Mat44;
|
||||||
@ -291,6 +293,7 @@ extern class MassProperties {
|
|||||||
@:native('Jolt.BodyCreationSettings')
|
@:native('Jolt.BodyCreationSettings')
|
||||||
extern class BodyCreationSettings {
|
extern class BodyCreationSettings {
|
||||||
public function new(shape:Shape, position:RVec3, rotation:Quat, motionType:Int, objectLayer:Int):Void;
|
public function new(shape:Shape, position:RVec3, rotation:Quat, motionType:Int, objectLayer:Int):Void;
|
||||||
|
public var mObjectLayer:Int;
|
||||||
public var mFriction:Float;
|
public var mFriction:Float;
|
||||||
public var mRestitution:Float;
|
public var mRestitution:Float;
|
||||||
public var mLinearDamping:Float;
|
public var mLinearDamping:Float;
|
||||||
@ -409,9 +412,70 @@ extern class ObjectLayerPairFilter {
|
|||||||
public function new():Void;
|
public function new():Void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.RayCastSettings')
|
||||||
|
extern class RayCastSettings {
|
||||||
|
public function new():Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.BroadPhaseLayerFilter')
|
||||||
|
extern class BroadPhaseLayerFilter {
|
||||||
|
public function new():Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.ObjectLayerFilter')
|
||||||
|
extern class ObjectLayerFilter {
|
||||||
|
public function new():Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.DefaultObjectLayerFilter')
|
||||||
|
extern class DefaultObjectLayerFilter extends ObjectLayerFilter {
|
||||||
|
public function new(objectLayerPairFilter:ObjectLayerPairFilter, objectLayer:Int):Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.BodyFilter')
|
||||||
|
extern class BodyFilter {
|
||||||
|
public function new():Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.ShapeFilter')
|
||||||
|
extern class ShapeFilter {
|
||||||
|
public function new():Void;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.CastRayCollector')
|
||||||
|
extern class CastRayCollector {
|
||||||
|
public function new():Void;
|
||||||
|
public function Reset():Void;
|
||||||
|
public function SetContext(context:Dynamic):Void;
|
||||||
|
public function GetContext():Dynamic;
|
||||||
|
public function UpdateEarlyOutFraction(fraction:Float):Void;
|
||||||
|
public function ResetEarlyOutFraction(fraction:Float = 1.0):Void;
|
||||||
|
public function ForceEarlyOut():Void;
|
||||||
|
public function ShouldEarlyOut():Bool;
|
||||||
|
public function GetEarlyOutFraction():Float;
|
||||||
|
public function GetPositiveEarlyOutFraction():Float;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.CastRayClosestHitCollisionCollector')
|
||||||
|
extern class CastRayClosestHitCollisionCollector extends CastRayCollector {
|
||||||
|
public function new():Void;
|
||||||
|
public function HadHit():Bool;
|
||||||
|
public var mHit:RayCastResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@:native('Jolt.BroadPhaseQuery')
|
||||||
|
extern class BroadPhaseQuery {
|
||||||
|
public function CastRay(ray:RRayCast, result:RayCastResult,
|
||||||
|
broadPhaseFilter:BroadPhaseLayerFilter,
|
||||||
|
objectLayerFilter:ObjectLayerFilter):Void;
|
||||||
|
}
|
||||||
|
|
||||||
@:native('Jolt.NarrowPhaseQuery')
|
@:native('Jolt.NarrowPhaseQuery')
|
||||||
extern class NarrowPhaseQuery {
|
extern class NarrowPhaseQuery {
|
||||||
public function CastRay(ray:RRayCast, result:RayCastResult):Bool;
|
public function CastRay(ray:RRayCast, settings:RayCastSettings,
|
||||||
|
collector:CastRayCollector, broadPhaseFilter:BroadPhaseLayerFilter,
|
||||||
|
objectLayerFilter:ObjectLayerFilter, bodyFilter:BodyFilter,
|
||||||
|
shapeFilter:ShapeFilter):Void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@:native('Jolt.ContactListenerJS')
|
@:native('Jolt.ContactListenerJS')
|
||||||
@ -440,6 +504,7 @@ extern class PhysicsSystem {
|
|||||||
public function SetContactListener(listener:ContactListener):Void;
|
public function SetContactListener(listener:ContactListener):Void;
|
||||||
public function SetBodyActivationListener(listener:BodyActivationListener):Void;
|
public function SetBodyActivationListener(listener:BodyActivationListener):Void;
|
||||||
public function GetNarrowPhaseQuery():NarrowPhaseQuery;
|
public function GetNarrowPhaseQuery():NarrowPhaseQuery;
|
||||||
|
public function GetBroadPhaseQuery():BroadPhaseQuery;
|
||||||
public function AddConstraint(constraint:Constraint):Void;
|
public function AddConstraint(constraint:Constraint):Void;
|
||||||
public function RemoveConstraint(constraint:Constraint):Void;
|
public function RemoveConstraint(constraint:Constraint):Void;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -156,7 +156,9 @@ interface Body {
|
|||||||
int GetMotionType();
|
int GetMotionType();
|
||||||
void SetMotionType(int inMotionType);
|
void SetMotionType(int inMotionType);
|
||||||
[Value] RVec3 GetPosition();
|
[Value] RVec3 GetPosition();
|
||||||
|
void GetPositionInto([Ref] RVec3 outPosition);
|
||||||
[Value] Quat GetRotation();
|
[Value] Quat GetRotation();
|
||||||
|
void GetRotationInto([Ref] Quat outRotation);
|
||||||
[Value] Mat44 GetWorldTransform();
|
[Value] Mat44 GetWorldTransform();
|
||||||
[Value] RVec3 GetCenterOfMassPosition();
|
[Value] RVec3 GetCenterOfMassPosition();
|
||||||
[Value] Mat44 GetCenterOfMassTransform();
|
[Value] Mat44 GetCenterOfMassTransform();
|
||||||
@ -198,6 +200,7 @@ interface MassProperties {
|
|||||||
// BodyCreationSettings
|
// BodyCreationSettings
|
||||||
interface BodyCreationSettings {
|
interface BodyCreationSettings {
|
||||||
void BodyCreationSettings([Const] Shape inShape, [Const, Ref] RVec3 inPosition, [Const, Ref] Quat inRotation, int inMotionType, short inObjectLayer);
|
void BodyCreationSettings([Const] Shape inShape, [Const, Ref] RVec3 inPosition, [Const, Ref] Quat inRotation, int inMotionType, short inObjectLayer);
|
||||||
|
attribute short mObjectLayer;
|
||||||
attribute float mFriction;
|
attribute float mFriction;
|
||||||
attribute float mRestitution;
|
attribute float mRestitution;
|
||||||
attribute float mLinearDamping;
|
attribute float mLinearDamping;
|
||||||
@ -273,9 +276,39 @@ interface RayCastResult {
|
|||||||
attribute float mFraction;
|
attribute float mFraction;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// RayCastSettings
|
||||||
|
interface RayCastSettings {
|
||||||
|
void RayCastSettings();
|
||||||
|
};
|
||||||
|
|
||||||
|
// BroadPhaseLayerFilter
|
||||||
|
interface BroadPhaseLayerFilter {
|
||||||
|
void BroadPhaseLayerFilter();
|
||||||
|
};
|
||||||
|
|
||||||
|
// ObjectLayerFilter
|
||||||
|
interface ObjectLayerFilter {
|
||||||
|
void ObjectLayerFilter();
|
||||||
|
};
|
||||||
|
|
||||||
|
// BodyFilter
|
||||||
|
interface BodyFilter {
|
||||||
|
void BodyFilter();
|
||||||
|
};
|
||||||
|
|
||||||
|
// ShapeFilter
|
||||||
|
interface ShapeFilter {
|
||||||
|
void ShapeFilter();
|
||||||
|
};
|
||||||
|
|
||||||
|
// BroadPhaseQuery
|
||||||
|
interface BroadPhaseQuery {
|
||||||
|
void CastRay([Const, Ref] RRayCast inRay, [Ref] RayCastResult ioHit, [Const, Ref] BroadPhaseLayerFilter inBroadPhaseLayerFilter, [Const, Ref] ObjectLayerFilter inObjectLayerFilter);
|
||||||
|
};
|
||||||
|
|
||||||
// NarrowPhaseQuery
|
// NarrowPhaseQuery
|
||||||
interface NarrowPhaseQuery {
|
interface NarrowPhaseQuery {
|
||||||
boolean CastRay([Const, Ref] RRayCast inRay, [Ref] RayCastResult ioHit);
|
boolean CastRay([Const, Ref] RRayCast inRay, [Ref] RayCastResult ioHit, [Const, Ref] RayCastSettings inRayCastSettings, [Const, Ref] BroadPhaseLayerFilter inBroadPhaseLayerFilter, [Const, Ref] ObjectLayerFilter inObjectLayerFilter, [Const, Ref] BodyFilter inBodyFilter, [Const, Ref] ShapeFilter inShapeFilter);
|
||||||
};
|
};
|
||||||
|
|
||||||
// PhysicsSystem
|
// PhysicsSystem
|
||||||
@ -292,6 +325,7 @@ interface PhysicsSystem {
|
|||||||
void SetGravity([Const, Ref] Vec3 inGravity);
|
void SetGravity([Const, Ref] Vec3 inGravity);
|
||||||
[Value] Vec3 GetGravity();
|
[Value] Vec3 GetGravity();
|
||||||
[Const, Ref] NarrowPhaseQuery GetNarrowPhaseQuery();
|
[Const, Ref] NarrowPhaseQuery GetNarrowPhaseQuery();
|
||||||
|
[Const, Ref] BroadPhaseQuery GetBroadPhaseQuery();
|
||||||
void AddConstraint(Constraint inConstraint);
|
void AddConstraint(Constraint inConstraint);
|
||||||
void RemoveConstraint(Constraint inConstraint);
|
void RemoveConstraint(Constraint inConstraint);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -214,7 +214,7 @@ class Module {
|
|||||||
if( v.ret.t != TVoid )
|
if( v.ret.t != TVoid )
|
||||||
e = { expr : EReturn(e), pos : p };
|
e = { expr : EReturn(e), pos : p };
|
||||||
else if( isConstr )
|
else if( isConstr )
|
||||||
e = macro this = $e;
|
e = macro this = untyped $e;
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -849,6 +849,16 @@ HL_PRIM void HL_NAME(BodyCreationSettings_set_mIsSensor)(_ref(BodyCreationSettin
|
|||||||
}
|
}
|
||||||
DEFINE_PRIM(_VOID, BodyCreationSettings_set_mIsSensor, _IDL _BOOL);
|
DEFINE_PRIM(_VOID, BodyCreationSettings_set_mIsSensor, _IDL _BOOL);
|
||||||
|
|
||||||
|
HL_PRIM int HL_NAME(BodyCreationSettings_get_mObjectLayer)(_ref(BodyCreationSettings)* _this) {
|
||||||
|
return (int)_unref(_this)->mObjectLayer;
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_I32, BodyCreationSettings_get_mObjectLayer, _IDL);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(BodyCreationSettings_set_mObjectLayer)(_ref(BodyCreationSettings)* _this, int value) {
|
||||||
|
_unref(_this)->mObjectLayer = (ObjectLayer)value;
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, BodyCreationSettings_set_mObjectLayer, _IDL _I32);
|
||||||
|
|
||||||
// ============= BodyInterface =============
|
// ============= BodyInterface =============
|
||||||
|
|
||||||
HL_PRIM _ref(Body)* HL_NAME(BodyInterface_CreateBody1)(_ref(BodyInterface)* _this, _ref(BodyCreationSettings)* settings) {
|
HL_PRIM _ref(Body)* HL_NAME(BodyInterface_CreateBody1)(_ref(BodyInterface)* _this, _ref(BodyCreationSettings)* settings) {
|
||||||
@ -1110,12 +1120,22 @@ HL_PRIM _ref(RVec3)* HL_NAME(Body_GetPosition0)(_ref(Body)* _this) {
|
|||||||
}
|
}
|
||||||
DEFINE_PRIM(_IDL, Body_GetPosition0, _IDL);
|
DEFINE_PRIM(_IDL, Body_GetPosition0, _IDL);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(Body_GetPositionInto1)(_ref(Body)* _this, _ref(RVec3)* out) {
|
||||||
|
*_unref(out) = _unref(_this)->GetPosition();
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, Body_GetPositionInto1, _IDL _IDL);
|
||||||
|
|
||||||
HL_PRIM _ref(Quat)* HL_NAME(Body_GetRotation0)(_ref(Body)* _this) {
|
HL_PRIM _ref(Quat)* HL_NAME(Body_GetRotation0)(_ref(Body)* _this) {
|
||||||
Quat rot = _unref(_this)->GetRotation();
|
Quat rot = _unref(_this)->GetRotation();
|
||||||
return alloc_ref(new Quat(rot), Quat);
|
return alloc_ref(new Quat(rot), Quat);
|
||||||
}
|
}
|
||||||
DEFINE_PRIM(_IDL, Body_GetRotation0, _IDL);
|
DEFINE_PRIM(_IDL, Body_GetRotation0, _IDL);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(Body_GetRotationInto1)(_ref(Body)* _this, _ref(Quat)* out) {
|
||||||
|
*_unref(out) = _unref(_this)->GetRotation();
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, Body_GetRotationInto1, _IDL _IDL);
|
||||||
|
|
||||||
HL_PRIM _ref(RVec3)* HL_NAME(Body_GetCenterOfMassPosition0)(_ref(Body)* _this) {
|
HL_PRIM _ref(RVec3)* HL_NAME(Body_GetCenterOfMassPosition0)(_ref(Body)* _this) {
|
||||||
RVec3 pos = _unref(_this)->GetCenterOfMassPosition();
|
RVec3 pos = _unref(_this)->GetCenterOfMassPosition();
|
||||||
return alloc_ref(new RVec3(pos), RVec3);
|
return alloc_ref(new RVec3(pos), RVec3);
|
||||||
@ -2385,6 +2405,66 @@ HL_PRIM void HL_NAME(SixDOFConstraintSettings_SetLimitedAxis3)(_ref(SixDOFConstr
|
|||||||
}
|
}
|
||||||
DEFINE_PRIM(_VOID, SixDOFConstraintSettings_SetLimitedAxis3, _IDL _I32 _F32 _F32);
|
DEFINE_PRIM(_VOID, SixDOFConstraintSettings_SetLimitedAxis3, _IDL _I32 _F32 _F32);
|
||||||
|
|
||||||
|
// ============= RayCastSettings =============
|
||||||
|
|
||||||
|
HL_PRIM _ref(RayCastSettings)* HL_NAME(RayCastSettings_new0)() {
|
||||||
|
return alloc_ref(new RayCastSettings(), RayCastSettings);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_IDL, RayCastSettings_new0, _NO_ARG);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(RayCastSettings_delete)(_ref(RayCastSettings)* _this) {
|
||||||
|
free_ref(_this);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, RayCastSettings_delete, _IDL);
|
||||||
|
|
||||||
|
// ============= BroadPhaseLayerFilter =============
|
||||||
|
|
||||||
|
HL_PRIM _ref(BroadPhaseLayerFilter)* HL_NAME(BroadPhaseLayerFilter_new0)() {
|
||||||
|
return alloc_ref(new BroadPhaseLayerFilter(), BroadPhaseLayerFilter);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_IDL, BroadPhaseLayerFilter_new0, _NO_ARG);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(BroadPhaseLayerFilter_delete)(_ref(BroadPhaseLayerFilter)* _this) {
|
||||||
|
free_ref(_this);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, BroadPhaseLayerFilter_delete, _IDL);
|
||||||
|
|
||||||
|
// ============= ObjectLayerFilter =============
|
||||||
|
|
||||||
|
HL_PRIM _ref(ObjectLayerFilter)* HL_NAME(ObjectLayerFilter_new0)() {
|
||||||
|
return alloc_ref(new ObjectLayerFilter(), ObjectLayerFilter);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_IDL, ObjectLayerFilter_new0, _NO_ARG);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(ObjectLayerFilter_delete)(_ref(ObjectLayerFilter)* _this) {
|
||||||
|
free_ref(_this);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, ObjectLayerFilter_delete, _IDL);
|
||||||
|
|
||||||
|
// ============= BodyFilter =============
|
||||||
|
|
||||||
|
HL_PRIM _ref(BodyFilter)* HL_NAME(BodyFilter_new0)() {
|
||||||
|
return alloc_ref(new BodyFilter(), BodyFilter);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_IDL, BodyFilter_new0, _NO_ARG);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(BodyFilter_delete)(_ref(BodyFilter)* _this) {
|
||||||
|
free_ref(_this);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, BodyFilter_delete, _IDL);
|
||||||
|
|
||||||
|
// ============= ShapeFilter =============
|
||||||
|
|
||||||
|
HL_PRIM _ref(ShapeFilter)* HL_NAME(ShapeFilter_new0)() {
|
||||||
|
return alloc_ref(new ShapeFilter(), ShapeFilter);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_IDL, ShapeFilter_new0, _NO_ARG);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(ShapeFilter_delete)(_ref(ShapeFilter)* _this) {
|
||||||
|
free_ref(_this);
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, ShapeFilter_delete, _IDL);
|
||||||
|
|
||||||
// ============= NarrowPhaseQuery =============
|
// ============= NarrowPhaseQuery =============
|
||||||
|
|
||||||
HL_PRIM void HL_NAME(NarrowPhaseQuery_delete)(_ref(NarrowPhaseQuery)* _this) {
|
HL_PRIM void HL_NAME(NarrowPhaseQuery_delete)(_ref(NarrowPhaseQuery)* _this) {
|
||||||
@ -2392,15 +2472,10 @@ HL_PRIM void HL_NAME(NarrowPhaseQuery_delete)(_ref(NarrowPhaseQuery)* _this) {
|
|||||||
}
|
}
|
||||||
DEFINE_PRIM(_VOID, NarrowPhaseQuery_delete, _IDL);
|
DEFINE_PRIM(_VOID, NarrowPhaseQuery_delete, _IDL);
|
||||||
|
|
||||||
HL_PRIM bool HL_NAME(NarrowPhaseQuery_CastRay2)(_ref(NarrowPhaseQuery)* _this, _ref(RRayCast)* ray, _ref(RayCastResult)* result) {
|
HL_PRIM bool HL_NAME(NarrowPhaseQuery_CastRay7)(_ref(NarrowPhaseQuery)* _this, _ref(RRayCast)* ray, _ref(RayCastResult)* result, _ref(RayCastSettings)* settings, _ref(BroadPhaseLayerFilter)* broadPhaseFilter, _ref(ObjectLayerFilter)* objectLayerFilter, _ref(BodyFilter)* bodyFilter, _ref(ShapeFilter)* shapeFilter) {
|
||||||
RayCastResult hit;
|
return _unref(_this)->CastRay(*_unref(ray), *_unref(result), *_unref(broadPhaseFilter), *_unref(objectLayerFilter), *_unref(bodyFilter));
|
||||||
bool didHit = _unref(_this)->CastRay(*_unref(ray), hit);
|
|
||||||
if (didHit) {
|
|
||||||
*_unref(result) = hit;
|
|
||||||
}
|
|
||||||
return didHit;
|
|
||||||
}
|
}
|
||||||
DEFINE_PRIM(_BOOL, NarrowPhaseQuery_CastRay2, _IDL _IDL _IDL);
|
DEFINE_PRIM(_BOOL, NarrowPhaseQuery_CastRay7, _IDL _IDL _IDL _IDL _IDL _IDL _IDL _IDL);
|
||||||
|
|
||||||
// ============= PhysicsSystem::GetNarrowPhaseQuery =============
|
// ============= PhysicsSystem::GetNarrowPhaseQuery =============
|
||||||
|
|
||||||
@ -2409,4 +2484,23 @@ HL_PRIM _ref(NarrowPhaseQuery)* HL_NAME(PhysicsSystem_GetNarrowPhaseQuery0)(_ref
|
|||||||
}
|
}
|
||||||
DEFINE_PRIM(_IDL, PhysicsSystem_GetNarrowPhaseQuery0, _IDL);
|
DEFINE_PRIM(_IDL, PhysicsSystem_GetNarrowPhaseQuery0, _IDL);
|
||||||
|
|
||||||
|
// ============= BroadPhaseQuery =============
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(BroadPhaseQuery_delete)(_ref(BroadPhaseQuery)* _this) {
|
||||||
|
// BroadPhaseQuery is owned by PhysicsSystem, do not delete
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, BroadPhaseQuery_delete, _IDL);
|
||||||
|
|
||||||
|
HL_PRIM void HL_NAME(BroadPhaseQuery_CastRay4)(_ref(BroadPhaseQuery)* _this, _ref(RRayCast)* ray, _ref(RayCastResult)* result, _ref(BroadPhaseLayerFilter)* broadPhaseFilter, _ref(ObjectLayerFilter)* objectLayerFilter) {
|
||||||
|
// BroadPhaseQuery::CastRay API mismatch - RayCastBodyCollector required, not RayCastResult. Not used from Haxe.
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_VOID, BroadPhaseQuery_CastRay4, _IDL _IDL _IDL _IDL _IDL);
|
||||||
|
|
||||||
|
// ============= PhysicsSystem::GetBroadPhaseQuery =============
|
||||||
|
|
||||||
|
HL_PRIM _ref(BroadPhaseQuery)* HL_NAME(PhysicsSystem_GetBroadPhaseQuery0)(_ref(PhysicsSystem)* _this) {
|
||||||
|
return const_cast<BroadPhaseQuery*>(&_unref(_this)->GetBroadPhaseQuery());
|
||||||
|
}
|
||||||
|
DEFINE_PRIM(_IDL, PhysicsSystem_GetBroadPhaseQuery0, _IDL);
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
1931
lib/haxejolt/jolt/jolt.mt.wasm.js
Normal file
1931
lib/haxejolt/jolt/jolt.mt.wasm.js
Normal file
File diff suppressed because it is too large
Load Diff
BIN
lib/haxejolt/jolt/jolt.mt.wasm.wasm
Normal file
BIN
lib/haxejolt/jolt/jolt.mt.wasm.wasm
Normal file
Binary file not shown.
@ -10,7 +10,20 @@ project.cppStd = 'c++17';
|
|||||||
if (platform === Platform.Windows || platform === Platform.Linux) {
|
if (platform === Platform.Windows || platform === Platform.Linux) {
|
||||||
project.addDefine('JPH_USE_SSE4_1');
|
project.addDefine('JPH_USE_SSE4_1');
|
||||||
project.addDefine('JPH_USE_SSE4_2');
|
project.addDefine('JPH_USE_SSE4_2');
|
||||||
|
if (process.env.JOLT_USE_AVX2) {
|
||||||
|
project.addDefine('JPH_USE_AVX2');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (platform === Platform.Windows) {
|
||||||
|
project.addCppFlag('/O2');
|
||||||
|
project.addCppFlag('/Ot');
|
||||||
|
if (process.env.JOLT_USE_AVX2) {
|
||||||
|
project.addCppFlag('/arch:AVX2');
|
||||||
|
}
|
||||||
|
project.addCppFlag('/Ob1');
|
||||||
}
|
}
|
||||||
project.addDefine('JPH_NO_DEBUG');
|
project.addDefine('JPH_NO_DEBUG');
|
||||||
|
project.addDefine('NDEBUG');
|
||||||
|
|
||||||
resolve(project);
|
resolve(project);
|
||||||
|
|||||||
Reference in New Issue
Block a user