Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SensorCoords node upgrade #3113

Merged
merged 2 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions armory/Sources/armory/logicnode/SensorCoordsNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,27 @@ class SensorCoordsNode extends LogicNode {
}

override function get(from: Int): Dynamic {
var sensor = iron.system.Input.getSensor();
coords.x = sensor.x;
coords.y = sensor.y;
coords.z = sensor.z;
return coords;
#if kha_html5
switch(from){
case 0:
var sensor = iron.system.Input.getSensor();
coords.x = sensor.x;
coords.y = sensor.y;
coords.z = sensor.z;
return coords;
case 1:
var gyro = kha.input.Sensor.get(kha.input.SensorType.Gyroscope);
gyro.notify(function listener(x: Float, y: Float, z: Float) {
coords.x = x;
coords.y = y;
coords.z = z;
});
return coords;
case 2:
return js.Browser.window.orientation;
default: return null;
}
#end
return null;
}
}
23 changes: 20 additions & 3 deletions armory/blender/arm/logicnode/input/LN_sensor_coords.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
from arm.logicnode.arm_nodes import *

class SensorCoordsNode(ArmLogicTreeNode):
"""TO DO."""
"""Sensor Coords Node: Retrieves and provides real-time information from the device's sensors.

@output Accelerometer Coords: Provides the acceleration data from the device's accelerometer,
including values for the X, Y, and Z axes.

@output Gyroscope Coords: Returns the rotational speed data from the device's gyroscope,
including values for the X, Y, and Z axes.

@output Device Orientation: Offers information about the overall orientation of the device represented in degrees (°).
"""
bl_idname = 'LNSensorCoordsNode'
bl_label = 'Sensor Coords'
arm_section = 'sensor'
arm_version = 1
arm_version = 2

def arm_init(self, context):
self.add_output('ArmVectorSocket', 'Coords')
self.add_output('ArmVectorSocket', 'Accelerometer Coords')
self.add_output('ArmVectorSocket', 'Gyroscope Coords')
self.add_output('ArmIntSocket', 'Device Orientation')

def get_replacement_node(self, node_tree: bpy.types.NodeTree):
if self.arm_version not in (0, 1):
raise LookupError()

return NodeReplacement.Identity(self)