-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtileset.go
133 lines (113 loc) · 3.09 KB
/
tileset.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
package tile3d
import (
"encoding/json"
"errors"
"io"
)
const (
TILE_REFINE_ADD = "ADD"
TILE_REFINE_REPLACE = "REPLACE"
)
var (
TileDefaultTransform = [16]float64{1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}
)
type Asset struct {
Version string `json:"version"`
TilesetVersion string `json:"tilesetVersion,omitempty"`
GltfUpAxis string `json:"gltfUpAxis,omitempty"`
}
type Content struct {
Url string `json:"uri"`
}
type Schema struct {
Maximum float64 `json:"maximum,omitempty"`
Minimum float64 `json:"minimum,omitempty"`
}
type BoundingVolume struct {
Region *[]float64 `json:"region,omitempty"`
Box *[]float64 `json:"box,omitempty"`
Sphere *[]float64 `json:"sphere,omitempty"`
}
func (b *BoundingVolume) SetBox(box []float64) error {
if len(box) != 12 {
return errors.New("box must 12 element")
}
if b.Region != nil || b.Sphere != nil {
b.Region = nil
b.Sphere = nil
}
b.Box = &box
return nil
}
func (b *BoundingVolume) SetRegion(region []float64) error {
if len(region) != 6 {
return errors.New("region must 6 element")
}
if b.Box != nil || b.Sphere != nil {
b.Box = nil
b.Sphere = nil
}
b.Region = ®ion
return nil
}
func (b *BoundingVolume) SetSphere(sphere []float64) error {
if len(sphere) != 4 {
return errors.New("sphere must 4 element")
}
if b.Box != nil || b.Region != nil {
b.Box = nil
b.Region = nil
}
b.Sphere = &sphere
return nil
}
func (b *BoundingVolume) GetRegion() []float64 {
return *b.Region
}
func (b *BoundingVolume) GetBox() []float64 {
return *b.Box
}
func (b *BoundingVolume) GetSphere() []float64 {
return *b.Sphere
}
func (b *BoundingVolume) GetData() []float64 {
if b.Region != nil {
return *b.Region
}
if b.Box != nil {
return *b.Box
}
if b.Sphere != nil {
return *b.Sphere
}
return nil
}
const MULTIPLE_CONTENTS = "3DTILES_multiple_contents"
type MultipeContent []*Content
type Tile struct {
Content *Content `json:"content,omitempty"`
BoundingVolume BoundingVolume `json:"boundingVolume,omitempty"`
ViewerRequestVolume *BoundingVolume `json:"viewerRequestVolume,omitempty"`
GeometricError float64 `json:"geometricError"`
Refine string `json:"refine"`
Transform *[16]float64 `json:"transform,omitempty"`
Children []Tile `json:"children,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
type Tileset struct {
Asset Asset `json:"asset"`
GeometricError float64 `json:"geometricError"`
Root Tile `json:"root"`
Properties *map[string]Schema `json:"properties,omitempty"`
ExtensionsUsed []string `json:"extensionsUsed,omitempty"`
ExtensionsRequired []string `json:"extensionsRequired,omitempty"`
}
func (ts *Tileset) ToJson() (string, error) {
b, e := json.Marshal(ts)
return string(b), e
}
func TilesetFromJson(data io.Reader) *Tileset {
var ts *Tileset
json.NewDecoder(data).Decode(&ts)
return ts
}