Merge pull request #1494 from QuantumCoderQC/master
Implemented Kinematic and Static flags for better control.
This commit is contained in:
commit
c97c5ff36b
|
@ -26,6 +26,7 @@ class RigidBody extends iron.Trait {
|
|||
public var linearDamping:Float;
|
||||
public var angularDamping:Float;
|
||||
public var animated:Bool;
|
||||
public var staticObj:Bool;
|
||||
public var destroyed = false;
|
||||
var linearFactors:Array<Float>;
|
||||
var angularFactors:Array<Float>;
|
||||
|
@ -100,6 +101,7 @@ class RigidBody extends iron.Trait {
|
|||
this.animated = flags[0];
|
||||
this.trigger = flags[1];
|
||||
this.ccd = flags[2];
|
||||
this.staticObj = flags[3];
|
||||
|
||||
notifyOnAdd(init);
|
||||
}
|
||||
|
@ -219,6 +221,8 @@ class RigidBody extends iron.Trait {
|
|||
vec1.setY(0);
|
||||
vec1.setZ(0);
|
||||
var inertia = vec1;
|
||||
|
||||
if(staticObj || animated) mass = 0;
|
||||
if (mass > 0) btshape.calculateLocalInertia(mass, inertia);
|
||||
var bodyCI = new bullet.Bt.RigidBodyConstructionInfo(mass, motionState, btshape, inertia);
|
||||
body = new bullet.Bt.RigidBody(bodyCI);
|
||||
|
@ -250,8 +254,12 @@ class RigidBody extends iron.Trait {
|
|||
setAngularFactor(angularFactors[0], angularFactors[1], angularFactors[2]);
|
||||
}
|
||||
|
||||
var CF_NO_CONTACT_RESPONSE = 4; // bullet.Bt.CollisionObject.CF_NO_CONTACT_RESPONSE
|
||||
if (trigger) bodyColl.setCollisionFlags(bodyColl.getCollisionFlags() | CF_NO_CONTACT_RESPONSE);
|
||||
if (trigger) bodyColl.setCollisionFlags(bodyColl.getCollisionFlags() | bullet.Bt.CollisionObject.CF_NO_CONTACT_RESPONSE);
|
||||
if (animated){
|
||||
bodyColl.setCollisionFlags(bodyColl.getCollisionFlags() | bullet.Bt.CollisionObject.CF_KINEMATIC_OBJECT);
|
||||
bodyColl.setCollisionFlags(bodyColl.getCollisionFlags() & ~bullet.Bt.CollisionObject.CF_STATIC_OBJECT);
|
||||
}
|
||||
if (staticObj && !animated) bodyColl.setCollisionFlags(bodyColl.getCollisionFlags() | bullet.Bt.CollisionObject.CF_STATIC_OBJECT);
|
||||
|
||||
if (ccd) setCcd(transform.radius);
|
||||
|
||||
|
@ -283,7 +291,7 @@ class RigidBody extends iron.Trait {
|
|||
|
||||
function physicsUpdate() {
|
||||
if (!ready) return;
|
||||
if (object.animation != null || animated) {
|
||||
if (animated) {
|
||||
syncTransform();
|
||||
}
|
||||
else {
|
||||
|
@ -447,7 +455,10 @@ class RigidBody extends iron.Trait {
|
|||
quat.fromMat(t.world);
|
||||
quat1.setValue(quat.x, quat.y, quat.z, quat.w);
|
||||
trans1.setRotation(quat1);
|
||||
body.setCenterOfMassTransform(trans1);
|
||||
if(animated)
|
||||
body.getMotionState().setWorldTransform(trans1);
|
||||
else
|
||||
body.setWorldTransform(trans1);
|
||||
if (currentScaleX != t.scale.x || currentScaleY != t.scale.y || currentScaleZ != t.scale.z) setScale(t.scale);
|
||||
activate();
|
||||
}
|
||||
|
|
|
@ -2236,7 +2236,7 @@ class ArmoryExporter:
|
|||
elif rb.collision_shape == 'CAPSULE':
|
||||
shape = 6
|
||||
body_mass = rb.mass
|
||||
is_static = not rb.enabled or (rb.type == 'PASSIVE' and not rb.kinematic)
|
||||
is_static = (not rb.enabled and not rb.kinematic) or (rb.type == 'PASSIVE' and rb.kinematic)
|
||||
if is_static:
|
||||
body_mass = 0
|
||||
x = {}
|
||||
|
@ -2285,10 +2285,11 @@ class ArmoryExporter:
|
|||
col_margin,
|
||||
deact_lv, deact_av, deact_time
|
||||
)
|
||||
body_flags = '[{0}, {1}, {2}]'.format(
|
||||
body_flags = '[{0}, {1}, {2}, {3}]'.format(
|
||||
str(rb.kinematic).lower(),
|
||||
str(bobject.arm_rb_trigger).lower(),
|
||||
str(bobject.arm_rb_ccd).lower()
|
||||
str(bobject.arm_rb_ccd).lower(),
|
||||
str(is_static).lower()
|
||||
)
|
||||
x['parameters'].append(body_params)
|
||||
x['parameters'].append(body_flags)
|
||||
|
|
Loading…
Reference in a new issue