Fix nodes

This commit is contained in:
Henrique 2021-06-28 16:12:05 -03:00
parent 7515a20d93
commit c7e1f5d0a9
6 changed files with 31 additions and 35 deletions

View file

@ -10,23 +10,20 @@ class GetLocationNode extends LogicNode {
override function get(from: Int): Dynamic { override function get(from: Int): Dynamic {
var object: Object = inputs[0].get(); var object: Object = inputs[0].get();
var relative: Bool = inputs[1].get();
if (object == null) return null; if (object == null) return null;
var loc = object.transform.world.getLoc(); var loc = object.transform.world.getLoc();
if (inputs.length > 1) { // Keep compatibility if (relative && object.parent != null) {
var relative: Bool = inputs[1].get(); loc.sub(object.parent.transform.world.getLoc()); // Add parent location influence
if (relative && object.parent != null) { // Convert loc to parent local space
loc.sub(object.parent.transform.world.getLoc()); // Add parent location influence var dotX = loc.dot(object.parent.transform.right());
var dotY = loc.dot(object.parent.transform.look());
// Convert vec to parent local space var dotZ = loc.dot(object.parent.transform.up());
var dotX = vec.dot(object.parent.transform.right()); loc.set(dotX, dotY, dotZ);
var dotY = vec.dot(object.parent.transform.look());
var dotZ = vec.dot(object.parent.transform.up());
loc.set(dotX, dotY, dotZ);
}
} }
return loc; return loc;

View file

@ -13,21 +13,19 @@ class SetLocationNode extends LogicNode {
override function run(from: Int) { override function run(from: Int) {
var object: Object = inputs[1].get(); var object: Object = inputs[1].get();
var vec: Vec4 = inputs[2].get(); var vec: Vec4 = inputs[2].get();
var relative: Bool = inputs[3].get();
if (object == null || vec == null) return; if (object == null || vec == null) return;
if (inputs.length > 3) { // Keep compatibility if (!relative && object.parent != null) {
var relative: Bool = inputs[3].get(); var loc = vec.clone();
loc.sub(object.parent.transform.world.getLoc()); // Remove parent location influence
if (!relative && object.parent != null) { // Convert vec to parent local space
vec.sub(object.parent.transform.world.getLoc()); // Remove parent location influence var dotX = loc.dot(object.parent.transform.right());
var dotY = loc.dot(object.parent.transform.look());
// Convert vec to parent local space var dotZ = loc.dot(object.parent.transform.up());
var dotX = vec.dot(object.parent.transform.right()); vec.set(dotX, dotY, dotZ);
var dotY = vec.dot(object.parent.transform.look());
var dotZ = vec.dot(object.parent.transform.up());
vec.set(dotX, dotY, dotZ);
}
} }
object.transform.loc.setFrom(vec); object.transform.loc.setFrom(vec);
@ -40,4 +38,4 @@ class SetLocationNode extends LogicNode {
runOutput(0); runOutput(0);
} }
} }

View file

@ -13,18 +13,10 @@ class WorldVectorToLocalSpaceNode extends LogicNode {
var object: Object = inputs[0].get(); var object: Object = inputs[0].get();
var worldVec: Vec4 = inputs[1].get(); var worldVec: Vec4 = inputs[1].get();
if (object == null || worldVec == null) return null; if (object == null || worldVec == null) return null;
var localVec = new Vec4(); var localVec = new Vec4();
localVec.sub(object.transform.world.getLoc());
if (inputs.length > 2) { // Keep compatibility
var sub: Bool = inputs[2].get();
if (sub) {
localVec.sub(object.transform.world.getLoc());
}
}
localVec.x = worldVec.dot(object.transform.right()); localVec.x = worldVec.dot(object.transform.right());
localVec.y = worldVec.dot(object.transform.look()); localVec.y = worldVec.dot(object.transform.look());

View file

@ -12,7 +12,7 @@ class GetLocationNode(ArmLogicTreeNode):
bl_idname = 'LNGetLocationNode' bl_idname = 'LNGetLocationNode'
bl_label = 'Get Object Location' bl_label = 'Get Object Location'
arm_section = 'location' arm_section = 'location'
arm_version = 1 arm_version = 2
def init(self, context): def init(self, context):
super(GetLocationNode, self).init(context) super(GetLocationNode, self).init(context)
@ -20,3 +20,8 @@ class GetLocationNode(ArmLogicTreeNode):
self.add_input('NodeSocketBool', 'Parent Relative') self.add_input('NodeSocketBool', 'Parent Relative')
self.add_output('NodeSocketVector', 'Location') 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)

View file

@ -12,7 +12,7 @@ class SetLocationNode(ArmLogicTreeNode):
bl_idname = 'LNSetLocationNode' bl_idname = 'LNSetLocationNode'
bl_label = 'Set Object Location' bl_label = 'Set Object Location'
arm_section = 'location' arm_section = 'location'
arm_version = 1 arm_version = 2
def init(self, context): def init(self, context):
super(SetLocationNode, self).init(context) super(SetLocationNode, self).init(context)
@ -22,3 +22,8 @@ class SetLocationNode(ArmLogicTreeNode):
self.add_input('NodeSocketBool', 'Parent Relative') self.add_input('NodeSocketBool', 'Parent Relative')
self.add_output('ArmNodeSocketAction', 'Out') 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)

View file

@ -16,6 +16,5 @@ class WorldVectorToLocalSpaceNode(ArmLogicTreeNode):
super(WorldVectorToLocalSpaceNode, self).init(context) super(WorldVectorToLocalSpaceNode, self).init(context)
self.add_input('ArmNodeSocketObject', 'Object') self.add_input('ArmNodeSocketObject', 'Object')
self.add_input('NodeSocketVector', 'World') self.add_input('NodeSocketVector', 'World')
self.add_input('NodeSocketBool', 'Subtract', default_value=True)
self.add_output('NodeSocketVector', 'Local') self.add_output('NodeSocketVector', 'Local')