Skip to content

Commit

Permalink
use float64 instead of float32
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Feb 20, 2019
1 parent 07fe1cd commit ab2ceee
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 98 deletions.
37 changes: 19 additions & 18 deletions decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func readFile(path string) []uint8 {
}

func TestOpen(t *testing.T) {
deep.FloatPrecision = 5
type args struct {
name string
embedded string
Expand All @@ -28,11 +29,11 @@ func TestOpen(t *testing.T) {
{args{"openError", ""}, nil, true},
{args{"testdata/Cube/glTF/Cube.gltf", ""}, &Document{
Accessors: []Accessor{
{BufferView: 0, ByteOffset: 0, ComponentType: UnsignedShort, Count: 36, Max: []float32{35}, Min: []float32{0}, Type: Scalar},
{BufferView: 1, ByteOffset: 0, ComponentType: Float, Count: 36, Max: []float32{1, 1, 1}, Min: []float32{-1, -1, -1}, Type: Vec3},
{BufferView: 2, ByteOffset: 0, ComponentType: Float, Count: 36, Max: []float32{1, 1, 1}, Min: []float32{-1, -1, -1}, Type: Vec3},
{BufferView: 3, ByteOffset: 0, ComponentType: Float, Count: 36, Max: []float32{1, 0, 0, 1}, Min: []float32{0, 0, -1, -1}, Type: Vec4},
{BufferView: 4, ByteOffset: 0, ComponentType: Float, Count: 36, Max: []float32{1, 1}, Min: []float32{-1, -1}, Type: Vec2}},
{BufferView: 0, ByteOffset: 0, ComponentType: UnsignedShort, Count: 36, Max: []float64{35}, Min: []float64{0}, Type: Scalar},
{BufferView: 1, ByteOffset: 0, ComponentType: Float, Count: 36, Max: []float64{1, 1, 1}, Min: []float64{-1, -1, -1}, Type: Vec3},
{BufferView: 2, ByteOffset: 0, ComponentType: Float, Count: 36, Max: []float64{1, 1, 1}, Min: []float64{-1, -1, -1}, Type: Vec3},
{BufferView: 3, ByteOffset: 0, ComponentType: Float, Count: 36, Max: []float64{1, 0, 0, 1}, Min: []float64{0, 0, -1, -1}, Type: Vec4},
{BufferView: 4, ByteOffset: 0, ComponentType: Float, Count: 36, Max: []float64{1, 1}, Min: []float64{-1, -1}, Type: Vec2}},
Asset: Asset{Generator: "VKTS glTF 2.0 exporter", Version: "2.0"},
BufferViews: []BufferView{
{Buffer: 0, ByteLength: 72, ByteOffset: 0, Target: ElementArrayBuffer},
Expand All @@ -43,9 +44,9 @@ func TestOpen(t *testing.T) {
},
Buffers: []Buffer{{ByteLength: 1800, URI: "Cube.bin", Data: readFile("testdata/Cube/glTF/Cube.bin")}},
Images: []Image{{URI: "Cube_BaseColor.png"}, {URI: "Cube_MetallicRoughness.png"}},
Materials: []Material{{Name: "Cube", AlphaMode: Opaque, AlphaCutoff: 0.5, PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: [4]float32{1, 1, 1, 1}, MetallicFactor: 1, RoughnessFactor: 1, BaseColorTexture: &TextureInfo{Index: 0}, MetallicRoughnessTexture: &TextureInfo{Index: 1}}}},
Materials: []Material{{Name: "Cube", AlphaMode: Opaque, AlphaCutoff: 0.5, PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: [4]float64{1, 1, 1, 1}, MetallicFactor: 1, RoughnessFactor: 1, BaseColorTexture: &TextureInfo{Index: 0}, MetallicRoughnessTexture: &TextureInfo{Index: 1}}}},
Meshes: []Mesh{{Name: "Cube", Primitives: []Primitive{{Indices: 0, Material: 0, Mode: Triangles, Attributes: map[string]uint32{"NORMAL": 2, "POSITION": 1, "TANGENT": 3, "TEXCOORD_0": 4}}}}},
Nodes: []Node{{Mesh: 0, Name: "Cube", Camera: -1, Skin: -1, Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}}},
Nodes: []Node{{Mesh: 0, Name: "Cube", Camera: -1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}}},
Samplers: []Sampler{{WrapS: Repeat, WrapT: Repeat}},
Scene: 0,
Scenes: []Scene{{Nodes: []uint32{0}}},
Expand All @@ -55,8 +56,8 @@ func TestOpen(t *testing.T) {
}, false},
{args{"testdata/Cameras/glTF/Cameras.gltf", "testdata/Cameras/glTF-Embedded/Cameras.gltf"}, &Document{
Accessors: []Accessor{
{BufferView: 0, ByteOffset: 0, ComponentType: UnsignedShort, Count: 6, Max: []float32{3}, Min: []float32{0}, Type: Scalar},
{BufferView: 1, ByteOffset: 0, ComponentType: Float, Count: 4, Max: []float32{1, 1, 0}, Min: []float32{0, 0, 0}, Type: Vec3},
{BufferView: 0, ByteOffset: 0, ComponentType: UnsignedShort, Count: 6, Max: []float64{3}, Min: []float64{0}, Type: Scalar},
{BufferView: 1, ByteOffset: 0, ComponentType: Float, Count: 4, Max: []float64{1, 1, 0}, Min: []float64{0, 0, 0}, Type: Vec3},
},
Asset: Asset{Version: "2.0"},
BufferViews: []BufferView{
Expand All @@ -70,17 +71,17 @@ func TestOpen(t *testing.T) {
},
Meshes: []Mesh{{Primitives: []Primitive{{Indices: 0, Material: -1, Mode: Triangles, Attributes: map[string]uint32{"POSITION": 1}}}}},
Nodes: []Node{
{Mesh: 0, Camera: -1, Skin: -1, Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float32{-0.3, 0, 0, 0.9}, Scale: [3]float32{1, 1, 1}},
{Mesh: -1, Camera: 0, Skin: -1, Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}, Translation: [3]float32{0.5, 0.5, 3.0}},
{Mesh: -1, Camera: 1, Skin: -1, Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}, Translation: [3]float32{0.5, 0.5, 3.0}},
{Mesh: 0, Camera: -1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{-0.3, 0, 0, 0.9}, Scale: [3]float64{1, 1, 1}},
{Mesh: -1, Camera: 0, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}, Translation: [3]float64{0.5, 0.5, 3.0}},
{Mesh: -1, Camera: 1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}, Translation: [3]float64{0.5, 0.5, 3.0}},
},
Scene: -1,
Scenes: []Scene{{Nodes: []uint32{0, 1, 2}}},
}, false},
{args{"testdata/BoxVertexColors/glTF-Binary/BoxVertexColors.glb", ""}, &Document{
Accessors: []Accessor{
{BufferView: 0, ByteOffset: 0, ComponentType: UnsignedShort, Count: 36, Type: Scalar},
{BufferView: 1, ByteOffset: 0, ComponentType: Float, Count: 24, Max: []float32{0.5, 0.5, 0.5}, Min: []float32{-0.5, -0.5, -0.5}, Type: Vec3},
{BufferView: 1, ByteOffset: 0, ComponentType: Float, Count: 24, Max: []float64{0.5, 0.5, 0.5}, Min: []float64{-0.5, -0.5, -0.5}, Type: Vec3},
{BufferView: 2, ByteOffset: 0, ComponentType: Float, Count: 24, Type: Vec3},
{BufferView: 3, ByteOffset: 0, ComponentType: Float, Count: 24, Type: Vec4},
{BufferView: 4, ByteOffset: 0, ComponentType: Float, Count: 24, Type: Vec2},
Expand All @@ -94,13 +95,13 @@ func TestOpen(t *testing.T) {
{Buffer: 0, ByteLength: 192, ByteOffset: 1032, Target: ArrayBuffer},
},
Buffers: []Buffer{{ByteLength: 1224, Data: readFile("testdata/BoxVertexColors/glTF-Binary/BoxVertexColors.glb")[1628+20+8:]}},
Materials: []Material{{Name: "Default", AlphaMode: Opaque, AlphaCutoff: 0.5, PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: [4]float32{0.8, 0.8, 0.8, 1}, MetallicFactor: 0.1, RoughnessFactor: 0.99}}},
Materials: []Material{{Name: "Default", AlphaMode: Opaque, AlphaCutoff: 0.5, PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: [4]float64{0.8, 0.8, 0.8, 1}, MetallicFactor: 0.1, RoughnessFactor: 0.99}}},
Meshes: []Mesh{{Name: "Cube", Primitives: []Primitive{{Indices: 0, Material: 0, Mode: Triangles, Attributes: map[string]uint32{"POSITION": 1, "COLOR_0": 3, "NORMAL": 2, "TEXCOORD_0": 4}}}}},
Nodes: []Node{
{Name: "RootNode", Mesh: -1, Camera: -1, Skin: -1, Children: []uint32{1, 2, 3}, Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}},
{Name: "Mesh", Mesh: -1, Camera: -1, Skin: -1, Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}},
{Name: "Cube", Mesh: 0, Camera: -1, Skin: -1, Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}},
{Name: "Texture Group", Mesh: -1, Camera: -1, Skin: -1, Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}},
{Name: "RootNode", Mesh: -1, Camera: -1, Skin: -1, Children: []uint32{1, 2, 3}, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
{Name: "Mesh", Mesh: -1, Camera: -1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
{Name: "Cube", Mesh: 0, Camera: -1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
{Name: "Texture Group", Mesh: -1, Camera: -1, Skin: -1, Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
},
Samplers: []Sampler{{WrapS: Repeat, WrapT: Repeat}},
Scene: 0,
Expand Down
20 changes: 10 additions & 10 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestEncoder_Encode(t *testing.T) {
{"withExtensions", args{&Document{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, ExtensionsUsed: []string{"c"}, ExtensionsRequired: []string{"d", "e"}}}, false},
{"withAsset", args{&Document{Asset: Asset{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Copyright: "@2019", Generator: "qmuntal/gltf", Version: "2.0", MinVersion: "1.0"}}}, false},
{"withAccessors", args{&Document{Accessors: []Accessor{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "acc_1", BufferView: 0, ByteOffset: 50, ComponentType: Byte, Normalized: true, Count: 5, Type: Vec3, Max: []float32{1, 2}, Min: []float32{2.4}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "acc_1", BufferView: 0, ByteOffset: 50, ComponentType: Byte, Normalized: true, Count: 5, Type: Vec3, Max: []float64{1, 2}, Min: []float64{2.4}},
{BufferView: 0, Normalized: false, Count: 50, Type: Vec4, Sparse: &Sparse{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Count: 2,
Values: SparseValues{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, BufferView: 1, ByteOffset: 2},
Indices: SparseIndices{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, BufferView: 1, ByteOffset: 2, ComponentType: Float}},
Expand Down Expand Up @@ -84,10 +84,10 @@ func TestEncoder_Encode(t *testing.T) {
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "external", URI: "https://web.com/a", MimeType: "data:image/png"},
}}}, false},
{"withMaterials", args{&Document{Materials: []Material{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "base", EmissiveFactor: [3]float32{1.0, 1.0, 1.0}, DoubleSided: true, AlphaCutoff: 0.5, AlphaMode: Opaque},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "base", EmissiveFactor: [3]float64{1.0, 1.0, 1.0}, DoubleSided: true, AlphaCutoff: 0.5, AlphaMode: Opaque},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "pbr", AlphaCutoff: 0.5, AlphaMode: Opaque,
PBRMetallicRoughness: &PBRMetallicRoughness{
Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, MetallicFactor: 1, RoughnessFactor: 2, BaseColorFactor: [4]float32{1, 2, 3, 4},
Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, MetallicFactor: 1, RoughnessFactor: 2, BaseColorFactor: [4]float64{1, 2, 3, 4},
BaseColorTexture: &TextureInfo{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Index: 1, TexCoord: 3},
MetallicRoughnessTexture: &TextureInfo{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Index: 6, TexCoord: 5},
},
Expand All @@ -101,30 +101,30 @@ func TestEncoder_Encode(t *testing.T) {
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "emmisice", AlphaCutoff: 0.5, AlphaMode: Mask, EmissiveTexture: &TextureInfo{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Index: 4, TexCoord: 50}},
}}}, false},
{"withMeshes", args{&Document{Meshes: []Mesh{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "mesh_1", Weights: []float32{1.2, 2}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "mesh_1", Weights: []float64{1.2, 2}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "mesh_2", Primitives: []Primitive{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Attributes: Attribute{"POSITION": 1}, Indices: 2, Material: 1, Mode: Lines},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Targets: []Attribute{{"POSITION": 1, "THEN": 4}, {"OTHER": 2}}, Indices: 2, Material: 1, Mode: Lines},
}},
}}}, false},
{"withNodes", args{&Document{Nodes: []Node{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "n-1", Camera: 1, Children: []uint32{1, 2}, Skin: 3,
Matrix: [16]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, Mesh: 15, Rotation: [4]float32{1.5, 1.3, 12, 0}, Scale: [3]float32{1, 3, 4}, Translation: [3]float32{0, 7.8, 9}, Weights: []float32{1, 3}},
Matrix: [16]float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, Mesh: 15, Rotation: [4]float64{1.5, 1.3, 12, 0}, Scale: [3]float64{1, 3, 4}, Translation: [3]float64{0, 7.8, 9}, Weights: []float64{1, 3}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "n-2", Camera: 1, Children: []uint32{1, 2}, Skin: 3,
Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Mesh: 15, Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}},
Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Mesh: 15, Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}},
}}}, false},
{"withSampler", args{&Document{Samplers: []Sampler{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "s_1", MagFilter: MagLinear, MinFilter: MinLinearMipMapLinear, WrapS: ClampToEdge, WrapT: MirroredRepeat},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "s_2", MagFilter: MagNearest, MinFilter: MinLinearMipMapLinear, WrapS: MirroredRepeat, WrapT: Repeat},
}}}, false},
{"withScene", args{&Document{Scene: 1}}, false},
{"withScenes", args{&Document{Scenes: []Scene{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "s_1", Nodes: []uint32{1,2}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "s_2", Nodes: []uint32{2,3}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "s_1", Nodes: []uint32{1, 2}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "s_2", Nodes: []uint32{2, 3}},
}}}, false},
{"withSkins", args{&Document{Skins: []Skin{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "skin_1", InverseBindMatrices: 2, Skeleton: 4, Joints: []uint32{5,6}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "skin_2", InverseBindMatrices: 3, Skeleton: 4, Joints: []uint32{7,8}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "skin_1", InverseBindMatrices: 2, Skeleton: 4, Joints: []uint32{5, 6}},
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "skin_2", InverseBindMatrices: 3, Skeleton: 4, Joints: []uint32{7, 8}},
}}}, false},
{"withTextures", args{&Document{Textures: []Texture{
{Extensions: 8.0, Extras: map[string]interface{}{"a": "b"}, Name: "t_1", Sampler: 2, Source: 3},
Expand Down
Loading

0 comments on commit ab2ceee

Please sign in to comment.