Merge pull request #2242 from knowledgenude/master
Add "Parent Relative" option to location nodes
This commit is contained in:
commit
e308d9058b
|
@ -10,9 +10,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 && object.parent != null) {
|
||||
loc.sub(object.parent.transform.world.getLoc()); // Add parent location influence
|
||||
|
||||
// Convert loc to parent local space
|
||||
var dotX = loc.dot(object.parent.transform.right());
|
||||
var dotY = loc.dot(object.parent.transform.look());
|
||||
var dotZ = loc.dot(object.parent.transform.up());
|
||||
loc.set(dotX, dotY, dotZ);
|
||||
}
|
||||
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,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 && object.parent != null) {
|
||||
var loc = vec.clone();
|
||||
loc.sub(object.parent.transform.world.getLoc()); // Remove parent location influence
|
||||
|
||||
// Convert vec to parent local space
|
||||
var dotX = loc.dot(object.parent.transform.right());
|
||||
var dotY = loc.dot(object.parent.transform.look());
|
||||
var dotZ = loc.dot(object.parent.transform.up());
|
||||
vec.set(dotX, dotY, dotZ);
|
||||
}
|
||||
|
||||
object.transform.loc.setFrom(vec);
|
||||
object.transform.buildMatrix();
|
||||
|
||||
|
@ -26,4 +38,4 @@ class SetLocationNode extends LogicNode {
|
|||
|
||||
runOutput(0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,8 @@ class WorldVectorToLocalSpaceNode extends LogicNode {
|
|||
|
||||
if (object == null || worldVec == null) return null;
|
||||
|
||||
var localVec: Vec4 = new Vec4();
|
||||
var localVec = new Vec4();
|
||||
localVec.sub(object.transform.world.getLoc());
|
||||
|
||||
localVec.x = worldVec.dot(object.transform.right());
|
||||
localVec.y = worldVec.dot(object.transform.look());
|
||||
|
|
|
@ -1,14 +1,27 @@
|
|||
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'
|
||||
arm_version = 1
|
||||
arm_version = 2
|
||||
|
||||
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')
|
||||
|
||||
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
|
||||
if self.arm_version not in (0, 1):
|
||||
raise LookupError()
|
||||
return NodeReplacement.Identity(self)
|
|
@ -1,16 +1,29 @@
|
|||
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'
|
||||
arm_version = 1
|
||||
arm_version = 2
|
||||
|
||||
def init(self, context):
|
||||
super(SetLocationNode, self).init(context)
|
||||
self.add_input('ArmNodeSocketAction', 'In')
|
||||
self.add_input('ArmNodeSocketObject', 'Object')
|
||||
self.add_input('NodeSocketVector', 'Location')
|
||||
self.add_input('NodeSocketBool', 'Parent Relative')
|
||||
|
||||
self.add_output('ArmNodeSocketAction', 'Out')
|
||||
|
||||
def get_replacement_node(self, node_tree: bpy.types.NodeTree):
|
||||
if self.arm_version not in (0, 1):
|
||||
raise LookupError()
|
||||
return NodeReplacement.Identity(self)
|
|
@ -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
|
||||
"""
|
||||
|
|
|
@ -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
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue