-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlight.go
More file actions
105 lines (92 loc) · 2.31 KB
/
Copy pathlight.go
File metadata and controls
105 lines (92 loc) · 2.31 KB
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
package topotypes
import (
"encoding/json"
"errors"
)
type LightInterface interface {
GetLight() string
}
type TopoLight struct {
Topos
Light string `json:"light"`
Color []uint8 `json:"color"`
Instensity float64 `json:"instensity"`
}
func (lt *TopoLight) GetLight() string {
return lt.Light
}
type TopoAreaLight struct {
TopoLight
Width float64 `json:"width"`
Height float64 `json:"height"`
}
func NewTopoAreaLight() *TopoAreaLight {
l := TopoAreaLight{}
l.Light = LightTypeToString(TOPO_LIGHT_MODE_AREA)
l.Type = TopoTypeToString(TOPO_TYPE_LIGHT)
return &l
}
type TopoDirectionalLight struct {
TopoLight
Dir [3]float64 `json:"dir"`
Shadow int `json:"shadow"`
Strength *float64 `json:"strength,omitempty"`
Bias *float64 `json:"bias,omitempty"`
Softness *float64 `json:"softness,omitempty"`
SoftnessFade *float64 `json:"softness-fade,omitempty"`
}
func NewTopoDirectionalLight() *TopoDirectionalLight {
l := TopoDirectionalLight{}
l.Light = LightTypeToString(TOPO_LIGHT_MODE_DIRECTIONAL)
l.Type = TopoTypeToString(TOPO_TYPE_LIGHT)
return &l
}
type TopoPointLight struct {
TopoLight
Distance float64 `json:"distance"`
}
func NewTopoPointLight() *TopoPointLight {
l := TopoPointLight{}
l.Light = LightTypeToString(TOPO_LIGHT_MODE_POINT)
l.Type = TopoTypeToString(TOPO_TYPE_LIGHT)
return &l
}
type TopoSpotLight struct {
TopoLight
Dir [3]float64 `json:"dir"`
Angle float64 `json:"angle"`
Exponent float64 `json:"exponent"`
Distance float64 `json:"distance"`
}
func NewTopoSpotLight() *TopoSpotLight {
l := TopoSpotLight{}
l.Light = LightTypeToString(TOPO_LIGHT_MODE_SPOT)
l.Type = TopoTypeToString(TOPO_TYPE_LIGHT)
return &l
}
func LightUnmarshal(js []byte) (ToposInterface, error) {
lt := TopoLight{}
e := json.Unmarshal(js, <)
if e != nil {
return nil, e
}
var inter ToposInterface
ty := StringToLightType(lt.Light)
switch ty {
case TOPO_LIGHT_MODE_SPOT:
inter = NewTopoSpotLight()
case TOPO_LIGHT_MODE_POINT:
inter = NewTopoPointLight()
case TOPO_LIGHT_MODE_DIRECTIONAL:
inter = NewTopoDirectionalLight()
case TOPO_LIGHT_MODE_AREA:
inter = NewTopoAreaLight()
default:
return nil, errors.New("not support topo type")
}
e = json.Unmarshal(([]byte)(js), inter)
if e != nil {
return nil, e
}
return inter, nil
}