-
Notifications
You must be signed in to change notification settings - Fork 1
/
GenerateCubes.gd
57 lines (50 loc) · 1.67 KB
/
GenerateCubes.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
extends Spatial
var pointColor = SpatialMaterial.new()
var blockColor = SpatialMaterial.new()
# Called when the node enters the scene tree for the first time.
func _ready():
pointColor.albedo_color = Color(.25, .82, .17)
blockColor.albedo_color = Color(.08, .46, 1)
makeBlocks(5, 5, 5)
func makeBlocks(numOfCubesX, numOfCubesY, numOfCubesZ, highlightPoints = true):
var block = null
var offset = 2
for i in range(numOfCubesX):
var xOffset = offset * i
block = MeshInstance.new()
block.mesh = CubeMesh.new()
block.set_surface_material(0, blockColor)
highlightPoints(block)
block.translate(Vector3(xOffset, 0, 0))
self.add_child(block)
for j in range(numOfCubesY):
var yOffset = offset * j
block = MeshInstance.new()
block.mesh = CubeMesh.new()
block.set_surface_material(0, blockColor)
highlightPoints(block)
block.translate(Vector3(xOffset, yOffset, 0))
self.add_child(block)
for k in range(numOfCubesZ):
var zOffset = offset * k
block = MeshInstance.new()
block.mesh = CubeMesh.new()
block.set_surface_material(0, blockColor)
highlightPoints(block)
block.translate(Vector3(xOffset, yOffset, zOffset))
self.add_child(block)
func highlightPoints(block):
for i in range(8):
var point = MeshInstance.new()
point.mesh = SphereMesh.new();
point.set_surface_material(0, pointColor)
point.set_scale(Vector3(.1, .1, .1))
point.translate(block.get_aabb().get_endpoint(i) / .1)
block.add_child(point)
func createPointCube(size):
var point = MeshInstance.new()
point.mesh = SphereMesh.new();
point.set_surface_material(0, pointColor)
point.set_scale(Vector3(.1, .1, .1))
for i in range(8):
point.translate(size / .1)