-
Notifications
You must be signed in to change notification settings - Fork 0
/
Face.gd
86 lines (67 loc) · 1.92 KB
/
Face.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
74
75
76
77
78
79
80
81
82
83
84
85
86
extends StaticBody
class_name Face
var mat = preload("res://FaceMaterial.tres")
var color = Color(0, 0, 0, 1)
var texture : ImageTexture
enum {TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT}
var side : int
func _ready():
mat = mat.duplicate(true)
$MeshInstance.material_override = mat
mat.albedo_color = color
mat.albedo_texture = texture
mat.emission = color
mat.emission_energy = 1.0
mat.emission_enabled = false
#func _process(delta):
# pass
func init_face(direction : Vector3):
match direction:
Vector3(1, 0, 0):
rotate(Vector3(0, 1, 0), PI / 2)
side = RIGHT
Vector3(-1, 0, 0):
rotate(Vector3(0, 1, 0), -PI / 2)
side = LEFT
Vector3(0, -1, 0):
rotate(Vector3(1, 0, 0), PI / 2)
side = BOTTOM
Vector3(0, 1, 0):
rotate(Vector3(1, 0, 0), -PI / 2)
side = TOP
Vector3(0, 0, -1):
rotate(Vector3(0, 1, 0), PI)
side = BACK
Vector3(0, 0, 1):
side = FRONT
round_transform()
color_face()
func round_transform():
var o = transform.origin
var b = transform.basis
var x = Vector3(stepify(b.x.x, 1), stepify(b.x.y, 1), stepify(b.x.z, 1))
var y = Vector3(stepify(b.y.x, 1), stepify(b.y.y, 1), stepify(b.y.z, 1))
var z = Vector3(stepify(b.z.x, 1), stepify(b.z.y, 1), stepify(b.z.z, 1))
o = Vector3(stepify(o.x, 0.5), stepify(o.y, 0.5), stepify(o.z, 0.5))
transform = Transform(x, y, z, o).orthonormalized()
func color_face():
if get_parent().get_parent().show_textures:
set_texture(get_parent().get_parent().textures[side])
set_color(Color(1, 1, 1), false)
else:
set_texture(null)
set_color(get_parent().get_parent().colors[side])
func set_color(c : Color, emission : bool = true):
color = c
mat.albedo_color = color
if emission:
mat.emission = color
else:
mat.emission = Color(0, 0, 0)
func set_texture(t : Texture):
texture = t
mat.albedo_texture = texture
mat.emission_texture = texture
func set_face_uv(scale : Vector3, offset : Vector3):
mat.uv1_scale = scale
mat.uv1_offset = offset