Skip to content

Commit

Permalink
upscale uint8 on ReadColor64
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Dec 21, 2020
1 parent bd8f1d7 commit b4a5a4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 11 additions & 2 deletions modeler/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,20 @@ func ReadColor64(doc *gltf.Document, acr *gltf.Accessor, buffer [][4]uint16) ([]
case gltf.ComponentUbyte:
if acr.Type == gltf.AccessorVec3 {
for i, e := range data.([][3]uint8) {
buffer[i] = [4]uint16{uint16(e[0]), uint16(e[1]), uint16(e[2]), 65535}
buffer[i] = [4]uint16{
uint16(e[0]) | uint16(e[0])<<8,
uint16(e[1]) | uint16(e[1])<<8,
uint16(e[2]) | uint16(e[2])<<8,
65535}
}
} else {
for i, e := range data.([][4]uint8) {
buffer[i] = [4]uint16{uint16(e[0]), uint16(e[1]), uint16(e[2]), uint16(e[3])}
buffer[i] = [4]uint16{
uint16(e[0]) | uint16(e[0])<<8,
uint16(e[1]) | uint16(e[1])<<8,
uint16(e[2]) | uint16(e[2])<<8,
uint16(e[3]) | uint16(e[3])<<8,
}
}
}
case gltf.ComponentUshort:
Expand Down
12 changes: 6 additions & 6 deletions modeler/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,9 @@ func TestReadColor(t *testing.T) {
{"[4]uint8", args{[]byte{1, 2, 3, 4}, &gltf.Accessor{
BufferView: gltf.Index(0), Count: 1, Type: gltf.AccessorVec4, ComponentType: gltf.ComponentUbyte,
}, nil}, [][4]uint8{{1, 2, 3, 4}}, false},
{"[4]uint16", args{[]byte{0, 0, 255, 255, 0, 0, 255, 255}, &gltf.Accessor{
{"[4]uint16", args{[]byte{0, 0, 115, 33, 200, 0, 255, 255}, &gltf.Accessor{
BufferView: gltf.Index(0), Count: 1, Type: gltf.AccessorVec4, ComponentType: gltf.ComponentUshort,
}, nil}, [][4]uint8{{0, 255, 0, 255}}, false},
}, nil}, [][4]uint8{{0, 115, 200, 255}}, false},
{"[4]float32", args{[]byte{0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64}, &gltf.Accessor{
BufferView: gltf.Index(0), Count: 1, Type: gltf.AccessorVec4, ComponentType: gltf.ComponentFloat,
}, nil}, [][4]uint8{{255, 89, 155, 252}}, false},
Expand Down Expand Up @@ -595,18 +595,18 @@ func TestReadColor64(t *testing.T) {
want [][4]uint16
wantErr bool
}{
{"[4]uint8", args{[]byte{1, 2, 3, 4}, &gltf.Accessor{
{"[4]uint8", args{[]byte{0, 115, 200, 255}, &gltf.Accessor{
BufferView: gltf.Index(0), Count: 1, Type: gltf.AccessorVec4, ComponentType: gltf.ComponentUbyte,
}, nil}, [][4]uint16{{1, 2, 3, 4}}, false},
}, nil}, [][4]uint16{{0, 29555, 51400, 65535}}, false},
{"[4]uint16", args{[]byte{0, 0, 255, 255, 0, 0, 255, 255}, &gltf.Accessor{
BufferView: gltf.Index(0), Count: 1, Type: gltf.AccessorVec4, ComponentType: gltf.ComponentUshort,
}, nil}, [][4]uint16{{0, 65535, 0, 65535}}, false},
{"[4]float32", args{[]byte{0, 0, 128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, 128, 64}, &gltf.Accessor{
BufferView: gltf.Index(0), Count: 1, Type: gltf.AccessorVec4, ComponentType: gltf.ComponentFloat,
}, nil}, [][4]uint16{{65535, 23149, 40135, 65532}}, false},
{"[3]uint8", args{[]byte{1, 2, 3, 0}, &gltf.Accessor{
{"[3]uint8", args{[]byte{0, 100, 200, 0}, &gltf.Accessor{
BufferView: gltf.Index(0), Count: 1, Type: gltf.AccessorVec3, ComponentType: gltf.ComponentUbyte,
}, nil}, [][4]uint16{{1, 2, 3, 65535}}, false},
}, nil}, [][4]uint16{{0, 25700, 51400, 65535}}, false},
{"[3]uint16", args{[]byte{0, 0, 255, 0, 255, 0, 0, 0}, &gltf.Accessor{
BufferView: gltf.Index(0), Count: 1, Type: gltf.AccessorVec3, ComponentType: gltf.ComponentUshort,
}, nil}, [][4]uint16{{0, 255, 255, 65535}}, false},
Expand Down

0 comments on commit b4a5a4e

Please sign in to comment.