forked from icosa-foundation/open-brush
/
ToolScript.ScatterCubes.lua
69 lines (53 loc) · 1.85 KB
/
ToolScript.ScatterCubes.lua
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
Settings = {
description="Random hull brush cubes as you draw",
space="canvas"
}
Parameters = {
maxSize={label="Maximum Size", type="float", min=0.01, max=1, default=0.25},
spread={label="Spread", type="float", min=0.01, max=1, default=0.25},
amount={label="Amount", type="float", min=0.001, max=1, default=0.25},
}
function Start()
originalBrushType = Brush.type
originalBrushSize = Brush.size
Brush.type = "Shiny Hull"
Brush.size = 0.1
end
function Main()
if Brush.triggerIsPressed then
Brush.colorRgb = Color:New(Random.value, Random.value, Random.value)
origin = Brush.position
if Random.value < amount then
randomOffset = Random.insideUnitSphere * spread
return drawCube(
origin + randomOffset,
Random.value * maxSize
)
end
end
end
function End()
-- If the user hasn't changed settings then restore the previous values
if Brush.type == "Shiny Hull" then
Brush.type = originalBrushType
end
if Brush.size == 0.1 then
Brush.size = originalBrushSize
end
end
function drawCube(center, size)
points = Path:New()
-- front face
points:Insert(center:Add(-size, size, size)) -- top left
points:Insert(center:Add(size, size, size)) -- top right
points:Insert(center:Add(size, -size, size)) -- bottom right
points:Insert(center:Add(-size, -size, size)) -- bottom left
points:Insert(center:Add(-size, size, size)) -- top left
-- back face
points:Insert(center:Add(size, size, -size)) -- top back
points:Insert(center:Add(-size, size, -size)) -- top left
points:Insert(center:Add(-size, -size, -size)) -- bottom left
points:Insert(center:Add(size, -size, -size)) -- bottom back
points:Insert(center:Add(size, size, -size)) -- top back
return points
end