Skip to content

Commit

Permalink
screen space vector at
Browse files Browse the repository at this point in the history
  • Loading branch information
t3du committed Nov 13, 2024
1 parent 7df0d65 commit b5997e2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
44 changes: 26 additions & 18 deletions Sources/armory/logicnode/ScreenToWorldSpaceNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
33 changes: 26 additions & 7 deletions blender/arm/logicnode/math/LN_screen_to_world_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,43 @@


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):
layout.prop(self, 'property0') # Separator Out
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
Expand All @@ -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)

0 comments on commit b5997e2

Please sign in to comment.