diff --git a/Sources/armory/logicnode/GetLocationNode.hx b/Sources/armory/logicnode/GetLocationNode.hx index 961f8280..e5f5bee1 100644 --- a/Sources/armory/logicnode/GetLocationNode.hx +++ b/Sources/armory/logicnode/GetLocationNode.hx @@ -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; } } diff --git a/Sources/armory/logicnode/SetLocationNode.hx b/Sources/armory/logicnode/SetLocationNode.hx index 709e457b..382b0264 100644 --- a/Sources/armory/logicnode/SetLocationNode.hx +++ b/Sources/armory/logicnode/SetLocationNode.hx @@ -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(); diff --git a/Sources/armory/logicnode/VectorToObjectOrientationNode.hx b/Sources/armory/logicnode/VectorToObjectOrientationNode.hx index 2a72590a..27a4b994 100644 --- a/Sources/armory/logicnode/VectorToObjectOrientationNode.hx +++ b/Sources/armory/logicnode/VectorToObjectOrientationNode.hx @@ -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); } } diff --git a/Sources/armory/logicnode/WorldVectorToLocalSpaceNode.hx b/Sources/armory/logicnode/WorldVectorToLocalSpaceNode.hx index 493ed615..44e12f15 100644 --- a/Sources/armory/logicnode/WorldVectorToLocalSpaceNode.hx +++ b/Sources/armory/logicnode/WorldVectorToLocalSpaceNode.hx @@ -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()); diff --git a/blender/arm/logicnode/transform/LN_get_object_location.py b/blender/arm/logicnode/transform/LN_get_object_location.py index c708ba9a..62fdb9fb 100644 --- a/blender/arm/logicnode/transform/LN_get_object_location.py +++ b/blender/arm/logicnode/transform/LN_get_object_location.py @@ -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') diff --git a/blender/arm/logicnode/transform/LN_set_object_location.py b/blender/arm/logicnode/transform/LN_set_object_location.py index 48afdffb..02bebaf5 100644 --- a/blender/arm/logicnode/transform/LN_set_object_location.py +++ b/blender/arm/logicnode/transform/LN_set_object_location.py @@ -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') diff --git a/blender/arm/logicnode/transform/LN_vector_to_object_orientation.py b/blender/arm/logicnode/transform/LN_vector_to_object_orientation.py index e1402b6a..7c4bbcb0 100644 --- a/blender/arm/logicnode/transform/LN_vector_to_object_orientation.py +++ b/blender/arm/logicnode/transform/LN_vector_to_object_orientation.py @@ -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 """ diff --git a/blender/arm/logicnode/transform/LN_world_vector_to_local_space.py b/blender/arm/logicnode/transform/LN_world_vector_to_local_space.py index 61497f81..7d011fad 100644 --- a/blender/arm/logicnode/transform/LN_world_vector_to_local_space.py +++ b/blender/arm/logicnode/transform/LN_world_vector_to_local_space.py @@ -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 """