Created-Armory-Nodes/Sources/armory/logicnode/EnhancedTransformNode.hx

56 lines
1.5 KiB
Haxe

package armory.logicnode;
import armory.trait.physics.RigidBody;
import iron.object.Object;
import iron.math.Mat4;
import iron.math.Vec4;
import iron.math.Quat;
class EnhancedTransformNode extends LogicNode {
var value:Mat4 = Mat4.identity();
static var q = new Quat();
public function new(tree:LogicTree) {
super(tree);
}
override function run() {
var object:Object = inputs[1].get();
var loc:Vec4 = inputs[2].get();
var rot:Vec4 = inputs[3].get();
var scale:Vec4 = inputs[4].get();
if (loc == null || rot == null || scale == null) return;
if(loc.x == 0.0 && loc.y == 0.0 && loc.z == 0.0) {
loc.x = object.transform.loc.x;
loc.y = object.transform.loc.y;
loc.z = object.transform.loc.z;
}
if(rot.x == 0.0 && rot.y == 0.0 && rot.z == 0.0) {
rot.x = object.transform.rot.x;
rot.y = object.transform.rot.y;
rot.z = object.transform.rot.z;
}
if(scale.x == 0.0 && scale.y == 0.0 && scale.z == 0.0) {
scale.x = object.transform.scale.x;
scale.y = object.transform.scale.y;
scale.z = object.transform.scale.z;
}
q.fromEuler(rot.x, rot.y, rot.z);
value.compose(loc, q, scale);
object.transform.setMatrix(value);
#if arm_physics
var rigidBody = object.getTrait(RigidBody);
if (rigidBody != null) rigidBody.syncTransform();
#end
super.run();
}
}