-
Notifications
You must be signed in to change notification settings - Fork 0
/
light.go
135 lines (116 loc) · 3.83 KB
/
light.go
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package controllers
import (
"strings"
"strconv"
"github.com/revel/revel"
"github.com/sutthirak/labyrinth/data"
)
type SceneLightController struct {
*revel.Controller
}
func (c SceneLightController) AddLight(sceneHex string,
name string,
kind string,
positionX string,
positionY string,
positionZ string,
directionX string,
directionY string,
directionZ string,
diffuseRed string,
diffuseGreen string,
diffuseBlue string,
specularRed string,
specularGreen string,
specularBlue string,
angle string,
exponent string,
intensity string) revel.Result {
c.Validation.Required(name).Message("Please enter your light name")
c.Validation.Required(kind).Message("Please enter your light kind")
if c.Validation.HasErrors(){
c.Validation.Keep()
return c.Redirect("/admin/scenes/%s?tab=light",sceneHex)
}
scene := data.GetSceneByHex(sceneHex)
light := data.Light{}
light.Name = strings.Replace(name," ","_",-1)
light.RefName = strings.Replace(name," ","_",-1) + "_" + strconv.Itoa(len(scene.Lights))
light.Kind = kind
light.Properties = make(map[string]string)
light.Properties["x"] = positionX
light.Properties["y"] = positionY
light.Properties["z"] = positionZ
light.Properties["diffusered"] = diffuseRed
light.Properties["diffusegreen"] = diffuseGreen
light.Properties["diffuseblue"] = diffuseBlue
light.Properties["specularred"] = specularRed
light.Properties["speculargreen"] = specularGreen
light.Properties["specularblue"] = specularBlue
light.Properties["intensity"] = intensity
if kind == "SPOT_LIGHT" {
light.Properties["directionx"] = directionX
light.Properties["directiony"] = directionY
light.Properties["directionz"] = directionZ
light.Properties["angle"] = angle
light.Properties["exponent"] = exponent
}
scene.Lights = append(scene.Lights,light)
data.SaveScene(&scene)
c.Flash.Success("Done!")
return c.Redirect("/admin/scenes/%s?tab=light",scene.Id.Hex())
}
func (c SceneLightController) UpdateLight(sceneHex string,
elementNumber int,
positionX string,
positionY string,
positionZ string,
directionX string,
directionY string,
directionZ string,
diffuseRed string,
diffuseGreen string,
diffuseBlue string,
specularRed string,
specularGreen string,
specularBlue string,
angle string,
exponent string,
intensity string) revel.Result {
scene := data.GetSceneByHex(sceneHex)
light := scene.Lights[elementNumber]
light.Properties["x"] = positionX
light.Properties["y"] = positionY
light.Properties["z"] = positionZ
light.Properties["diffusered"] = diffuseRed
light.Properties["diffusegreen"] = diffuseGreen
light.Properties["diffuseblue"] = diffuseBlue
light.Properties["specularred"] = specularRed
light.Properties["speculargreen"] = specularGreen
light.Properties["specularblue"] = specularBlue
light.Properties["intensity"] = intensity
if light.Kind == "SPOT_LIGHT" {
light.Properties["directionx"] = directionX
light.Properties["directiony"] = directionY
light.Properties["directionz"] = directionZ
light.Properties["angle"] = angle
light.Properties["exponent"] = exponent
}
s := data.SaveScene(&scene)
c.Flash.Success("Done!")
return c.Redirect("/admin/scenes/%s?tab=light",s.Id.Hex())
}
func (c SceneLightController) DeleteLight(sceneHex string,
elementNumber int) revel.Result{
scene := data.GetSceneByHex(sceneHex)
lights := make([]data.Light,0)
for index , element := range scene.Lights {
if index != elementNumber {
lights = append(lights,element)
}
}
scene.Lights = lights
data.SaveScene(&scene)
c.Flash.Success("Done!")
return c.RenderText("success")
}