-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
unlit.go
43 lines (36 loc) · 990 Bytes
/
unlit.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
package unlit
import (
"encoding/json"
"github.com/qmuntal/gltf"
)
const (
// ExtensionName defines the Unlit unique key.
ExtensionName = "KHR_materials_unlit"
)
// Unmarshal decodes the json data into the correct type.
func Unmarshal(data []byte) (any, error) {
u := new(Unlit)
err := json.Unmarshal(data, u)
return u, err
}
func init() {
gltf.RegisterExtension(ExtensionName, Unmarshal)
}
// Unlit defines an unlit shading model.
// When present, the extension indicates that a material should be unlit.
// Additional properties on the extension object are allowed, but may lead to undefined behaviour in conforming viewers.
type Unlit map[string]any
// UnmarshalJSON unmarshal the pbr with the correct default values.
func (u *Unlit) UnmarshalJSON(data []byte) error {
if len(*u) == 0 {
*u = make(Unlit)
}
var raw map[string]json.RawMessage
err := json.Unmarshal(data, &raw)
if err == nil {
for key, value := range raw {
(*u)[key] = value
}
}
return err
}