-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexturevertex.go
108 lines (97 loc) · 1.92 KB
/
texturevertex.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
package main
import (
"strconv"
"strings"
)
// TextureVertex _ (vt)
type TextureVertex struct {
U float32
V float32
W float32
}
// Marshal _
func (tc *TextureVertex) Marshal(options MarshalOptions) string {
var sb strings.Builder
sb.WriteString("vt ")
sb.WriteString(strconv.FormatFloat(float64(tc.U), 'f', options.FloatPrecision, 32))
if options.OmitDefaultOptional && tc.V == 0 && tc.W == 0 {
return sb.String()
}
sb.WriteRune(' ')
sb.WriteString(strconv.FormatFloat(float64(tc.V), 'f', options.FloatPrecision, 32))
if options.OmitDefaultOptional && tc.W == 0 {
return sb.String()
}
sb.WriteRune(' ')
sb.WriteString(strconv.FormatFloat(float64(tc.W), 'f', options.FloatPrecision, 32))
return sb.String()
}
// UnmarshalTextureVertex _
func UnmarshalTextureVertex(v string) (vt TextureVertex, rest string, ok bool) {
if v == "" {
ok = false
return
}
if len(v) < 2 || v[0] != 'v' || v[1] != 't' {
ok = false
return
}
v, ok = skipSpaces(v[2:])
if !ok {
return
}
x, v, ok := parseFloat(v)
if !ok {
return
}
if v == "" {
vt = TextureVertex{x, 0, 0}
return
}
v, ok = skipSpaces(v)
if !ok {
return
}
if v == "" {
vt = TextureVertex{x, 0, 0}
return
}
y, v, ok := parseFloat(v)
if !ok {
return
}
if v == "" {
vt = TextureVertex{x, y, 0}
return
}
v, ok = skipSpaces(v)
if !ok {
return
}
if v == "" {
vt = TextureVertex{x, y, 0}
return
}
z, v, ok := parseFloat(v)
if !ok {
return
}
rest = v
vt = TextureVertex{x, y, z}
return
}
// func UnmarshalTextureVertex(s string) (*TextureVertex, error) {
// match := regTextureVertexFormat.FindStringSubmatch(s)
// if match == nil {
// return nil, ErrInvalidFormat
// }
// match = match[1:]
// args, _, err := parseFloatArguments(match, 1, 3)
// if err != nil {
// return nil, ErrInvalidArgument
// }
// for len(args) < 3 {
// args = append(args, 0)
// }
// return &TextureVertex{args[0], args[1], args[2]}, nil
// }