-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
vector_3d.gd
73 lines (57 loc) · 2.09 KB
/
vector_3d.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
@tool
class_name Vector3D extends Node3D
@export_custom(PROPERTY_HINT_NONE, "suffix:m") var data := Vector3.UP:
set(new_data):
if data.is_zero_approx():
return
data = new_data
_stem.mesh.height = data.length() - pointer_height
_stem.position.y = 0.5 * _stem.mesh.height
_pointer.position.y = _stem.mesh.height + 0.5 * pointer_height
_pivot.rotation = Vector3.ZERO
if data.abs().normalized().is_equal_approx(Vector3.UP):
if data.sign().y < 0.0:
_pivot.rotation.z = PI
else:
var rotate_axis := Vector3.UP.cross(data).normalized()
_pivot.rotate(rotate_axis, Vector3.UP.angle_to(data))
@export_category("Cosmetics")
@export var color := Color.WHITE:
set(new_color):
color = new_color
_stem.mesh.surface_get_material(0).albedo_color = color
@export_range(0.001, 1.0, 0.001, "or_greater", "suffix:m") var stem_radius := 0.05:
set(new_stem_radius):
stem_radius = new_stem_radius
_stem.mesh.top_radius = stem_radius
_stem.mesh.bottom_radius = _stem.mesh.top_radius
@export_range(0.001, 1.0, 0.001, "or_greater", "suffix:m") var pointer_radius := 0.1:
set(new_pointer_radius):
pointer_radius = new_pointer_radius
_pointer.mesh.bottom_radius = pointer_radius
@export_range(0.001, 1.0, 0.001, "or_greater", "suffix:m") var pointer_height := 0.3:
set(new_pointer_height):
if new_pointer_height > data.length():
return
pointer_height = new_pointer_height
_pointer.mesh.height = pointer_height
_pointer.position.y = _stem.mesh.height + 0.5 * pointer_height
data = data
var _pivot := Node3D.new()
var _stem := MeshInstance3D.new()
var _pointer := MeshInstance3D.new()
func _ready() -> void:
add_child(_pivot)
_pivot.add_child(_stem)
_stem.mesh = CylinderMesh.new()
var material := StandardMaterial3D.new()
material.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
_stem.mesh.surface_set_material(0, material)
_pivot.add_child(_pointer)
_pointer.mesh = CylinderMesh.new()
_pointer.mesh.top_radius = 0.0
_pointer.mesh.surface_set_material(0, _stem.mesh.material)
stem_radius = stem_radius
pointer_radius = pointer_radius
pointer_height = pointer_height
data = data