start working on graph

This commit is contained in:
Nitwel 2024-04-10 20:23:19 +02:00
parent 0cf4b932f6
commit b9dae18042
6 changed files with 191 additions and 2 deletions

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3 uid="uid://eecv28y6jxk4"] [gd_scene load_steps=18 format=3 uid="uid://eecv28y6jxk4"]
[ext_resource type="PackedScene" uid="uid://clc5dre31iskm" path="res://addons/godot-xr-tools/xr/start_xr.tscn" id="1_i4c04"] [ext_resource type="PackedScene" uid="uid://clc5dre31iskm" path="res://addons/godot-xr-tools/xr/start_xr.tscn" id="1_i4c04"]
[ext_resource type="Script" path="res://content/main.gd" id="1_uvrd4"] [ext_resource type="Script" path="res://content/main.gd" id="1_uvrd4"]
@ -12,6 +12,7 @@
[ext_resource type="PackedScene" uid="uid://lrehk38exd5n" path="res://content/system/keyboard/keyboard.tscn" id="9_e5n3p"] [ext_resource type="PackedScene" uid="uid://lrehk38exd5n" path="res://content/system/keyboard/keyboard.tscn" id="9_e5n3p"]
[ext_resource type="PackedScene" uid="uid://cbemihbxkd4ll" path="res://content/system/house/house.tscn" id="9_np6mw"] [ext_resource type="PackedScene" uid="uid://cbemihbxkd4ll" path="res://content/system/house/house.tscn" id="9_np6mw"]
[ext_resource type="PackedScene" uid="uid://bhyddd1f0ry1x" path="res://content/ui/onboarding/onboarding.tscn" id="12_uq2nj"] [ext_resource type="PackedScene" uid="uid://bhyddd1f0ry1x" path="res://content/ui/onboarding/onboarding.tscn" id="12_uq2nj"]
[ext_resource type="PackedScene" uid="uid://cwvykoymlrrel" path="res://content/ui/components/line_chart/line_chart.tscn" id="13_iw50x"]
[sub_resource type="Sky" id="Sky_vhymk"] [sub_resource type="Sky" id="Sky_vhymk"]
sky_material = ExtResource("5_wgwf8") sky_material = ExtResource("5_wgwf8")
@ -36,7 +37,7 @@ material = SubResource("StandardMaterial3D_m58yb")
size = Vector3(0.01, 0.01, 0.01) size = Vector3(0.01, 0.01, 0.01)
[node name="Main" type="Node3D"] [node name="Main" type="Node3D"]
transform = Transform3D(1, -0.000296142, 0.000270963, 0.000296143, 1, -4.61078e-06, -0.000270962, 4.67014e-06, 1, 0, 0, 0) transform = Transform3D(1, -0.000296142, 0.000270963, 0.000296143, 1, -4.5899e-06, -0.000270962, 4.67014e-06, 1, 0, 0, 0)
script = ExtResource("1_uvrd4") script = ExtResource("1_uvrd4")
[node name="WorldEnvironment" type="WorldEnvironment" parent="."] [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
@ -87,4 +88,7 @@ transform = Transform3D(0.499999, -0.000139169, -6.50204e-05, 5.24307e-05, 0.353
[node name="Onboarding" parent="." instance=ExtResource("12_uq2nj")] [node name="Onboarding" parent="." instance=ExtResource("12_uq2nj")]
transform = Transform3D(0.999999, -1.39632e-11, 0, 9.48097e-12, 0.999999, 0, 0, 0, 0.999999, -0.529594, 0.820154, -0.600147) transform = Transform3D(0.999999, -1.39632e-11, 0, 9.48097e-12, 0.999999, 0, 0, 0, 0.999999, -0.529594, 0.820154, -0.600147)
[node name="LineChart" parent="." instance=ExtResource("13_iw50x")]
transform = Transform3D(1, -7.21733e-11, 5.82077e-11, 4.42421e-11, 1, 0, 0, 9.09495e-13, 1, 0.000296143, 1, -4.5899e-06)
[editable path="XROrigin3D/XRControllerLeft"] [editable path="XROrigin3D/XRControllerLeft"]

View File

@ -0,0 +1,89 @@
@tool
extends Node3D
@onready var mesh: MeshInstance3D = $Line
@onready var plane: MeshInstance3D = $Plane
@onready var x_axis: Sprite3D = $XAxis
const RADIUS = 0.005
const STEPS = 5
@export var size: Vector2 = Vector2(0.5, 0.3)
var points = R.state([])
var minmax = R.computed(func(_arg):
if points.value.size() == 0:
return [Vector2(0, 0), Vector2(0, 0)]
var min=points.value[0]
var max=points.value[0]
for point in points.value:
min.x=min(min.x, point.x)
min.y=min(min.y, point.y)
max.x=max(max.x, point.x)
max.y=max(max.y, point.y)
return [min, max]
)
var relative_points = R.computed(func(_arg):
var min=minmax.value[0]
var max=minmax.value[1]
return points.value.map(func(point):
return Vector2(inverse_lerp(min.x, max.x, point.x), inverse_lerp(min.y, max.y, point.y))
)
)
func _ready():
for i in range(100):
points.value.append(Vector2(i, sin(i / 10.0)))
R.effect(func(_arg):
mesh.mesh=generate_mesh(relative_points.value)
)
plane.position = Vector3(size.x / 2, size.y / 2, -0.001)
plane.mesh.size = size
func generate_mesh(points: Array):
if points.size() < 2:
return null
var sf = SurfaceTool.new()
sf.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
for i in range(points.size() - 1):
var point = points[i]
var next_point = points[i + 1]
var angle = (next_point - point).angle_to(Vector2(1, 0))
var up = Vector2(0, 1).rotated( - angle)
var p0 = point + up * RADIUS * 2
var p1 = point + up * - RADIUS * 2
sf.add_vertex(Vector3(p0.x * size.x, p0.y * size.y, 0))
sf.add_vertex(Vector3(p1.x * size.x, p1.y * size.y, 0))
sf.index()
sf.generate_normals()
var _mesh = sf.commit()
sf.clear()
sf.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
for i in range(points.size() - 1):
var point = points[i]
sf.add_vertex(Vector3(point.x * size.x, point.y * size.y, RADIUS))
sf.add_vertex(Vector3(point.x * size.x, point.y * size.y, -RADIUS))
return sf.commit(_mesh)

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,10 @@
@tool
extends Control
func _draw():
draw_line(Vector2(380, 0), Vector2(380, 3000), Color(1, 1, 1), 10)
for i in range(100, 3000, 100):
draw_line(Vector2(350, i), Vector2(380, i), Color(1, 1, 1), 5)
draw_string_outline(get_theme_default_font(), Vector2(240, i + 15), str(i), HORIZONTAL_ALIGNMENT_RIGHT, 100, 40, 10, Color(0, 0, 0))
draw_string(get_theme_default_font(), Vector2(240, i + 15), str(i), HORIZONTAL_ALIGNMENT_RIGHT, 100, 40, Color(1, 1, 1))

View File

@ -0,0 +1,19 @@
[gd_scene load_steps=2 format=3 uid="uid://bs5wjs1sf67il"]
[ext_resource type="Script" path="res://content/ui/components/line_chart/x_axis.gd" id="1_5fiu5"]
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_5fiu5")
[node name="Label" type="Label" parent="."]
layout_mode = 0
offset_right = 40.0
offset_bottom = 20.0
theme_override_font_sizes/font_size = 50
text = "X Axis"

View File

@ -62,6 +62,7 @@ horizontal_alignment = 0
[node name="MinSlider" parent="Content" instance=ExtResource("4_d3xhb")] [node name="MinSlider" parent="Content" instance=ExtResource("4_d3xhb")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0.01, 0.2) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0.01, 0.2)
value = 0.0
step = 1.0 step = 1.0
show_label = true show_label = true
size = Vector3(10, 0.4, 1) size = Vector3(10, 0.4, 1)
@ -76,6 +77,7 @@ horizontal_alignment = 0
[node name="MaxSlider" parent="Content" instance=ExtResource("4_d3xhb")] [node name="MaxSlider" parent="Content" instance=ExtResource("4_d3xhb")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0.01, 0.24) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.06, 0.01, 0.24)
value = 0.0
step = 1.0 step = 1.0
show_label = true show_label = true
size = Vector3(10, 0.4, 1) size = Vector3(10, 0.4, 1)