Open ZenRepublic opened 7 months ago
I'm currently in the middle of some crazy shifts (5 consecutive days of 12 hour shifts) at work. I will figure out what's going on with it as soon as I possibly can. I'll start poking at it right now and hopefully have a solution tomorrow around this time or before. I'll add a comment here with what I find and hopefully a PR around the same time.
I will point out that the tool requires you use a raycast that sends the correct data to the panels. There should be a working example raycast script in the demo files included with the plugin. The panels will not simply respond to mouse input automatically because they are designed to work isolated in the game environment (I use this in my VR projects).
Could you also please tell me what version of Godot you're using?
So please let me know if you need some guide on how to interface with the panels.
No worries. Btw, I want to suggest some changes to make the code lighter and much more readable.
in the 3d_panel script, I have done the following:
`var last_pos:Vector2 = Vector2.ZERO func laser_input(event:InputEvent,collision_point:Vector3):
if event is InputEventMouseMotion or event is InputEventMouseButton:
var quad_size = mesh.mesh.size
# Convert GLOBAL collision point from to be in local space of the panel
var mouse_pos3D = to_local(collision_point) # data.position must be global
var mouse_pos2D = Vector2(mouse_pos3D.x, mouse_pos3D.z)
# Translate the 2D mouse position to the center of the quad
# by adding half of the quad size to both x and y coordinates.
mouse_pos2D.x += quad_size.x / 2
mouse_pos2D.y += quad_size.y / 2
# Normalize the mouse position to be within the quad size
mouse_pos2D.x = mouse_pos2D.x / quad_size.x
mouse_pos2D.y = mouse_pos2D.y / quad_size.y
# Convert the 2D mouse position to viewport coordinates
mouse_pos2D.x = mouse_pos2D.x * viewport.size.x
mouse_pos2D.y = mouse_pos2D.y * viewport.size.y
# Sets the position of the event to the calculated mouse position in 2D space.
event.position = mouse_pos2D
event.global_position = mouse_pos2D
if event is InputEventMouseMotion:
event.relative = last_pos-mouse_pos2D
last_pos = mouse_pos2D
viewport.push_input(event)`
and the raycast example script then could be watered down to simple as this:
`extends RayCast3D
var curr_panel:Panel3D
func _process(delta: float) -> void: var cam = get_viewport().get_camera_3d() global_position = cam.global_position target_position = cam.project_ray_normal(get_viewport().get_mouse_position())*10.0
if is_colliding():
var colliding_obj = get_collider()
if colliding_obj is Panel3D:
curr_panel = colliding_obj as Panel3D
else:
curr_panel=null
else:
curr_panel=null
func _unhandled_input(event: InputEvent) -> void: if curr_panel == null: return
#if event is InputEventMouseMotion or event is InputEventMouseButton:
curr_panel.laser_input(event,get_collision_point())
`
maybe you could update when youfind time. I thought adding relative position would for sure get hovering to work, but ehhhh didnt
ffs why dont these code snippets work xd
Instead of dumping code in a comment, why not submit a PR? If you do so, it would make it much easier for me to consider and pull your improvements, as long as they function. It would also make it so much easier for us to have a back-and-forth on the changes... and your name gets to be on the repo iirc.
okay let me know if i did it correctly xd
Hey, I have tried editing the code in so many ways, can't get the hovering of buttons to work still. Maybe we could talk about it and try to find a solution together?