-
Notifications
You must be signed in to change notification settings - Fork 1
/
figure_6_mesh.gd
104 lines (88 loc) · 2.46 KB
/
figure_6_mesh.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
extends MeshInstance3D
@onready var point_view: PointView = $"../PointView";
var surface_tool := SurfaceTool.new();
func _ready():
point_view.add_point(Vector3(0,0,0), Colors.PURPLE_B);
point_view.add_point(Vector3(1,0,0), Colors.BLUE_B);
point_view.add_point(Vector3(0,1,0), Colors.BLUE_B);
point_view.add_point(Vector3(0,0,1), Colors.BLUE_B);
surface_tool.begin(Mesh.PRIMITIVE_TRIANGLES);
surface_tool.set_color(Colors.BLUE_B);
add_reversed_quad(Vector3i(0,0,0), 0);
add_reversed_quad(Vector3i(0,0,0), 1);
add_reversed_quad(Vector3i(0,0,0), 2);
mesh = surface_tool.commit();
func add_quad(index: Vector3i, axis_index: int):
var points = get_quad_points(index, axis_index);
surface_tool.set_normal(AXIS[axis_index]);
add_vertex(points[0])
add_vertex(points[1])
add_vertex(points[2])
add_vertex(points[0])
add_vertex(points[2])
add_vertex(points[3])
func add_reversed_quad(index: Vector3i, axis_index: int):
var points = get_quad_points(index, axis_index);
surface_tool.set_normal(-AXIS[axis_index]);
add_vertex(points[0])
add_vertex(points[2])
add_vertex(points[1])
add_vertex(points[0])
add_vertex(points[3])
add_vertex(points[2])
func get_quad_points(index: Vector3i, axis_index: int):
return [
index + QUAD_POINTS[axis_index][0],
index + QUAD_POINTS[axis_index][1],
index + QUAD_POINTS[axis_index][2],
index + QUAD_POINTS[axis_index][3],
];
func add_vertex(index: Vector3i):
surface_tool.add_vertex(Vector3(index) + Vector3.ONE * 0.5);
# Constants
const AXIS := [
Vector3i(1,0,0),
Vector3i(0,1,0),
Vector3i(0,0,1),
];
# The 4 relative indexes of the corners of a Quad that is orthogonal to each axis
const QUAD_POINTS := [
# x axis
[
Vector3i(0,0,-1),
Vector3i(0,-1,-1),
Vector3i(0,-1,0),
Vector3i(0,0,0)
],
# y axis
[
Vector3i(0,0,-1),
Vector3i(0,0,0),
Vector3i(-1,0,0),
Vector3i(-1,0,-1)
],
# z axis
[
Vector3i(0,0,0),
Vector3i(0,-1,0),
Vector3i(-1,-1,0),
Vector3i(-1,0,0)
],
];
const EDGES := [
# Edges on min Z axis
[Vector3i(0,0,0),Vector3i(1,0,0)],
[Vector3i(1,0,0),Vector3i(1,1,0)],
[Vector3i(1,1,0),Vector3i(0,1,0)],
[Vector3i(0,1,0),Vector3i(0,0,0)],
# Edges on max Z axis
[Vector3i(0,0,1),Vector3i(1,0,1)],
[Vector3i(1,0,1),Vector3i(1,1,1)],
[Vector3i(1,1,1),Vector3i(0,1,1)],
[Vector3i(0,1,1),Vector3i(0,0,1)],
# Edges connecting min Z to max Z
[Vector3i(0,0,0),Vector3i(0,0,1)],
[Vector3i(1,0,0),Vector3i(1,0,1)],
[Vector3i(1,1,0),Vector3i(1,1,1)],
[Vector3i(0,1,0),Vector3i(0,1,1)],
]