1
This commit is contained in:
56
BITKit/Scripts/UX/UXBasedModelViewer.cs
Normal file
56
BITKit/Scripts/UX/UXBasedModelViewer.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public partial class UXBasedModelViewer : Control
|
||||
{
|
||||
[Export] private float delta = 0.1f;
|
||||
[Export] private Node3D model;
|
||||
|
||||
private readonly ValidHandle _isEnabled = new();
|
||||
|
||||
private Vector2 _velocity;
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
MouseEntered += () => _isEnabled.RemoveDisableElements(this);
|
||||
MouseExited += () => _isEnabled.AddDisableElements(this);
|
||||
_isEnabled.SetDisableElements(1,false);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
base._Process(delta);
|
||||
_isEnabled.SetDisableElements(1,!Visible);
|
||||
if (_velocity == default) return;
|
||||
|
||||
var rotate = _velocity * this.delta * (float)delta;
|
||||
|
||||
model.RotateX(Mathf.DegToRad(rotate.Y));
|
||||
model.RotateY(Mathf.DegToRad(rotate.X));
|
||||
|
||||
_velocity = Vector2.Zero;
|
||||
|
||||
|
||||
}
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
base._Input(@event);
|
||||
switch (@event)
|
||||
{
|
||||
case InputEventMouseButton button:
|
||||
_isEnabled.SetElements(this,button.Pressed);
|
||||
break;
|
||||
case InputEventMouseMotion motion when _isEnabled:
|
||||
_velocity += motion.Relative;
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
model.RotationDegrees = Vector3.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
19
BITKit/Scripts/UX/UXControl.cs
Normal file
19
BITKit/Scripts/UX/UXControl.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public partial class UXControl : Control
|
||||
{
|
||||
private readonly Queue<ImageTexture> _imageTextureQueue = new();
|
||||
public void DrawTextureRect(ImageTexture texture)=>_imageTextureQueue.Enqueue(texture);
|
||||
public override void _Draw()
|
||||
{
|
||||
while (_imageTextureQueue.TryDequeue(out var texture))
|
||||
{
|
||||
DrawTextureRect(texture, GetRect(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user