From b5997e2e2dd9cfbdabd28c309bec8e7f606836f4 Mon Sep 17 00:00:00 2001 From: t3du <32546729+t3du@users.noreply.github.com> Date: Wed, 13 Nov 2024 14:00:54 +0000 Subject: [PATCH] screen space vector at --- .../logicnode/ScreenToWorldSpaceNode.hx | 44 +++++++++++-------- .../math/LN_screen_to_world_space.py | 33 +++++++++++--- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/Sources/armory/logicnode/ScreenToWorldSpaceNode.hx b/Sources/armory/logicnode/ScreenToWorldSpaceNode.hx index 956a44099a..e30cb04ddf 100644 --- a/Sources/armory/logicnode/ScreenToWorldSpaceNode.hx +++ b/Sources/armory/logicnode/ScreenToWorldSpaceNode.hx @@ -22,50 +22,58 @@ class ScreenToWorldSpaceNode extends LogicNode { // Separator Out if (property0) { switch (from) { - // World + // At case 0: { - return RayCaster.getRay(vInput.x, vInput.y, cam).origin; + return RayCaster.getRay(vInput.x, vInput.y, cam).at(inputs[2].get()); } - // World X + // Origin case 1: { - return RayCaster.getRay(vInput.x, vInput.y, cam).origin.x; + return RayCaster.getRay(vInput.x, vInput.y, cam).origin; } - // World Y + // Origin X case 2: { - return RayCaster.getRay(vInput.x, vInput.y, cam).origin.y; + return RayCaster.getRay(vInput.x, vInput.y, cam).origin.x; } - // World Z + // Origin Y case 3: { + return RayCaster.getRay(vInput.x, vInput.y, cam).origin.y; + } + // Origin Z + case 4: { return RayCaster.getRay(vInput.x, vInput.y, cam).origin.z; } // Direction - case 4: { - return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize(); + case 5: { + return RayCaster.getRay(vInput.x, vInput.y, cam).direction; } // Direction X - case 5: { - return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize().x; + case 6: { + return RayCaster.getRay(vInput.x, vInput.y, cam).direction.x; } // Direction Y - case 6: { - return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize().y; + case 7: { + return RayCaster.getRay(vInput.x, vInput.y, cam).direction.y; } // Direction Z - case 7: { - return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize().z; + case 8: { + return RayCaster.getRay(vInput.x, vInput.y, cam).direction.z; } } } else { switch (from) { - // World + // At case 0: { + return RayCaster.getRay(vInput.x, vInput.y, cam).at(inputs[2].get()); + } + // Origin + case 1: { return RayCaster.getRay(vInput.x, vInput.y, cam).origin; } // Direction - case 1: { - return RayCaster.getRay(vInput.x, vInput.y, cam).direction.normalize(); + case 2: { + return RayCaster.getRay(vInput.x, vInput.y, cam).direction; } } } diff --git a/blender/arm/logicnode/math/LN_screen_to_world_space.py b/blender/arm/logicnode/math/LN_screen_to_world_space.py index 1556d930b9..8aa6e36bf7 100644 --- a/blender/arm/logicnode/math/LN_screen_to_world_space.py +++ b/blender/arm/logicnode/math/LN_screen_to_world_space.py @@ -2,20 +2,33 @@ class ScreenToWorldSpaceNode(ArmLogicTreeNode): - """Transforms the given screen coordinates into world coordinates.""" + """Transforms the given screen coordinates into World coordinates. + + @input Screen X: screen x position. + @input Screen Y: screen y position. + @input Distance at: distance from camera to the result vector position. + Try between 0 and 1. + + @output Screen At: result vector position. + @output Screen Word: origin position of the ray emitted from camera. + @output Screen Direction: ray direction. + """ + bl_idname = 'LNScreenToWorldSpaceNode' bl_label = 'Screen to World Space' arm_section = 'matrix' - arm_version = 1 - max_outputs = 8 + arm_version = 2 + max_outputs = 9 property0: HaxeBoolProperty('property0', name='Separator Out', default=False) def arm_init(self, context): self.add_input('ArmIntSocket', 'Screen X') self.add_input('ArmIntSocket', 'Screen Y') + self.add_input('ArmFloatSocket', 'Distance at', default_value = 0.1) - self.add_output('ArmVectorSocket', 'World') + self.add_output('ArmVectorSocket', 'At') + self.add_output('ArmVectorSocket', 'Origin') self.add_output('ArmVectorSocket', 'Direction') def draw_buttons(self, context, layout): @@ -23,9 +36,9 @@ def draw_buttons(self, context, layout): if self.property0: if len(self.outputs) < self.max_outputs: self.outputs.remove(self.outputs.values()[-1]) # Direction vector - self.add_output('ArmFloatSocket', 'X') # World X - self.add_output('ArmFloatSocket', 'Y') # World Y - self.add_output('ArmFloatSocket', 'Z') # World Z + self.add_output('ArmFloatSocket', 'X') # Origin X + self.add_output('ArmFloatSocket', 'Y') # Origin Y + self.add_output('ArmFloatSocket', 'Z') # Origin Z self.add_output('ArmVectorSocket', 'Direction') # Vector self.add_output('ArmFloatSocket', 'X') # Direction X self.add_output('ArmFloatSocket', 'Y') # Direction Y @@ -40,3 +53,9 @@ def draw_buttons(self, context, layout): self.outputs.remove(self.outputs.values()[-1]) # Y self.outputs.remove(self.outputs.values()[-1]) # X self.add_output('ArmVectorSocket', 'Direction') + + def get_replacement_node(self, node_tree: bpy.types.NodeTree): + if self.arm_version not in (0, 1): + raise LookupError() + + return NodeReplacement.Identity(self) \ No newline at end of file