update-local-axis-nodes
This commit is contained in:
parent
8e839b84c7
commit
7fcd3dc81d
|
@ -4,6 +4,8 @@ import iron.object.Object;
|
|||
import iron.math.Vec4;
|
||||
import armory.trait.physics.RigidBody;
|
||||
|
||||
using armory.object.TransformExtension;
|
||||
|
||||
class ApplyForceAtLocationNode extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
|
@ -13,30 +15,23 @@ class ApplyForceAtLocationNode extends LogicNode {
|
|||
override function run(from: Int) {
|
||||
var object: Object = inputs[1].get();
|
||||
var force: Vec4 = inputs[2].get();
|
||||
var localForce: Bool = inputs[3].get();
|
||||
var location: Vec4 = inputs[4].get();
|
||||
var localLoc: Bool = inputs[5].get();
|
||||
var localForce: Bool = inputs.length > 2 ? inputs[3].get() : false;
|
||||
var location: Vec4 = inputs[4].get();
|
||||
var localLoc: Bool = inputs.length > 4 ? inputs[5].get() : false;
|
||||
|
||||
if (object == null || force == null || location == null) return;
|
||||
|
||||
#if arm_physics
|
||||
var rb: RigidBody = object.getTrait(RigidBody);
|
||||
|
||||
if (localLoc) {
|
||||
location.applyQuat(object.transform.rot);
|
||||
}
|
||||
if(!localForce){
|
||||
rb.applyForce(force,location);
|
||||
}
|
||||
else {
|
||||
var look = object.transform.world.look().mult(force.y);
|
||||
var right = object.transform.world.right().mult(force.x);
|
||||
var up = object.transform.world.up().mult(force.z);
|
||||
rb.applyForce(look, location);
|
||||
rb.applyForce(right, location);
|
||||
rb.applyForce(up, location);
|
||||
}
|
||||
|
||||
!localForce ? rb.applyForce(force, location) : rb.applyForce(object.transform.worldVecToOrientation(force), location);
|
||||
#end
|
||||
|
||||
runOutput(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import iron.object.Object;
|
|||
import iron.math.Vec4;
|
||||
import armory.trait.physics.RigidBody;
|
||||
|
||||
using armory.object.TransformExtension;
|
||||
|
||||
class ApplyForceNode extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
|
@ -13,25 +15,17 @@ class ApplyForceNode extends LogicNode {
|
|||
override function run(from: Int) {
|
||||
var object: Object = inputs[1].get();
|
||||
var force: Vec4 = inputs[2].get();
|
||||
var local: Bool = inputs.length > 3 ? inputs[3].get() : false;
|
||||
var local: Bool = inputs.length > 2 ? inputs[3].get() : false;
|
||||
|
||||
if (object == null || force == null) return;
|
||||
|
||||
#if arm_physics
|
||||
var rb: RigidBody = object.getTrait(RigidBody);
|
||||
if (!local) {
|
||||
rb.applyForce(force);
|
||||
}
|
||||
else {
|
||||
var look = object.transform.world.look().mult(force.y);
|
||||
var right = object.transform.world.right().mult(force.x);
|
||||
var up = object.transform.world.up().mult(force.z);
|
||||
rb.applyForce(look);
|
||||
rb.applyForce(right);
|
||||
rb.applyForce(up);
|
||||
}
|
||||
|
||||
!local ? rb.applyForce(force) : rb.applyForce(object.transform.worldVecToOrientation(force));
|
||||
#end
|
||||
|
||||
runOutput(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import iron.object.Object;
|
|||
import iron.math.Vec4;
|
||||
import armory.trait.physics.RigidBody;
|
||||
|
||||
using armory.object.TransformExtension;
|
||||
|
||||
class ApplyImpulseAtLocationNode extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
|
@ -13,30 +15,23 @@ class ApplyImpulseAtLocationNode extends LogicNode {
|
|||
override function run(from: Int) {
|
||||
var object: Object = inputs[1].get();
|
||||
var impulse: Vec4 = inputs[2].get();
|
||||
var localForce: Bool = inputs[3].get();
|
||||
var location: Vec4 = inputs[4].get();
|
||||
var localLoc: Bool = inputs[5].get();
|
||||
var localImpulse: Bool = inputs.length > 2 ? inputs[3].get() : false;
|
||||
var location: Vec4 = inputs[4].get();
|
||||
var localLoc: Bool = inputs.length > 4 ? inputs[5].get() : false;
|
||||
|
||||
if (object == null || impulse == null || location == null) return;
|
||||
|
||||
#if arm_physics
|
||||
var rb: RigidBody = object.getTrait(RigidBody);
|
||||
|
||||
if (localLoc) {
|
||||
location.applyQuat(object.transform.rot);
|
||||
}
|
||||
if (!localForce) {
|
||||
rb.applyImpulse(impulse, location);
|
||||
}
|
||||
else {
|
||||
var look = object.transform.world.look().mult(impulse.y);
|
||||
var right = object.transform.world.right().mult(impulse.x);
|
||||
var up = object.transform.world.up().mult(impulse.z);
|
||||
rb.applyImpulse(look, location);
|
||||
rb.applyImpulse(right, location);
|
||||
rb.applyImpulse(up, location);
|
||||
}
|
||||
|
||||
!localImpulse ? rb.applyImpulse(impulse, location) : rb.applyImpulse(object.transform.worldVecToOrientation(impulse), location);
|
||||
#end
|
||||
|
||||
runOutput(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import iron.object.Object;
|
|||
import iron.math.Vec4;
|
||||
import armory.trait.physics.RigidBody;
|
||||
|
||||
using armory.object.TransformExtension;
|
||||
|
||||
class ApplyImpulseNode extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
|
@ -13,25 +15,17 @@ class ApplyImpulseNode extends LogicNode {
|
|||
override function run(from: Int) {
|
||||
var object: Object = inputs[1].get();
|
||||
var impulse: Vec4 = inputs[2].get();
|
||||
var local: Bool = inputs.length > 3 ? inputs[3].get() : false;
|
||||
var local: Bool = inputs.length > 2 ? inputs[3].get() : false;
|
||||
|
||||
if (object == null || impulse == null) return;
|
||||
|
||||
#if arm_physics
|
||||
var rb: RigidBody = object.getTrait(RigidBody);
|
||||
if (!local) {
|
||||
rb.applyImpulse(impulse);
|
||||
}
|
||||
else {
|
||||
var look = object.transform.world.look().mult(impulse.y);
|
||||
var right = object.transform.world.right().mult(impulse.x);
|
||||
var up = object.transform.world.up().mult(impulse.z);
|
||||
rb.applyImpulse(look);
|
||||
rb.applyImpulse(right);
|
||||
rb.applyImpulse(up);
|
||||
}
|
||||
|
||||
!local ? rb.applyImpulse(impulse) : rb.applyImpulse(object.transform.worldVecToOrientation(impulse));
|
||||
#end
|
||||
|
||||
runOutput(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import iron.object.Object;
|
|||
import iron.math.Vec4;
|
||||
import armory.trait.physics.RigidBody;
|
||||
|
||||
using armory.object.TransformExtension;
|
||||
|
||||
class ApplyTorqueImpulseNode extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
|
@ -13,14 +15,17 @@ class ApplyTorqueImpulseNode extends LogicNode {
|
|||
override function run(from: Int) {
|
||||
var object: Object = inputs[1].get();
|
||||
var torque: Vec4 = inputs[2].get();
|
||||
var local: Bool = inputs.length > 2 ? inputs[3].get() : false;
|
||||
|
||||
if (object == null || torque == null) return;
|
||||
|
||||
#if arm_physics
|
||||
var rb: RigidBody = object.getTrait(RigidBody);
|
||||
rb.applyTorqueImpulse(torque);
|
||||
|
||||
!local ? rb.applyTorqueImpulse(torque) : rb.applyTorqueImpulse(object.transform.worldVecToOrientation(torque));
|
||||
#end
|
||||
|
||||
runOutput(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import iron.object.Object;
|
|||
import iron.math.Vec4;
|
||||
import armory.trait.physics.RigidBody;
|
||||
|
||||
using armory.object.TransformExtension;
|
||||
|
||||
class ApplyTorqueNode extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
|
@ -13,14 +15,17 @@ class ApplyTorqueNode extends LogicNode {
|
|||
override function run(from: Int) {
|
||||
var object: Object = inputs[1].get();
|
||||
var torque: Vec4 = inputs[2].get();
|
||||
var local: Bool = inputs.length > 2 ? inputs[3].get() : false;
|
||||
|
||||
if (object == null || torque == null) return;
|
||||
|
||||
#if arm_physics
|
||||
var rb: RigidBody = object.getTrait(RigidBody);
|
||||
rb.applyTorque(torque);
|
||||
|
||||
!local ? rb.applyTorque(torque) : rb.applyTorque(object.transform.worldVecToOrientation(torque));
|
||||
#end
|
||||
|
||||
runOutput(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package armory.logicnode;
|
|||
import iron.object.Object;
|
||||
import armory.trait.physics.RigidBody;
|
||||
|
||||
using armory.object.TransformExtension;
|
||||
|
||||
class GetVelocityNode extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
|
@ -11,17 +13,24 @@ class GetVelocityNode extends LogicNode {
|
|||
|
||||
override function get(from: Int): Dynamic {
|
||||
var object: Object = inputs[0].get();
|
||||
var localLinear: Bool = inputs.length > 0 ? inputs[1].get() : false;
|
||||
var localAngular: Bool = inputs.length > 1 ? inputs[2].get() : false;
|
||||
|
||||
if (object == null) return null;
|
||||
|
||||
#if arm_physics
|
||||
var rb: RigidBody = object.getTrait(RigidBody);
|
||||
|
||||
return switch (from) {
|
||||
case 0: rb.getLinearVelocity();
|
||||
case 1: rb.getAngularVelocity();
|
||||
default: null;
|
||||
if (from == 0) {
|
||||
!localLinear ? return rb.getLinearVelocity() : return object.transform.worldVecToOrientation(rb.getLinearVelocity());
|
||||
}
|
||||
|
||||
else {
|
||||
!localAngular ? return rb.getAngularVelocity() : return object.transform.worldVecToOrientation(rb.getAngularVelocity());
|
||||
}
|
||||
#end
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import iron.object.Object;
|
|||
import iron.math.Vec4;
|
||||
import armory.trait.physics.RigidBody;
|
||||
|
||||
using armory.object.TransformExtension;
|
||||
|
||||
class TranslateObjectNode extends LogicNode {
|
||||
|
||||
public function new(tree: LogicTree) {
|
||||
|
@ -13,7 +15,7 @@ class TranslateObjectNode extends LogicNode {
|
|||
override function run(from: Int) {
|
||||
var object: Object = inputs[1].get();
|
||||
var vec: Vec4 = inputs[2].get();
|
||||
var local: Bool = inputs.length > 3 ? inputs[3].get() : false;
|
||||
var local: Bool = inputs.length > 2 ? inputs[3].get() : false;
|
||||
|
||||
if (object == null || vec == null) return;
|
||||
|
||||
|
@ -21,18 +23,19 @@ class TranslateObjectNode extends LogicNode {
|
|||
object.transform.loc.add(vec);
|
||||
object.transform.buildMatrix();
|
||||
}
|
||||
|
||||
else {
|
||||
object.transform.move(object.transform.local.look(),vec.y);
|
||||
object.transform.move(object.transform.local.up(),vec.z);
|
||||
object.transform.move(object.transform.local.right(),vec.x);
|
||||
object.transform.loc.add(object.transform.worldVecToOrientation(vec));
|
||||
object.transform.buildMatrix();
|
||||
}
|
||||
|
||||
#if arm_physics
|
||||
#if arm_physics
|
||||
var rigidBody = object.getTrait(RigidBody);
|
||||
|
||||
if (rigidBody != null) rigidBody.syncTransform();
|
||||
#end
|
||||
#end
|
||||
|
||||
runOutput(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,4 +12,5 @@ class ApplyTorqueNode(ArmLogicTreeNode):
|
|||
self.add_input('ArmNodeSocketAction', 'In')
|
||||
self.add_input('ArmNodeSocketObject', 'RB')
|
||||
self.add_input('NodeSocketVector', 'Torque')
|
||||
self.add_input('NodeSocketBool', 'On Local Axis')
|
||||
self.add_output('ArmNodeSocketAction', 'Out')
|
||||
|
|
|
@ -12,4 +12,5 @@ class ApplyTorqueImpulseNode(ArmLogicTreeNode):
|
|||
self.add_input('ArmNodeSocketAction', 'In')
|
||||
self.add_input('ArmNodeSocketObject', 'RB')
|
||||
self.add_input('NodeSocketVector', 'Torque')
|
||||
self.add_input('NodeSocketBool', 'On Local Axis')
|
||||
self.add_output('ArmNodeSocketAction', 'Out')
|
||||
|
|
|
@ -9,5 +9,7 @@ class GetVelocityNode(ArmLogicTreeNode):
|
|||
def init(self, context):
|
||||
super(GetVelocityNode, self).init(context)
|
||||
self.add_input('ArmNodeSocketObject', 'RB')
|
||||
self.add_input('NodeSocketBool', 'Linear On Local Axis')
|
||||
self.add_input('NodeSocketBool', 'Angular On Local Axis')
|
||||
self.add_output('NodeSocketVector', 'Linear')
|
||||
self.add_output('NodeSocketVector', 'Angular')
|
||||
|
|
Loading…
Reference in a new issue