-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlod.go
100 lines (85 loc) · 2.76 KB
/
lod.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
package osg
import (
"github.com/flywave/go-osg/model"
)
func setCenterMode(obj interface{}, pro interface{}) {
obj.(model.LodInterface).SetCmode(pro.(uint32))
}
func getCenterMode(obj interface{}) interface{} {
return obj.(model.LodInterface).GetCmode()
}
func setRangeMode(obj interface{}, pro interface{}) {
obj.(model.LodInterface).SetRmode(pro.(uint32))
}
func getRangeMode(obj interface{}) interface{} {
return obj.(model.LodInterface).GetRmode()
}
func checkUserCenter(obj interface{}) bool {
lod := obj.(model.LodInterface)
md := *lod.GetCmode()
return md == model.USERDEFINEDCENTER || md == model.UNIONOFBOUNDINGSPHEREANDUSERDEFINED
}
func readUserCenter(is *OsgIstream, obj interface{}) {
lod := obj.(model.LodInterface)
ct := [3]float64{}
var r float64
is.Read(&ct)
is.Read(&r)
lod.SetCenter([3]float32{float32(ct[0]), float32(ct[1]), float32(ct[2])})
lod.SetRadius(float32(r))
}
func writeUserCenter(os *OsgOstream, obj interface{}) {
lod := obj.(model.LodInterface)
os.Write(*lod.GetCenter())
os.Write(*lod.GetRadius())
os.Write(os.CRLF)
}
func rangeListChecker(obj interface{}) bool {
lod := obj.(model.LodInterface)
return len(lod.GetRangeList()) > 0
}
func rangeListReader(is *OsgIstream, obj interface{}) {
lod := obj.(model.LodInterface)
size := is.ReadSize()
is.Read(is.BEGINBRACKET)
lod.SetRangeList(make([][2]float32, size, size))
for i := 0; i < size; i++ {
var min, max float32
is.Read(&min)
is.Read(&max)
lod.SetRange(i, min, max)
}
is.Read(is.ENDBRACKET)
}
func rangeListWriter(os *OsgOstream, obj interface{}) {
lod := obj.(model.LodInterface)
size := len(lod.GetRangeList())
os.Write(size)
os.Write(os.BEGINBRACKET)
for i := 0; i < size; i++ {
os.Write(lod.GetRangeList()[i][0])
os.Write(lod.GetRangeList()[i][1])
}
os.Write(os.ENDBRACKET)
os.Write(os.CRLF)
}
func init() {
fn := func() interface{} {
return nil
}
wrap := NewObjectWrapper("LOD", fn, "osg::Object osg::Node osg::Group osg::LOD")
ser1 := NewEnumSerializer("CenterMode", getCenterMode, setCenterMode)
ser1.Add("USEBOUNDINGSPHERECENTER", model.USEBOUNDINGSPHERECENTER)
ser1.Add("USERDEFINEDCENTER", model.USERDEFINEDCENTER)
ser1.Add("UNIONOFBOUNDINGSPHEREANDUSERDEFINED", model.UNIONOFBOUNDINGSPHEREANDUSERDEFINED)
wrap.AddSerializer(ser1, RWENUM)
ser2 := NewUserSerializer("UserCenter", checkUserCenter, readUserCenter, writeUserCenter)
wrap.AddSerializer(ser2, RWENUM)
ser3 := NewEnumSerializer("RangeMode", getRangeMode, setRangeMode)
ser3.Add("DISTANCEFROMEYEPOINT", model.DISTANCEFROMEYEPOINT)
ser3.Add("PIXELSIZEONSCREEN", model.PIXELSIZEONSCREEN)
wrap.AddSerializer(ser3, RWENUM)
seruser := NewUserSerializer("RangeList", rangeListChecker, rangeListReader, rangeListWriter)
wrap.AddSerializer(seruser, RWUSER)
GetObjectWrapperManager().AddWrap(wrap)
}