Add Relative Parent option to location nodes

This commit is contained in:
Henrique 2021-06-27 18:18:04 -03:00
parent 616a0e230d
commit dfad6902af
8 changed files with 54 additions and 15 deletions

View file

@ -1,6 +1,7 @@
package armory.logicnode;
import iron.object.Object;
import iron.math.Vec4;
class GetLocationNode extends LogicNode {
@ -10,9 +11,22 @@ class GetLocationNode extends LogicNode {
override function get(from: Int): Dynamic {
var object: Object = inputs[0].get();
var relative: Bool = inputs[1].get();
if (object == null) return null;
return object.transform.world.getLoc();
var loc = object.transform.world.getLoc();
if (relative) {
loc.sub(object.parent.transform.world.getLoc());
var vec = new Vec4();
vec.x = loc.dot(object.parent.transform.right());
vec.y = loc.dot(object.parent.transform.look());
vec.z = loc.dot(object.parent.transform.up());
loc.setFrom(vec);
}
return loc;
}
}

View file

@ -2,10 +2,13 @@ package armory.logicnode;
import iron.object.Object;
import iron.math.Vec4;
import iron.math.Quat;
import armory.trait.physics.RigidBody;
class SetLocationNode extends LogicNode {
var quat = new Quat();
public function new(tree: LogicTree) {
super(tree);
}
@ -13,9 +16,21 @@ class SetLocationNode extends LogicNode {
override function run(from: Int) {
var object: Object = inputs[1].get();
var vec: Vec4 = inputs[2].get();
var relative: Bool = inputs[3].get();
if (object == null || vec == null) return;
if (!relative) {
vec.sub(object.parent.transform.world.getLoc()); // Remove parent location influence
// Convert vec to parent local space
var vec1 = new Vec4();
vec1.x = vec.dot(object.parent.transform.right());
vec1.y = vec.dot(object.parent.transform.look());
vec1.z = vec.dot(object.parent.transform.up());
vec.setFrom(vec1);
}
object.transform.loc.setFrom(vec);
object.transform.buildMatrix();

View file

@ -3,8 +3,6 @@ package armory.logicnode;
import iron.object.Object;
import iron.math.Vec4;
using armory.object.TransformExtension;
class VectorToObjectOrientationNode extends LogicNode {
public function new(tree: LogicTree) {
@ -18,7 +16,7 @@ class VectorToObjectOrientationNode extends LogicNode {
if (object == null || vec == null) return null;
return object.transform.worldVecToOrientation(vec);
return vec.applyQuat(object.transform.rot);
}
}

View file

@ -3,8 +3,6 @@ package armory.logicnode;
import iron.math.Vec4;
import iron.object.Object;
using armory.object.TransformExtension;
class WorldVectorToLocalSpaceNode extends LogicNode {
public function new(tree: LogicTree) {
@ -17,7 +15,7 @@ class WorldVectorToLocalSpaceNode extends LogicNode {
if (object == null || worldVec == null) return null;
var localVec: Vec4 = new Vec4();
var localVec = new Vec4();
localVec.x = worldVec.dot(object.transform.right());
localVec.y = worldVec.dot(object.transform.look());

View file

@ -1,7 +1,14 @@
from arm.logicnode.arm_nodes import *
class GetLocationNode(ArmLogicTreeNode):
"""Returns the current location of the given object in world coordinates."""
"""Get the location of the given object in world coordinates.
@input Parent Relative: If enabled, transforms the world coordinates into object parent local coordinates
@seeNode Set Object Location
@seeNode World Vector to Local Space
@seeNode Vector to Object Orientation
"""
bl_idname = 'LNGetLocationNode'
bl_label = 'Get Object Location'
arm_section = 'location'
@ -10,5 +17,6 @@ class GetLocationNode(ArmLogicTreeNode):
def init(self, context):
super(GetLocationNode, self).init(context)
self.add_input('ArmNodeSocketObject', 'Object')
self.add_input('NodeSocketBool', 'Parent Relative')
self.add_output('NodeSocketVector', 'Location')

View file

@ -1,7 +1,14 @@
from arm.logicnode.arm_nodes import *
class SetLocationNode(ArmLogicTreeNode):
"""Sets the location of the given object."""
"""Set the location of the given object in world coordinates.
@input Parent Relative: If enabled, transforms the world coordinates into object parent local coordinates
@seeNode Get Object Location
@seeNode World Vector to Local Space
@seeNode Vector to Object Orientation
"""
bl_idname = 'LNSetLocationNode'
bl_label = 'Set Object Location'
arm_section = 'location'
@ -12,5 +19,6 @@ class SetLocationNode(ArmLogicTreeNode):
self.add_input('ArmNodeSocketAction', 'In')
self.add_input('ArmNodeSocketObject', 'Object')
self.add_input('NodeSocketVector', 'Location')
self.add_input('NodeSocketBool', 'Parent Relative', default_value=True)
self.add_output('ArmNodeSocketAction', 'Out')

View file

@ -1,10 +1,9 @@
from arm.logicnode.arm_nodes import *
class VectorToObjectOrientationNode(ArmLogicTreeNode):
"""Converts the given world vector to a vector oriented by the given object.
The object scale is taken in count.
"""Transform world coordinates into object oriented coordinates (in other words: apply object rotation to it).
@seeNode World Vector To Object Space
@seeNode World Vector to Object Space
@seeNode Get World Orientation
@seeNode Vector From Transform
"""

View file

@ -1,10 +1,9 @@
from arm.logicnode.arm_nodes import *
class WorldVectorToLocalSpaceNode(ArmLogicTreeNode):
"""Converts the given world vector to a object space vector.
The object scale is taken in count.
"""Transform world coordinates into object local coordinates.
@seeNode Vector To Object Orientation
@seeNode Vector to Object Orientation
@seeNode Get World Orientation
@seeNode Vector From Transform
"""