diff --git a/README.md b/README.md index 68a0a7f..7712d4f 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ func main() { doc := &gltf.Document{ Accessors: []*gltf.Accessor{ {BufferView: gltf.Index(0), ComponentType: gltf.ComponentUShort, Count: 36, Type: gltf.AccessorScalar}, - {BufferView: gltf.Index(1), ComponentType: gltf.ComponentFloat, Count: 24, Max: []float64{0.5, 0.5, 0.5}, Min: []float64{-0.5, -0. -0.5}, Type: gltf.AccessorVec3}, + {BufferView: gltf.Index(1), ComponentType: gltf.ComponentFloat, Count: 24, Max: []float32{0.5, 0.5, 0.5}, Min: []float32{-0.5, -0. -0.5}, Type: gltf.AccessorVec3}, {BufferView: gltf.Index(2), ComponentType: gltf.ComponentFloat, Count: 24, Type: gltf.AccessorVec3}, {BufferView: gltf.Index(3), ComponentType: gltf.ComponentFloat, Count: 24, Type: gltf.AccessorVec4}, {BufferView: gltf.Index(4), ComponentType: gltf.ComponentFloat, Count: 24, Type: gltf.AccessorVec2}, diff --git a/const.go b/const.go index a2ee956..c66af7b 100644 --- a/const.go +++ b/const.go @@ -4,19 +4,19 @@ import "encoding/json" var ( // DefaultMatrix defines an identity matrix. - DefaultMatrix = [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1} + DefaultMatrix = [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1} // DefaultRotation defines a quaternion without rotation. - DefaultRotation = [4]float64{0, 0, 0, 1} + DefaultRotation = [4]float32{0, 0, 0, 1} // DefaultScale defines a scaling that does not modify the size of the object. - DefaultScale = [3]float64{1, 1, 1} + DefaultScale = [3]float32{1, 1, 1} // DefaultTranslation defines a translation that does not move the object. - DefaultTranslation = [3]float64{0, 0, 0} + DefaultTranslation = [3]float32{0, 0, 0} ) var ( - emptyMatrix = [16]float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} - emptyRotation = [4]float64{0, 0, 0, 0} - emptyScale = [3]float64{0, 0, 0} + emptyMatrix = [16]float32{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + emptyRotation = [4]float32{0, 0, 0, 0} + emptyScale = [3]float32{0, 0, 0} ) // The ComponentType is the datatype of components in the attribute. All valid values correspond to WebGL enums. diff --git a/decoder_test.go b/decoder_test.go index f18a03a..c06c771 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -29,11 +29,11 @@ func TestOpen(t *testing.T) { {args{"openError", ""}, nil, true}, {args{"testdata/Cube/glTF/Cube.gltf", ""}, &Document{ Accessors: []*Accessor{ - {BufferView: Index(0), ByteOffset: 0, ComponentType: ComponentUshort, Count: 36, Max: []float64{35}, Min: []float64{0}, Type: AccessorScalar}, - {BufferView: Index(1), ByteOffset: 0, ComponentType: ComponentFloat, Count: 36, Max: []float64{1, 1, 1}, Min: []float64{-1, -1, -1}, Type: AccessorVec3}, - {BufferView: Index(2), ByteOffset: 0, ComponentType: ComponentFloat, Count: 36, Max: []float64{1, 1, 1}, Min: []float64{-1, -1, -1}, Type: AccessorVec3}, - {BufferView: Index(3), ByteOffset: 0, ComponentType: ComponentFloat, Count: 36, Max: []float64{1, 0, 0, 1}, Min: []float64{0, 0, -1, -1}, Type: AccessorVec4}, - {BufferView: Index(4), ByteOffset: 0, ComponentType: ComponentFloat, Count: 36, Max: []float64{1, 1}, Min: []float64{-1, -1}, Type: AccessorVec2}}, + {BufferView: Index(0), ByteOffset: 0, ComponentType: ComponentUshort, Count: 36, Max: []float32{35}, Min: []float32{0}, Type: AccessorScalar}, + {BufferView: Index(1), ByteOffset: 0, ComponentType: ComponentFloat, Count: 36, Max: []float32{1, 1, 1}, Min: []float32{-1, -1, -1}, Type: AccessorVec3}, + {BufferView: Index(2), ByteOffset: 0, ComponentType: ComponentFloat, Count: 36, Max: []float32{1, 1, 1}, Min: []float32{-1, -1, -1}, Type: AccessorVec3}, + {BufferView: Index(3), ByteOffset: 0, ComponentType: ComponentFloat, Count: 36, Max: []float32{1, 0, 0, 1}, Min: []float32{0, 0, -1, -1}, Type: AccessorVec4}, + {BufferView: Index(4), ByteOffset: 0, ComponentType: ComponentFloat, Count: 36, Max: []float32{1, 1}, Min: []float32{-1, -1}, Type: AccessorVec2}}, Asset: Asset{Generator: "VKTS glTF 2.0 exporter", Version: "2.0"}, BufferViews: []*BufferView{ {Buffer: 0, ByteLength: 72, ByteOffset: 0, Target: TargetElementArrayBuffer}, @@ -44,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: AlphaOpaque, AlphaCutoff: Float64(0.5), PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: &[4]float32{1, 1, 1, 1}, MetallicFactor: Float64(1), RoughnessFactor: Float64(1), BaseColorTexture: &TextureInfo{Index: 0}, MetallicRoughnessTexture: &TextureInfo{Index: 1}}}}, + Materials: []*Material{{Name: "Cube", AlphaMode: AlphaOpaque, AlphaCutoff: Float(0.5), PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: &[4]float32{1, 1, 1, 1}, MetallicFactor: Float(1), RoughnessFactor: Float(1), BaseColorTexture: &TextureInfo{Index: 0}, MetallicRoughnessTexture: &TextureInfo{Index: 1}}}}, Meshes: []*Mesh{{Name: "Cube", Primitives: []*Primitive{{Indices: Index(0), Material: Index(0), Mode: PrimitiveTriangles, Attributes: map[string]uint32{"NORMAL": 2, "POSITION": 1, "TANGENT": 3, "TEXCOORD_0": 4}}}}}, - Nodes: []*Node{{Mesh: Index(0), Name: "Cube", 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}}}, + Nodes: []*Node{{Mesh: Index(0), Name: "Cube", 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}}}, Samplers: []*Sampler{{WrapS: WrapRepeat, WrapT: WrapRepeat}}, Scene: Index(0), Scenes: []*Scene{{Nodes: []uint32{0}}}, @@ -56,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: Index(0), ByteOffset: 0, ComponentType: ComponentUshort, Count: 6, Max: []float64{3}, Min: []float64{0}, Type: AccessorScalar}, - {BufferView: Index(1), ByteOffset: 0, ComponentType: ComponentFloat, Count: 4, Max: []float64{1, 1, 0}, Min: []float64{0, 0, 0}, Type: AccessorVec3}, + {BufferView: Index(0), ByteOffset: 0, ComponentType: ComponentUshort, Count: 6, Max: []float32{3}, Min: []float32{0}, Type: AccessorScalar}, + {BufferView: Index(1), ByteOffset: 0, ComponentType: ComponentFloat, Count: 4, Max: []float32{1, 1, 0}, Min: []float32{0, 0, 0}, Type: AccessorVec3}, }, Asset: Asset{Version: "2.0"}, BufferViews: []*BufferView{ @@ -66,14 +66,14 @@ func TestOpen(t *testing.T) { }, Buffers: []*Buffer{{ByteLength: 60, URI: "simpleSquare.bin", Data: readFile("testdata/Cameras/glTF/simpleSquare.bin")}}, Cameras: []*Camera{ - {Perspective: &Perspective{AspectRatio: Float64(1.0), Yfov: 0.7, Zfar: Float64(100), Znear: 0.01}}, + {Perspective: &Perspective{AspectRatio: Float(1.0), Yfov: 0.7, Zfar: Float(100), Znear: 0.01}}, {Orthographic: &Orthographic{Xmag: 1.0, Ymag: 1.0, Zfar: 100, Znear: 0.01}}, }, Meshes: []*Mesh{{Primitives: []*Primitive{{Indices: Index(0), Mode: PrimitiveTriangles, Attributes: map[string]uint32{"POSITION": 1}}}}}, Nodes: []*Node{ - {Mesh: Index(0), 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}}, - {Camera: Index(0), 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}}, - {Camera: Index(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: Index(0), 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}}, + {Camera: Index(0), 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}}, + {Camera: Index(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}}, }, Scene: nil, Scenes: []*Scene{{Nodes: []uint32{0, 1, 2}}}, @@ -81,7 +81,7 @@ func TestOpen(t *testing.T) { {args{"testdata/BoxVertexColors/glTF-Binary/BoxVertexColors.glb", ""}, &Document{ Accessors: []*Accessor{ {BufferView: Index(0), ByteOffset: 0, ComponentType: ComponentUshort, Count: 36, Type: AccessorScalar}, - {BufferView: Index(1), ByteOffset: 0, ComponentType: ComponentFloat, Count: 24, Max: []float64{0.5, 0.5, 0.5}, Min: []float64{-0.5, -0.5, -0.5}, Type: AccessorVec3}, + {BufferView: Index(1), ByteOffset: 0, ComponentType: ComponentFloat, Count: 24, Max: []float32{0.5, 0.5, 0.5}, Min: []float32{-0.5, -0.5, -0.5}, Type: AccessorVec3}, {BufferView: Index(2), ByteOffset: 0, ComponentType: ComponentFloat, Count: 24, Type: AccessorVec3}, {BufferView: Index(3), ByteOffset: 0, ComponentType: ComponentFloat, Count: 24, Type: AccessorVec4}, {BufferView: Index(4), ByteOffset: 0, ComponentType: ComponentFloat, Count: 24, Type: AccessorVec2}, @@ -95,13 +95,13 @@ func TestOpen(t *testing.T) { {Buffer: 0, ByteLength: 192, ByteOffset: 1032, Target: TargetArrayBuffer}, }, Buffers: []*Buffer{{ByteLength: 1224, Data: readFile("testdata/BoxVertexColors/glTF-Binary/BoxVertexColors.glb")[1628+20+8:]}}, - Materials: []*Material{{Name: "Default", AlphaMode: AlphaOpaque, AlphaCutoff: Float64(0.5), PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: &[4]float32{0.8, 0.8, 0.8, 1}, MetallicFactor: Float64(0.1), RoughnessFactor: Float64(0.99)}}}, + Materials: []*Material{{Name: "Default", AlphaMode: AlphaOpaque, AlphaCutoff: Float(0.5), PBRMetallicRoughness: &PBRMetallicRoughness{BaseColorFactor: &[4]float32{0.8, 0.8, 0.8, 1}, MetallicFactor: Float(0.1), RoughnessFactor: Float(0.99)}}}, Meshes: []*Mesh{{Name: "Cube", Primitives: []*Primitive{{Indices: Index(0), Material: Index(0), Mode: PrimitiveTriangles, Attributes: map[string]uint32{"POSITION": 1, "COLOR_0": 3, "NORMAL": 2, "TEXCOORD_0": 4}}}}}, Nodes: []*Node{ - {Name: "RootNode", 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", 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: Index(0), 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", 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: "RootNode", 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", 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: Index(0), 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", 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}}, }, Samplers: []*Sampler{{WrapS: WrapRepeat, WrapT: WrapRepeat}}, Scene: Index(0), diff --git a/encode_test.go b/encode_test.go index 9ad85d8..d4c34e6 100644 --- a/encode_test.go +++ b/encode_test.go @@ -51,7 +51,7 @@ func TestEncoder_Encode(t *testing.T) { {"withExtensions", args{&Document{Extras: 8.0, ExtensionsUsed: []string{"c"}, ExtensionsRequired: []string{"d", "e"}}}, false}, {"withAsset", args{&Document{Asset: Asset{Extras: 8.0, Copyright: "@2019", Generator: "qmuntal/gltf", Version: "2.0", MinVersion: "1.0"}}}, false}, {"withAccessors", args{&Document{Accessors: []*Accessor{ - {Extras: 8.0, Name: "acc_1", BufferView: Index(0), ByteOffset: 50, ComponentType: ComponentByte, Normalized: true, Count: 5, Type: AccessorVec3, Max: []float64{1, 2}, Min: []float64{2.4}}, + {Extras: 8.0, Name: "acc_1", BufferView: Index(0), ByteOffset: 50, ComponentType: ComponentByte, Normalized: true, Count: 5, Type: AccessorVec3, Max: []float32{1, 2}, Min: []float32{2.4}}, {BufferView: Index(0), Normalized: false, Count: 50, Type: AccessorVec4, Sparse: &Sparse{Extras: 8.0, Count: 2, Values: SparseValues{Extras: 8.0, BufferView: 1, ByteOffset: 2}, Indices: SparseIndices{Extras: 8.0, BufferView: 1, ByteOffset: 2, ComponentType: ComponentFloat}}, @@ -82,7 +82,7 @@ func TestEncoder_Encode(t *testing.T) { }}}, false}, {"withCameras", args{&Document{Cameras: []*Camera{ {Extras: 8.0, Name: "cam_1", Orthographic: &Orthographic{Extras: 8.0, Xmag: 1, Ymag: 2, Zfar: 3, Znear: 4}}, - {Extras: 8.0, Name: "cam_2", Perspective: &Perspective{Extras: 8.0, AspectRatio: Float64(1), Yfov: 2, Zfar: Float64(3), Znear: 4}}, + {Extras: 8.0, Name: "cam_2", Perspective: &Perspective{Extras: 8.0, AspectRatio: Float(1), Yfov: 2, Zfar: Float(3), Znear: 4}}, }}}, false}, {"withImages", args{&Document{Images: []*Image{ {Extras: 8.0, Name: "binary", BufferView: Index(1), MimeType: "data:image/png"}, @@ -90,24 +90,24 @@ func TestEncoder_Encode(t *testing.T) { {Extras: 8.0, Name: "external", URI: "https://web.com/a", MimeType: "data:image/png"}, }}}, false}, {"withMaterials", args{&Document{Materials: []*Material{ - {Extras: 8.0, Name: "base", EmissiveFactor: [3]float64{1.0, 1.0, 1.0}, DoubleSided: true, AlphaCutoff: Float64(0.5), AlphaMode: AlphaOpaque}, - {Extras: 8.0, Name: "pbr", AlphaCutoff: Float64(0.5), AlphaMode: AlphaOpaque, + {Extras: 8.0, Name: "base", EmissiveFactor: [3]float32{1.0, 1.0, 1.0}, DoubleSided: true, AlphaCutoff: Float(0.5), AlphaMode: AlphaOpaque}, + {Extras: 8.0, Name: "pbr", AlphaCutoff: Float(0.5), AlphaMode: AlphaOpaque, PBRMetallicRoughness: &PBRMetallicRoughness{ - Extras: 8.0, MetallicFactor: Float64(1), RoughnessFactor: Float64(2), BaseColorFactor: &[4]float32{0.8, 0.8, 0.8, 1}, + Extras: 8.0, MetallicFactor: Float(1), RoughnessFactor: Float(2), BaseColorFactor: &[4]float32{0.8, 0.8, 0.8, 1}, BaseColorTexture: &TextureInfo{Extras: 8.0, Index: 1, TexCoord: 3}, MetallicRoughnessTexture: &TextureInfo{Extras: 8.0, Index: 6, TexCoord: 5}, }, }, - {Extras: 8.0, Name: "normal", AlphaCutoff: Float64(0.7), AlphaMode: AlphaBlend, - NormalTexture: &NormalTexture{Extras: 8.0, Index: Index(1), TexCoord: 2, Scale: Float64(2.0)}, + {Extras: 8.0, Name: "normal", AlphaCutoff: Float(0.7), AlphaMode: AlphaBlend, + NormalTexture: &NormalTexture{Extras: 8.0, Index: Index(1), TexCoord: 2, Scale: Float(2.0)}, }, - {Extras: 8.0, Name: "occlusion", AlphaCutoff: Float64(0.5), AlphaMode: AlphaMask, - OcclusionTexture: &OcclusionTexture{Extras: 8.0, Index: Index(1), TexCoord: 2, Strength: Float64(2.0)}, + {Extras: 8.0, Name: "occlusion", AlphaCutoff: Float(0.5), AlphaMode: AlphaMask, + OcclusionTexture: &OcclusionTexture{Extras: 8.0, Index: Index(1), TexCoord: 2, Strength: Float(2.0)}, }, - {Extras: 8.0, Name: "emmisice", AlphaCutoff: Float64(0.5), AlphaMode: AlphaMask, EmissiveTexture: &TextureInfo{Extras: 8.0, Index: 4, TexCoord: 50}}, + {Extras: 8.0, Name: "emmisice", AlphaCutoff: Float(0.5), AlphaMode: AlphaMask, EmissiveTexture: &TextureInfo{Extras: 8.0, Index: 4, TexCoord: 50}}, }}}, false}, {"withMeshes", args{&Document{Meshes: []*Mesh{ - {Extras: 8.0, Name: "mesh_1", Weights: []float64{1.2, 2}}, + {Extras: 8.0, Name: "mesh_1", Weights: []float32{1.2, 2}}, {Extras: 8.0, Name: "mesh_2", Primitives: []*Primitive{ {Extras: 8.0, Attributes: Attribute{"POSITION": 1}, Indices: Index(2), Material: Index(1), Mode: PrimitiveLines}, {Extras: 8.0, Targets: []Attribute{{"POSITION": 1, "THEN": 4}, {"OTHER": 2}}, Indices: Index(2), Material: Index(1), Mode: PrimitiveLines}, @@ -115,9 +115,9 @@ func TestEncoder_Encode(t *testing.T) { }}}, false}, {"withNodes", args{&Document{Nodes: []*Node{ {Extras: 8.0, Name: "n-1", Camera: Index(1), Children: []uint32{1, 2}, Skin: Index(3), - Matrix: [16]float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, Mesh: Index(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}}, + Matrix: [16]float32{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, Mesh: Index(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}}, {Extras: 8.0, Name: "n-2", Camera: Index(1), Children: []uint32{1, 2}, Skin: Index(3), - Matrix: [16]float64{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Mesh: Index(15), Rotation: [4]float64{0, 0, 0, 1}, Scale: [3]float64{1, 1, 1}}, + Matrix: [16]float32{1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}, Mesh: Index(15), Rotation: [4]float32{0, 0, 0, 1}, Scale: [3]float32{1, 1, 1}}, }}}, false}, {"withSampler", args{&Document{Samplers: []*Sampler{ {Extras: 8.0, Name: "s_1", MagFilter: MagLinear, MinFilter: MinLinearMipMapLinear, WrapS: WrapClampToEdge, WrapT: WrapMirroredRepeat}, diff --git a/example_test.go b/example_test.go index 0fa80a0..68cb083 100644 --- a/example_test.go +++ b/example_test.go @@ -18,7 +18,7 @@ func ExampleSave() { doc := &gltf.Document{ Accessors: []*gltf.Accessor{ {BufferView: gltf.Index(0), ComponentType: gltf.ComponentUshort, Count: 36, Type: gltf.AccessorScalar}, - {BufferView: gltf.Index(1), ComponentType: gltf.ComponentFloat, Count: 24, Max: []float64{0.5, 0.5, 0.5}, Min: []float64{-0.5, -0.5, -0.5}, Type: gltf.AccessorVec3}, + {BufferView: gltf.Index(1), ComponentType: gltf.ComponentFloat, Count: 24, Max: []float32{0.5, 0.5, 0.5}, Min: []float32{-0.5, -0.5, -0.5}, Type: gltf.AccessorVec3}, {BufferView: gltf.Index(2), ComponentType: gltf.ComponentFloat, Count: 24, Type: gltf.AccessorVec3}, {BufferView: gltf.Index(3), ComponentType: gltf.ComponentFloat, Count: 24, Type: gltf.AccessorVec4}, {BufferView: gltf.Index(4), ComponentType: gltf.ComponentFloat, Count: 24, Type: gltf.AccessorVec2}, @@ -33,8 +33,8 @@ func ExampleSave() { }, Buffers: []*gltf.Buffer{{ByteLength: 1224, Data: []byte{97, 110, 121, 32, 99, 97, 114, 110, 97, 108, 32, 112, 108, 101, 97, 115}}}, Materials: []*gltf.Material{{ - Name: "Default", AlphaMode: gltf.AlphaOpaque, AlphaCutoff: gltf.Float64(0.5), - PBRMetallicRoughness: &gltf.PBRMetallicRoughness{BaseColorFactor: &[4]float32{0.8, 0.8, 0.8, 1}, MetallicFactor: gltf.Float64(0.1), RoughnessFactor: gltf.Float64(0.99)}, + Name: "Default", AlphaMode: gltf.AlphaOpaque, AlphaCutoff: gltf.Float(0.5), + PBRMetallicRoughness: &gltf.PBRMetallicRoughness{BaseColorFactor: &[4]float32{0.8, 0.8, 0.8, 1}, MetallicFactor: gltf.Float(0.1), RoughnessFactor: gltf.Float(0.99)}, }}, Meshes: []*gltf.Mesh{{Name: "Cube", Primitives: []*gltf.Primitive{{Indices: gltf.Index(0), Material: gltf.Index(0), Mode: gltf.PrimitiveTriangles, Attributes: map[string]uint32{"POSITION": 1, "COLOR_0": 3, "NORMAL": 2, "TEXCOORD_0": 4}}}}}, Nodes: []*gltf.Node{ diff --git a/ext/lightspuntual/lightspuntual.go b/ext/lightspuntual/lightspuntual.go index 90c3256..441fef9 100644 --- a/ext/lightspuntual/lightspuntual.go +++ b/ext/lightspuntual/lightspuntual.go @@ -50,12 +50,12 @@ type LightIndex uint32 // Spot defines the spot cone. type Spot struct { - InnerConeAngle float64 `json:"innerConeAngle,omitempty"` - OuterConeAngle *float64 `json:"outerConeAngle,omitempty"` + InnerConeAngle float32 `json:"innerConeAngle,omitempty"` + OuterConeAngle *float32 `json:"outerConeAngle,omitempty"` } // OuterConeAngleOrDefault returns the OuterConeAngle if it is not nil, else return the default one. -func (s *Spot) OuterConeAngleOrDefault() float64 { +func (s *Spot) OuterConeAngleOrDefault() float32 { if s.OuterConeAngle == nil { return math.Pi / 4 } @@ -65,7 +65,7 @@ func (s *Spot) OuterConeAngleOrDefault() float64 { // UnmarshalJSON unmarshal the spot with the correct default values. func (s *Spot) UnmarshalJSON(data []byte) error { type alias Spot - tmp := alias(Spot{OuterConeAngle: gltf.Float64(math.Pi / 4)}) + tmp := alias(Spot{OuterConeAngle: gltf.Float(math.Pi / 4)}) err := json.Unmarshal(data, &tmp) if err == nil { *s = Spot(tmp) @@ -82,13 +82,13 @@ type Light struct { Type string `json:"type"` Name string `json:"name,omitempty"` Color *[3]float32 `json:"color,omitempty" validate:"omitempty,dive,gte=0,lte=1"` - Intensity *float64 `json:"intensity,omitempty"` - Range *float64 `json:"range,omitempty"` + Intensity *float32 `json:"intensity,omitempty"` + Range *float32 `json:"range,omitempty"` Spot *Spot `json:"spot,omitempty"` } // IntensityOrDefault returns the itensity if it is not nil, else return the default one. -func (l *Light) IntensityOrDefault() float64 { +func (l *Light) IntensityOrDefault() float32 { if l.Intensity == nil { return 1 } @@ -106,7 +106,7 @@ func (l *Light) ColorOrDefault() [3]float32 { // UnmarshalJSON unmarshal the light with the correct default values. func (l *Light) UnmarshalJSON(data []byte) error { type alias Light - tmp := alias(Light{Color: &[3]float32{1, 1, 1}, Intensity: gltf.Float64(1), Range: gltf.Float64(math.Inf(0))}) + tmp := alias(Light{Color: &[3]float32{1, 1, 1}, Intensity: gltf.Float(1), Range: gltf.Float(float32(math.Inf(0)))}) err := json.Unmarshal(data, &tmp) if err == nil { *l = Light(tmp) diff --git a/ext/lightspuntual/lightspuntual_test.go b/ext/lightspuntual/lightspuntual_test.go index 3c360ea..e031c5c 100644 --- a/ext/lightspuntual/lightspuntual_test.go +++ b/ext/lightspuntual/lightspuntual_test.go @@ -13,10 +13,10 @@ func TestLight_IntensityOrDefault(t *testing.T) { tests := []struct { name string l *Light - want float64 + want float32 }{ {"empty", &Light{}, 1}, - {"other", &Light{Intensity: gltf.Float64(0.5)}, 0.5}, + {"other", &Light{Intensity: gltf.Float(0.5)}, 0.5}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -49,10 +49,10 @@ func TestSpot_OuterConeAngleOrDefault(t *testing.T) { tests := []struct { name string s *Spot - want float64 + want float32 }{ {"empty", &Spot{}, math.Pi / 4}, - {"other", &Spot{OuterConeAngle: gltf.Float64(0.5)}, 0.5}, + {"other", &Spot{OuterConeAngle: gltf.Float(0.5)}, 0.5}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -75,7 +75,7 @@ func TestLight_UnmarshalJSON(t *testing.T) { wantErr bool }{ {"default", new(Light), args{[]byte("{}")}, &Light{ - Color: &[3]float32{1, 1, 1}, Intensity: gltf.Float64(1), Range: gltf.Float64(math.Inf(0)), + Color: &[3]float32{1, 1, 1}, Intensity: gltf.Float(1), Range: gltf.Float(float32(math.Inf(0))), }, false}, {"nodefault", new(Light), args{[]byte(`{ "color": [0.3, 0.7, 1.0], @@ -88,10 +88,10 @@ func TestLight_UnmarshalJSON(t *testing.T) { "outerConeAngle": 2.0 } }`)}, &Light{ - Name: "AAA", Type: "spot", Color: &[3]float32{0.3, 0.7, 1}, Intensity: gltf.Float64(40), Range: gltf.Float64(10), + Name: "AAA", Type: "spot", Color: &[3]float32{0.3, 0.7, 1}, Intensity: gltf.Float(40), Range: gltf.Float(10), Spot: &Spot{ InnerConeAngle: 1.0, - OuterConeAngle: gltf.Float64(2.0), + OuterConeAngle: gltf.Float(2.0), }, }, false}, } @@ -133,8 +133,8 @@ func TestUnmarshal(t *testing.T) { "type": "point" } ]}`)}, Lights{ - {Color: &[3]float32{1, 0.9, 0.7}, Name: "Directional", Intensity: gltf.Float64(3.0), Type: "directional", Range: gltf.Float64(math.Inf(0))}, - {Color: &[3]float32{1, 0, 0}, Name: "Point", Intensity: gltf.Float64(20.0), Type: "point", Range: gltf.Float64(math.Inf(0))}, + {Color: &[3]float32{1, 0.9, 0.7}, Name: "Directional", Intensity: gltf.Float(3.0), Type: "directional", Range: gltf.Float(float32(math.Inf(0)))}, + {Color: &[3]float32{1, 0, 0}, Name: "Point", Intensity: gltf.Float(20.0), Type: "point", Range: gltf.Float(float32(math.Inf(0)))}, }, false}, } for _, tt := range tests { diff --git a/ext/specular/specular.go b/ext/specular/specular.go index 3bd31bf..821bf5c 100644 --- a/ext/specular/specular.go +++ b/ext/specular/specular.go @@ -28,14 +28,14 @@ type PBRSpecularGlossiness struct { DiffuseFactor *[4]float32 `json:"diffuseFactor,omitempty" validate:"omitempty,dive,gte=0,lte=1"` DiffuseTexture *gltf.TextureInfo `json:"diffuseTexture,omitempty"` SpecularFactor *[3]float32 `json:"specularFactor,omitempty" validate:"omitempty,dive,gte=0,lte=1"` - GlossinessFactor *float64 `json:"glossinessFactor,omitempty" validate:"omitempty,gte=0,lte=1"` + GlossinessFactor *float32 `json:"glossinessFactor,omitempty" validate:"omitempty,gte=0,lte=1"` SpecularGlossinessTexture *gltf.TextureInfo `json:"specularGlossinessTexture,omitempty"` } // UnmarshalJSON unmarshal the pbr with the correct default values. func (p *PBRSpecularGlossiness) UnmarshalJSON(data []byte) error { type alias PBRSpecularGlossiness - tmp := alias(PBRSpecularGlossiness{DiffuseFactor: &[4]float32{1, 1, 1, 1}, SpecularFactor: &[3]float32{1, 1, 1}, GlossinessFactor: gltf.Float64(1)}) + tmp := alias(PBRSpecularGlossiness{DiffuseFactor: &[4]float32{1, 1, 1, 1}, SpecularFactor: &[3]float32{1, 1, 1}, GlossinessFactor: gltf.Float(1)}) err := json.Unmarshal(data, &tmp) if err == nil { *p = PBRSpecularGlossiness(tmp) diff --git a/ext/specular/specular_test.go b/ext/specular/specular_test.go index cc58b29..7f346f5 100644 --- a/ext/specular/specular_test.go +++ b/ext/specular/specular_test.go @@ -18,9 +18,9 @@ func TestPBRSpecularGlossiness_UnmarshalJSON(t *testing.T) { want *PBRSpecularGlossiness wantErr bool }{ - {"default", new(PBRSpecularGlossiness), args{[]byte("{}")}, &PBRSpecularGlossiness{DiffuseFactor: &[4]float32{1, 1, 1, 1}, SpecularFactor: &[3]float32{1, 1, 1}, GlossinessFactor: gltf.Float64(1)}, false}, + {"default", new(PBRSpecularGlossiness), args{[]byte("{}")}, &PBRSpecularGlossiness{DiffuseFactor: &[4]float32{1, 1, 1, 1}, SpecularFactor: &[3]float32{1, 1, 1}, GlossinessFactor: gltf.Float(1)}, false}, {"nodefault", new(PBRSpecularGlossiness), args{[]byte(`{"diffuseFactor": [0.1,0.2,0.3,0.4],"specularFactor":[0.5,0.6,0.7],"glossinessFactor":0.5}`)}, &PBRSpecularGlossiness{ - DiffuseFactor: &[4]float32{0.1, 0.2, 0.3, 0.4}, SpecularFactor: &[3]float32{0.5, 0.6, 0.7}, GlossinessFactor: gltf.Float64(0.5), + DiffuseFactor: &[4]float32{0.1, 0.2, 0.3, 0.4}, SpecularFactor: &[3]float32{0.5, 0.6, 0.7}, GlossinessFactor: gltf.Float(0.5), }, false}, } for _, tt := range tests { @@ -43,9 +43,9 @@ func TestPBRSpecularGlossiness_MarshalJSON(t *testing.T) { want []byte wantErr bool }{ - {"default", &PBRSpecularGlossiness{GlossinessFactor: gltf.Float64(1), DiffuseFactor: &[4]float32{1, 1, 1, 1}, SpecularFactor: &[3]float32{1, 1, 1}}, []byte(`{}`), false}, + {"default", &PBRSpecularGlossiness{GlossinessFactor: gltf.Float(1), DiffuseFactor: &[4]float32{1, 1, 1, 1}, SpecularFactor: &[3]float32{1, 1, 1}}, []byte(`{}`), false}, {"empty", &PBRSpecularGlossiness{}, []byte(`{}`), false}, - {"nodefault", &PBRSpecularGlossiness{GlossinessFactor: gltf.Float64(0.5), DiffuseFactor: &[4]float32{1, 0.5, 1, 1}, SpecularFactor: &[3]float32{1, 1, 0.5}}, []byte(`{"diffuseFactor":[1,0.5,1,1],"specularFactor":[1,1,0.5],"glossinessFactor":0.5}`), false}, + {"nodefault", &PBRSpecularGlossiness{GlossinessFactor: gltf.Float(0.5), DiffuseFactor: &[4]float32{1, 0.5, 1, 1}, SpecularFactor: &[3]float32{1, 1, 0.5}}, []byte(`{"diffuseFactor":[1,0.5,1,1],"specularFactor":[1,1,0.5],"glossinessFactor":0.5}`), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -71,7 +71,7 @@ func TestUnmarshal(t *testing.T) { want interface{} wantErr bool }{ - {"base", args{[]byte("{}")}, &PBRSpecularGlossiness{DiffuseFactor: &[4]float32{1, 1, 1, 1}, SpecularFactor: &[3]float32{1, 1, 1}, GlossinessFactor: gltf.Float64(1)}, false}, + {"base", args{[]byte("{}")}, &PBRSpecularGlossiness{DiffuseFactor: &[4]float32{1, 1, 1, 1}, SpecularFactor: &[3]float32{1, 1, 1}, GlossinessFactor: gltf.Float(1)}, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/ext/texturetransform/transform.go b/ext/texturetransform/transform.go index 53f384b..51579a3 100644 --- a/ext/texturetransform/transform.go +++ b/ext/texturetransform/transform.go @@ -9,9 +9,9 @@ import ( var ( // DefaultScale defines a scaling that does not modify the size of the object. - DefaultScale = [2]float64{1, 1} - emptyScale = [2]float64{0, 0} - emptyOffset = [2]float64{0, 0} + DefaultScale = [2]float32{1, 1} + emptyScale = [2]float32{0, 0} + emptyOffset = [2]float32{0, 0} ) const ( @@ -32,14 +32,14 @@ func init() { // TextureTranform can be used in textureInfo to pack many low-res texture into a single large texture atlas. type TextureTranform struct { - Offset [2]float64 `json:"offset"` - Rotation float64 `json:"rotation,omitempty"` - Scale [2]float64 `json:"scale"` + Offset [2]float32 `json:"offset"` + Rotation float32 `json:"rotation,omitempty"` + Scale [2]float32 `json:"scale"` TexCoord *uint32 `json:"texCoord,omitempty"` } // ScaleOrDefault returns the node scale if it represents a valid scale factor, else return the default one. -func (t *TextureTranform) ScaleOrDefault() [2]float64 { +func (t *TextureTranform) ScaleOrDefault() [2]float32 { if t.Scale == emptyScale { return DefaultScale } diff --git a/ext/texturetransform/transform_test.go b/ext/texturetransform/transform_test.go index 42bef41..3b60f67 100644 --- a/ext/texturetransform/transform_test.go +++ b/ext/texturetransform/transform_test.go @@ -11,11 +11,11 @@ func TestTextureTranform_ScaleOrDefault(t *testing.T) { tests := []struct { name string t *TextureTranform - want [2]float64 + want [2]float32 }{ {"default", &TextureTranform{Scale: DefaultScale}, DefaultScale}, {"zeros", &TextureTranform{Scale: emptyScale}, DefaultScale}, - {"other", &TextureTranform{Scale: [2]float64{1, 2}}, [2]float64{1, 2}}, + {"other", &TextureTranform{Scale: [2]float32{1, 2}}, [2]float32{1, 2}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -39,7 +39,7 @@ func TestTextureTranform_UnmarshalJSON(t *testing.T) { }{ {"default", new(TextureTranform), args{[]byte("{}")}, &TextureTranform{Scale: DefaultScale}, false}, {"nodefault", new(TextureTranform), args{[]byte(`{"offset": [0.1,0.2],"rotation":1.57,"scale":[1, -1],"texCoord":2}`)}, &TextureTranform{ - Offset: [2]float64{0.1, 0.2}, Rotation: 1.57, Scale: [2]float64{1, -1}, TexCoord: gltf.Index(2), + Offset: [2]float32{0.1, 0.2}, Rotation: 1.57, Scale: [2]float32{1, -1}, TexCoord: gltf.Index(2), }, false}, } for _, tt := range tests { @@ -64,7 +64,7 @@ func TestTextureTranform_MarshalJSON(t *testing.T) { }{ {"default", &TextureTranform{Scale: DefaultScale}, []byte(`{}`), false}, {"empty", &TextureTranform{}, []byte(`{}`), false}, - {"nodefault", &TextureTranform{Offset: [2]float64{0.1, 0.2}, Rotation: 1.57, Scale: [2]float64{1, -1}, TexCoord: gltf.Index(2)}, []byte(`{"offset":[0.1,0.2],"rotation":1.57,"scale":[1,-1],"texCoord":2}`), false}, + {"nodefault", &TextureTranform{Offset: [2]float32{0.1, 0.2}, Rotation: 1.57, Scale: [2]float32{1, -1}, TexCoord: gltf.Index(2)}, []byte(`{"offset":[0.1,0.2],"rotation":1.57,"scale":[1,-1],"texCoord":2}`), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/marshal.go b/marshal.go index 8cc1ecd..6cf4d07 100644 --- a/marshal.go +++ b/marshal.go @@ -78,7 +78,7 @@ func (c *Camera) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshal the material with the correct default values. func (m *Material) UnmarshalJSON(data []byte) error { type alias Material - tmp := alias(Material{AlphaCutoff: Float64(0.5)}) + tmp := alias(Material{AlphaCutoff: Float(0.5)}) err := json.Unmarshal(data, &tmp) if err == nil { *m = Material(tmp) @@ -94,7 +94,7 @@ func (m *Material) MarshalJSON() ([]byte, error) { if m.AlphaCutoff != nil && *m.AlphaCutoff == 0.5 { out = removeProperty([]byte(`"alphaCutoff":0.5`), out) } - if m.EmissiveFactor == [3]float64{0, 0, 0} { + if m.EmissiveFactor == [3]float32{0, 0, 0} { out = removeProperty([]byte(`"emissiveFactor":[0,0,0]`), out) } out = sanitizeJSON(out) @@ -105,7 +105,7 @@ func (m *Material) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshal the texture info with the correct default values. func (n *NormalTexture) UnmarshalJSON(data []byte) error { type alias NormalTexture - tmp := alias(NormalTexture{Scale: Float64(1)}) + tmp := alias(NormalTexture{Scale: Float(1)}) err := json.Unmarshal(data, &tmp) if err == nil { *n = NormalTexture(tmp) @@ -118,7 +118,7 @@ func (n *NormalTexture) MarshalJSON() ([]byte, error) { type alias NormalTexture if n.Scale != nil && *n.Scale == 1 { return json.Marshal(&struct { - Scale float64 `json:"scale,omitempty"` + Scale float32 `json:"scale,omitempty"` *alias }{ Scale: 0, @@ -131,7 +131,7 @@ func (n *NormalTexture) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshal the texture info with the correct default values. func (o *OcclusionTexture) UnmarshalJSON(data []byte) error { type alias OcclusionTexture - tmp := alias(OcclusionTexture{Strength: Float64(1)}) + tmp := alias(OcclusionTexture{Strength: Float(1)}) err := json.Unmarshal(data, &tmp) if err == nil { *o = OcclusionTexture(tmp) @@ -144,7 +144,7 @@ func (o *OcclusionTexture) MarshalJSON() ([]byte, error) { type alias OcclusionTexture if o.Strength != nil && *o.Strength == 1 { return json.Marshal(&struct { - Strength float64 `json:"strength,omitempty"` + Strength float32 `json:"strength,omitempty"` *alias }{ Strength: 0, @@ -157,7 +157,7 @@ func (o *OcclusionTexture) MarshalJSON() ([]byte, error) { // UnmarshalJSON unmarshal the pbr with the correct default values. func (p *PBRMetallicRoughness) UnmarshalJSON(data []byte) error { type alias PBRMetallicRoughness - tmp := alias(PBRMetallicRoughness{BaseColorFactor: &[4]float32{1, 1, 1, 1}, MetallicFactor: Float64(1), RoughnessFactor: Float64(1)}) + tmp := alias(PBRMetallicRoughness{BaseColorFactor: &[4]float32{1, 1, 1, 1}, MetallicFactor: Float(1), RoughnessFactor: Float(1)}) err := json.Unmarshal(data, &tmp) if err == nil { *p = PBRMetallicRoughness(tmp) diff --git a/marshal_test.go b/marshal_test.go index f2f7e65..7b10c38 100644 --- a/marshal_test.go +++ b/marshal_test.go @@ -46,22 +46,22 @@ func TestNode_UnmarshalJSON(t *testing.T) { wantErr bool }{ {"default", new(Node), args{[]byte("{}")}, &Node{ - 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}, + 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}, }, false}, {"nodefault", new(Node), args{[]byte(`{"matrix":[1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],"rotation":[0,0,0,1],"scale":[1,1,1],"camera":0,"mesh":0,"skin":0}`)}, &Node{ - 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}, + 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}, Camera: Index(0), Mesh: Index(0), Skin: Index(0), }, false}, {"nodefault", new(Node), args{[]byte(`{"matrix":[1,2,2,0,0,1,3,4,0,0,1,0,5,0,0,5],"rotation":[1,2,3,4],"scale":[2,3,4],"camera":1,"mesh":2,"skin":3}`)}, &Node{ - Matrix: [16]float64{1, 2, 2, 0, 0, 1, 3, 4, 0, 0, 1, 0, 5, 0, 0, 5}, - Rotation: [4]float64{1, 2, 3, 4}, - Scale: [3]float64{2, 3, 4}, + Matrix: [16]float32{1, 2, 2, 0, 0, 1, 3, 4, 0, 0, 1, 0, 5, 0, 0, 5}, + Rotation: [4]float32{1, 2, 3, 4}, + Scale: [3]float32{2, 3, 4}, Camera: Index(1), Mesh: Index(2), Skin: Index(3), @@ -91,8 +91,8 @@ func TestMaterial_UnmarshalJSON(t *testing.T) { want *Material wantErr bool }{ - {"default", new(Material), args{[]byte("{}")}, &Material{AlphaCutoff: Float64(0.5), AlphaMode: AlphaOpaque}, false}, - {"nodefault", new(Material), args{[]byte(`{"alphaCutoff": 0.2, "alphaMode": "MASK"}`)}, &Material{AlphaCutoff: Float64(0.2), AlphaMode: AlphaMask}, false}, + {"default", new(Material), args{[]byte("{}")}, &Material{AlphaCutoff: Float(0.5), AlphaMode: AlphaOpaque}, false}, + {"nodefault", new(Material), args{[]byte(`{"alphaCutoff": 0.2, "alphaMode": "MASK"}`)}, &Material{AlphaCutoff: Float(0.2), AlphaMode: AlphaMask}, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -118,9 +118,9 @@ func TestNormalTexture_UnmarshalJSON(t *testing.T) { want *NormalTexture wantErr bool }{ - {"default", new(NormalTexture), args{[]byte("{}")}, &NormalTexture{Scale: Float64(1)}, false}, - {"empty", new(NormalTexture), args{[]byte(`{"scale": 0, "index": 0}`)}, &NormalTexture{Scale: Float64(0), Index: Index(0)}, false}, - {"nodefault", new(NormalTexture), args{[]byte(`{"scale": 0.5, "index":2}`)}, &NormalTexture{Scale: Float64(0.5), Index: Index(2)}, false}, + {"default", new(NormalTexture), args{[]byte("{}")}, &NormalTexture{Scale: Float(1)}, false}, + {"empty", new(NormalTexture), args{[]byte(`{"scale": 0, "index": 0}`)}, &NormalTexture{Scale: Float(0), Index: Index(0)}, false}, + {"nodefault", new(NormalTexture), args{[]byte(`{"scale": 0.5, "index":2}`)}, &NormalTexture{Scale: Float(0.5), Index: Index(2)}, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -146,9 +146,9 @@ func TestOcclusionTexture_UnmarshalJSON(t *testing.T) { want *OcclusionTexture wantErr bool }{ - {"default", new(OcclusionTexture), args{[]byte("{}")}, &OcclusionTexture{Strength: Float64(1)}, false}, - {"empty", new(OcclusionTexture), args{[]byte(`{"strength": 0, "index": 0}`)}, &OcclusionTexture{Strength: Float64(0), Index: Index(0)}, false}, - {"nodefault", new(OcclusionTexture), args{[]byte(`{"strength": 0.5, "index":2}`)}, &OcclusionTexture{Strength: Float64(0.5), Index: Index(2)}, false}, + {"default", new(OcclusionTexture), args{[]byte("{}")}, &OcclusionTexture{Strength: Float(1)}, false}, + {"empty", new(OcclusionTexture), args{[]byte(`{"strength": 0, "index": 0}`)}, &OcclusionTexture{Strength: Float(0), Index: Index(0)}, false}, + {"nodefault", new(OcclusionTexture), args{[]byte(`{"strength": 0.5, "index":2}`)}, &OcclusionTexture{Strength: Float(0.5), Index: Index(2)}, false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -174,9 +174,9 @@ func TestPBRMetallicRoughness_UnmarshalJSON(t *testing.T) { want *PBRMetallicRoughness wantErr bool }{ - {"default", new(PBRMetallicRoughness), args{[]byte("{}")}, &PBRMetallicRoughness{BaseColorFactor: &[4]float32{1, 1, 1, 1}, MetallicFactor: Float64(1), RoughnessFactor: Float64(1)}, false}, + {"default", new(PBRMetallicRoughness), args{[]byte("{}")}, &PBRMetallicRoughness{BaseColorFactor: &[4]float32{1, 1, 1, 1}, MetallicFactor: Float(1), RoughnessFactor: Float(1)}, false}, {"nodefault", new(PBRMetallicRoughness), args{[]byte(`{"baseColorFactor": [0.1,0.2,0.6,0.7],"metallicFactor":0.5,"roughnessFactor":0.1}`)}, &PBRMetallicRoughness{ - BaseColorFactor: &[4]float32{0.1, 0.2, 0.6, 0.7}, MetallicFactor: Float64(0.5), RoughnessFactor: Float64(0.1), + BaseColorFactor: &[4]float32{0.1, 0.2, 0.6, 0.7}, MetallicFactor: Float(0.5), RoughnessFactor: Float(0.1), }, false}, } for _, tt := range tests { @@ -200,28 +200,28 @@ func TestNode_MarshalJSON(t *testing.T) { wantErr bool }{ {"default", &Node{ - 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}, + 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}, }, []byte("{}"), false}, {"default2", &Node{ - Matrix: [16]float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Rotation: [4]float64{0, 0, 0, 0}, - Scale: [3]float64{0, 0, 0}, + Matrix: [16]float32{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Rotation: [4]float32{0, 0, 0, 0}, + Scale: [3]float32{0, 0, 0}, }, []byte("{}"), false}, {"empty", &Node{ - Matrix: [16]float64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Rotation: [4]float64{0, 0, 0, 0}, - Scale: [3]float64{0, 0, 0}, + Matrix: [16]float32{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Rotation: [4]float32{0, 0, 0, 0}, + Scale: [3]float32{0, 0, 0}, Camera: Index(0), Skin: Index(0), Mesh: Index(0), }, []byte(`{"camera":0,"skin":0,"mesh":0}`), false}, {"nodefault", &Node{ - Matrix: [16]float64{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - Rotation: [4]float64{1, 0, 0, 0}, - Scale: [3]float64{1, 0, 0}, - Translation: [3]float64{1, 0, 0}, + Matrix: [16]float32{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + Rotation: [4]float32{1, 0, 0, 0}, + Scale: [3]float32{1, 0, 0}, + Translation: [3]float32{1, 0, 0}, Camera: Index(1), Skin: Index(1), Mesh: Index(1), @@ -248,9 +248,9 @@ func TestMaterial_MarshalJSON(t *testing.T) { want []byte wantErr bool }{ - {"default", &Material{AlphaCutoff: Float64(0.5), AlphaMode: AlphaOpaque}, []byte(`{}`), false}, + {"default", &Material{AlphaCutoff: Float(0.5), AlphaMode: AlphaOpaque}, []byte(`{}`), false}, {"empty", &Material{AlphaMode: AlphaBlend}, []byte(`{"alphaMode":"BLEND"}`), false}, - {"nodefault", &Material{AlphaCutoff: Float64(1), AlphaMode: AlphaBlend}, []byte(`{"alphaMode":"BLEND","alphaCutoff":1}`), false}, + {"nodefault", &Material{AlphaCutoff: Float(1), AlphaMode: AlphaBlend}, []byte(`{"alphaMode":"BLEND","alphaCutoff":1}`), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -273,9 +273,9 @@ func TestNormalTexture_MarshalJSON(t *testing.T) { want []byte wantErr bool }{ - {"default", &NormalTexture{Scale: Float64(1)}, []byte(`{}`), false}, + {"default", &NormalTexture{Scale: Float(1)}, []byte(`{}`), false}, {"empty", &NormalTexture{Index: Index(0)}, []byte(`{"index":0}`), false}, - {"nodefault", &NormalTexture{Index: Index(1), Scale: Float64(0.5)}, []byte(`{"index":1,"scale":0.5}`), false}, + {"nodefault", &NormalTexture{Index: Index(1), Scale: Float(0.5)}, []byte(`{"index":1,"scale":0.5}`), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -298,9 +298,9 @@ func TestOcclusionTexture_MarshalJSON(t *testing.T) { want []byte wantErr bool }{ - {"default", &OcclusionTexture{Strength: Float64(1)}, []byte(`{}`), false}, + {"default", &OcclusionTexture{Strength: Float(1)}, []byte(`{}`), false}, {"empty", &OcclusionTexture{Index: Index(0)}, []byte(`{"index":0}`), false}, - {"nodefault", &OcclusionTexture{Index: Index(1), Strength: Float64(0.5)}, []byte(`{"index":1,"strength":0.5}`), false}, + {"nodefault", &OcclusionTexture{Index: Index(1), Strength: Float(0.5)}, []byte(`{"index":1,"strength":0.5}`), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -323,9 +323,9 @@ func TestPBRMetallicRoughness_MarshalJSON(t *testing.T) { want []byte wantErr bool }{ - {"default", &PBRMetallicRoughness{MetallicFactor: Float64(1), RoughnessFactor: Float64(1), BaseColorFactor: &[4]float32{1, 1, 1, 1}}, []byte(`{}`), false}, - {"empty", &PBRMetallicRoughness{MetallicFactor: Float64(0), RoughnessFactor: Float64(0)}, []byte(`{"metallicFactor":0,"roughnessFactor":0}`), false}, - {"nodefault", &PBRMetallicRoughness{MetallicFactor: Float64(0.5), RoughnessFactor: Float64(0.5), BaseColorFactor: &[4]float32{1, 0.5, 1, 1}}, []byte(`{"baseColorFactor":[1,0.5,1,1],"metallicFactor":0.5,"roughnessFactor":0.5}`), false}, + {"default", &PBRMetallicRoughness{MetallicFactor: Float(1), RoughnessFactor: Float(1), BaseColorFactor: &[4]float32{1, 1, 1, 1}}, []byte(`{}`), false}, + {"empty", &PBRMetallicRoughness{MetallicFactor: Float(0), RoughnessFactor: Float(0)}, []byte(`{"metallicFactor":0,"roughnessFactor":0}`), false}, + {"nodefault", &PBRMetallicRoughness{MetallicFactor: Float(0.5), RoughnessFactor: Float(0.5), BaseColorFactor: &[4]float32{1, 0.5, 1, 1}}, []byte(`{"baseColorFactor":[1,0.5,1,1],"metallicFactor":0.5,"roughnessFactor":0.5}`), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/math.go b/math.go index 04b82fb..1a4904d 100644 --- a/math.go +++ b/math.go @@ -56,9 +56,9 @@ func NormalizeRGB(v [3]float32) [3]uint8 { // to its float represtation (from 0 to 1). func DenormalizeRGB(v [3]uint8) [3]float32 { return [3]float32{ - linearize(float64(v[0]) / 255), - linearize(float64(v[1]) / 255), - linearize(float64(v[2]) / 255), + linearize(float32(v[0]) / 255), + linearize(float32(v[1]) / 255), + linearize(float32(v[2]) / 255), } } @@ -77,9 +77,9 @@ func NormalizeRGBA(v [4]float32) [4]uint8 { // to its float represtation (from 0 to 1). func DenormalizeRGBA(v [4]uint8) [4]float32 { return [4]float32{ - linearize(float64(v[0]) / 255), - linearize(float64(v[1]) / 255), - linearize(float64(v[2]) / 255), + linearize(float32(v[0]) / 255), + linearize(float32(v[1]) / 255), + linearize(float32(v[2]) / 255), float32(v[3]) / 255, } } @@ -98,9 +98,9 @@ func NormalizeRGB64(v [3]float32) [3]uint16 { // to its float represtation (from 0 to 1). func DenormalizeRGB64(v [3]uint16) [3]float32 { return [3]float32{ - linearize(float64(v[0]) / 65535), - linearize(float64(v[1]) / 65535), - linearize(float64(v[2]) / 65535), + linearize(float32(v[0]) / 65535), + linearize(float32(v[1]) / 65535), + linearize(float32(v[2]) / 65535), } } @@ -119,18 +119,18 @@ func NormalizeRGBA64(v [4]float32) [4]uint16 { // to its float represtation (from 0 to 1). func DenormalizeRGBA64(v [4]uint16) [4]float32 { return [4]float32{ - linearize(float64(v[0]) / 65535), - linearize(float64(v[1]) / 65535), - linearize(float64(v[2]) / 65535), + linearize(float32(v[0]) / 65535), + linearize(float32(v[1]) / 65535), + linearize(float32(v[2]) / 65535), float32(v[3]) / 65535, } } -func linearize(v float64) float32 { +func linearize(v float32) float32 { if v <= 0.04045 { return float32(v / 12.92) } - return float32(math.Pow((v+0.055)/1.055, 2.4)) + return float32(math.Pow(float64(v+0.055)/1.055, 2.4)) } func deliniarize(v float32) float32 { diff --git a/modeler/read_test.go b/modeler/read_test.go index 0cb2347..e51b15a 100644 --- a/modeler/read_test.go +++ b/modeler/read_test.go @@ -149,11 +149,11 @@ func TestReadAccessorAllocs(t *testing.T) { BufferView: gltf.Index(0), ComponentType: gltf.ComponentFloat, Type: gltf.AccessorVec3, Count: 4, } - testFunc := func(t *testing.T, buf [][3]float32, want float64) { + testFunc := func(t *testing.T, buf [][3]float32, want float32) { allocs := testing.AllocsPerRun(10, func() { ReadAccessor(doc, acr, buf) }) - if allocs != want { + if allocs != float64(want) { t.Errorf("ReadAccessor expected %v allocs got %v", want, allocs) } diff --git a/modeler/write.go b/modeler/write.go index 25d1ff3..abbc6c1 100644 --- a/modeler/write.go +++ b/modeler/write.go @@ -90,12 +90,12 @@ func WriteJoints(doc *gltf.Document, data interface{}) uint32 { // and fills the last buffer with the vertices data. // If success it returns the index of the new accessor. func WritePosition(doc *gltf.Document, data [][3]float32) uint32 { - min := [3]float64{math.MaxFloat64, math.MaxFloat64, math.MaxFloat64} - max := [3]float64{-math.MaxFloat64, -math.MaxFloat64, -math.MaxFloat64} + min := [3]float32{math.MaxFloat32, math.MaxFloat32, math.MaxFloat32} + max := [3]float32{-math.MaxFloat32, -math.MaxFloat32, -math.MaxFloat32} for _, v := range data { for i, x := range v { - min[i] = math.Min(min[i], float64(x)) - max[i] = math.Max(max[i], float64(x)) + min[i] = float32(math.Min(float64(min[i]), float64(x))) + max[i] = float32(math.Max(float64(max[i]), float64(x))) } } index := WriteAccessor(doc, gltf.TargetArrayBuffer, data) diff --git a/modeler/write_test.go b/modeler/write_test.go index 0a1930b..5d580af 100644 --- a/modeler/write_test.go +++ b/modeler/write_test.go @@ -129,7 +129,7 @@ func TestWritePosition(t *testing.T) { }, args{[][3]float32{{1, 2, 3}, {0, 0, -1}}}, 1, &gltf.Document{ Accessors: []*gltf.Accessor{ {}, - {BufferView: gltf.Index(0), Count: 2, Type: gltf.AccessorVec3, ComponentType: gltf.ComponentFloat, Max: []float64{1, 2, 3}, Min: []float64{0, 0, -1}}, + {BufferView: gltf.Index(0), Count: 2, Type: gltf.AccessorVec3, ComponentType: gltf.ComponentFloat, Max: []float32{1, 2, 3}, Min: []float32{0, 0, -1}}, }, BufferViews: []*gltf.BufferView{ {ByteLength: 24, Target: gltf.TargetArrayBuffer}, diff --git a/struct.go b/struct.go index 8539669..6dfab58 100644 --- a/struct.go +++ b/struct.go @@ -11,8 +11,8 @@ func Index(i uint32) *uint32 { return &i } -// Float64 is an utility function that returns a pointer to a float64. -func Float64(val float64) *float64 { +// Float is an utility function that returns a pointer to a float32. +func Float(val float32) *float32 { return &val } @@ -74,8 +74,8 @@ type Accessor struct { Normalized bool `json:"normalized,omitempty"` // Specifies whether integer data values should be normalized. Count uint32 `json:"count" validate:"required"` // The number of attributes referenced by this accessor. Type AccessorType `json:"type" validate:"lte=6"` - Max []float64 `json:"max,omitempty" validate:"omitempty,lte=16"` // Maximum value of each component in this attribute. - Min []float64 `json:"min,omitempty" validate:"omitempty,lte=16"` // Minimum value of each component in this attribute. + Max []float32 `json:"max,omitempty" validate:"omitempty,lte=16"` // Maximum value of each component in this attribute. + Min []float32 `json:"min,omitempty" validate:"omitempty,lte=16"` // Minimum value of each component in this attribute. Sparse *Sparse `json:"sparse,omitempty"` // Sparse storage of attributes that deviate from their initialization value. } @@ -168,16 +168,16 @@ type Node struct { Camera *uint32 `json:"camera,omitempty"` Children []uint32 `json:"children,omitempty" validate:"omitempty,unique"` Skin *uint32 `json:"skin,omitempty"` - Matrix [16]float64 `json:"matrix"` // A 4x4 transformation matrix stored in column-major order. + Matrix [16]float32 `json:"matrix"` // A 4x4 transformation matrix stored in column-major order. Mesh *uint32 `json:"mesh,omitempty"` - Rotation [4]float64 `json:"rotation" validate:"omitempty,dive,gte=-1,lte=1"` // The node's unit quaternion rotation in the order (x, y, z, w), where w is the scalar. - Scale [3]float64 `json:"scale"` - Translation [3]float64 `json:"translation"` - Weights []float64 `json:"weights,omitempty"` // The weights of the instantiated Morph Target. + Rotation [4]float32 `json:"rotation" validate:"omitempty,dive,gte=-1,lte=1"` // The node's unit quaternion rotation in the order (x, y, z, w), where w is the scalar. + Scale [3]float32 `json:"scale"` + Translation [3]float32 `json:"translation"` + Weights []float32 `json:"weights,omitempty"` // The weights of the instantiated Morph Target. } // MatrixOrDefault returns the node matrix if it represents a valid affine matrix, else return the default one. -func (n *Node) MatrixOrDefault() [16]float64 { +func (n *Node) MatrixOrDefault() [16]float32 { if n.Matrix == emptyMatrix { return DefaultMatrix } @@ -185,7 +185,7 @@ func (n *Node) MatrixOrDefault() [16]float64 { } // RotationOrDefault returns the node rotation if it represents a valid quaternion, else return the default one. -func (n *Node) RotationOrDefault() [4]float64 { +func (n *Node) RotationOrDefault() [4]float32 { if n.Rotation == emptyRotation { return DefaultRotation } @@ -193,7 +193,7 @@ func (n *Node) RotationOrDefault() [4]float64 { } // ScaleOrDefault returns the node scale if it represents a valid scale factor, else return the default one. -func (n *Node) ScaleOrDefault() [3]float64 { +func (n *Node) ScaleOrDefault() [3]float32 { if n.Scale == emptyScale { return DefaultScale } @@ -201,7 +201,7 @@ func (n *Node) ScaleOrDefault() [3]float64 { } // TranslationOrDefault returns the node translation. -func (n *Node) TranslationOrDefault() [3]float64 { +func (n *Node) TranslationOrDefault() [3]float32 { return n.Translation } @@ -228,20 +228,20 @@ type Camera struct { type Orthographic struct { Extensions Extensions `json:"extensions,omitempty"` Extras interface{} `json:"extras,omitempty"` - Xmag float64 `json:"xmag"` // The horizontal magnification of the view. - Ymag float64 `json:"ymag"` // The vertical magnification of the view. - Zfar float64 `json:"zfar" validate:"gt=0,gtfield=Znear"` // The distance to the far clipping plane. - Znear float64 `json:"znear" validate:"gte=0"` // The distance to the near clipping plane. + Xmag float32 `json:"xmag"` // The horizontal magnification of the view. + Ymag float32 `json:"ymag"` // The vertical magnification of the view. + Zfar float32 `json:"zfar" validate:"gt=0,gtfield=Znear"` // The distance to the far clipping plane. + Znear float32 `json:"znear" validate:"gte=0"` // The distance to the near clipping plane. } // Perspective camera containing properties to create a perspective projection matrix. type Perspective struct { Extensions Extensions `json:"extensions,omitempty"` Extras interface{} `json:"extras,omitempty"` - AspectRatio *float64 `json:"aspectRatio,omitempty"` - Yfov float64 `json:"yfov"` // The vertical field of view in radians. - Zfar *float64 `json:"zfar,omitempty"` // The distance to the far clipping plane. - Znear float64 `json:"znear"` // The distance to the near clipping plane. + AspectRatio *float32 `json:"aspectRatio,omitempty"` + Yfov float32 `json:"yfov"` // The vertical field of view in radians. + Zfar *float32 `json:"zfar,omitempty"` // The distance to the far clipping plane. + Znear float32 `json:"znear"` // The distance to the near clipping plane. } // A Mesh is a set of primitives to be rendered. A node can contain one mesh. A node's transform places the mesh in the scene. @@ -250,7 +250,7 @@ type Mesh struct { Extras interface{} `json:"extras,omitempty"` Name string `json:"name,omitempty"` Primitives []*Primitive `json:"primitives" validate:"required,gt=0,dive"` - Weights []float64 `json:"weights,omitempty"` + Weights []float32 `json:"weights,omitempty"` } // Primitive defines the geometry to be rendered with the given material. @@ -273,14 +273,14 @@ type Material struct { NormalTexture *NormalTexture `json:"normalTexture,omitempty"` OcclusionTexture *OcclusionTexture `json:"occlusionTexture,omitempty"` EmissiveTexture *TextureInfo `json:"emissiveTexture,omitempty"` - EmissiveFactor [3]float64 `json:"emissiveFactor,omitempty" validate:"dive,gte=0,lte=1"` + EmissiveFactor [3]float32 `json:"emissiveFactor,omitempty" validate:"dive,gte=0,lte=1"` AlphaMode AlphaMode `json:"alphaMode,omitempty" validate:"lte=2"` - AlphaCutoff *float64 `json:"alphaCutoff,omitempty" validate:"omitempty,gte=0"` + AlphaCutoff *float32 `json:"alphaCutoff,omitempty" validate:"omitempty,gte=0"` DoubleSided bool `json:"doubleSided,omitempty"` } // AlphaCutoffOrDefault returns the scale if it is not nil, else return the default one. -func (m *Material) AlphaCutoffOrDefault() float64 { +func (m *Material) AlphaCutoffOrDefault() float32 { if m.AlphaCutoff == nil { return 0.5 } @@ -293,11 +293,11 @@ type NormalTexture struct { Extras interface{} `json:"extras,omitempty"` Index *uint32 `json:"index,omitempty"` TexCoord uint32 `json:"texCoord,omitempty"` // The index of texture's TEXCOORD attribute used for texture coordinate mapping. - Scale *float64 `json:"scale,omitempty"` + Scale *float32 `json:"scale,omitempty"` } // ScaleOrDefault returns the scale if it is not nil, else return the default one. -func (n *NormalTexture) ScaleOrDefault() float64 { +func (n *NormalTexture) ScaleOrDefault() float32 { if n.Scale == nil { return 1 } @@ -310,11 +310,11 @@ type OcclusionTexture struct { Extras interface{} `json:"extras,omitempty"` Index *uint32 `json:"index,omitempty"` TexCoord uint32 `json:"texCoord,omitempty"` // The index of texture's TEXCOORD attribute used for texture coordinate mapping. - Strength *float64 `json:"strength,omitempty" validate:"omitempty,gte=0,lte=1"` + Strength *float32 `json:"strength,omitempty" validate:"omitempty,gte=0,lte=1"` } // StrengthOrDefault returns the strength if it is not nil, else return the default one. -func (o *OcclusionTexture) StrengthOrDefault() float64 { +func (o *OcclusionTexture) StrengthOrDefault() float32 { if o.Strength == nil { return 1 } @@ -327,13 +327,13 @@ type PBRMetallicRoughness struct { Extras interface{} `json:"extras,omitempty"` BaseColorFactor *[4]float32 `json:"baseColorFactor,omitempty" validate:"omitempty,dive,gte=0,lte=1"` BaseColorTexture *TextureInfo `json:"baseColorTexture,omitempty"` - MetallicFactor *float64 `json:"metallicFactor,omitempty" validate:"omitempty,gte=0,lte=1"` - RoughnessFactor *float64 `json:"roughnessFactor,omitempty" validate:"omitempty,gte=0,lte=1"` + MetallicFactor *float32 `json:"metallicFactor,omitempty" validate:"omitempty,gte=0,lte=1"` + RoughnessFactor *float32 `json:"roughnessFactor,omitempty" validate:"omitempty,gte=0,lte=1"` MetallicRoughnessTexture *TextureInfo `json:"metallicRoughnessTexture,omitempty"` } // MetallicFactorOrDefault returns the metallic factor if it is not nil, else return the default one. -func (p *PBRMetallicRoughness) MetallicFactorOrDefault() float64 { +func (p *PBRMetallicRoughness) MetallicFactorOrDefault() float32 { if p.MetallicFactor == nil { return 1 } @@ -341,7 +341,7 @@ func (p *PBRMetallicRoughness) MetallicFactorOrDefault() float64 { } // RoughnessFactorOrDefault returns the roughness factor if it is not nil, else return the default one. -func (p *PBRMetallicRoughness) RoughnessFactorOrDefault() float64 { +func (p *PBRMetallicRoughness) RoughnessFactorOrDefault() float32 { if p.RoughnessFactor == nil { return 1 } diff --git a/struct_test.go b/struct_test.go index a865663..959ec41 100644 --- a/struct_test.go +++ b/struct_test.go @@ -114,11 +114,11 @@ func TestNode_MatrixOrDefault(t *testing.T) { tests := []struct { name string n *Node - want [16]float64 + want [16]float32 }{ {"default", &Node{Matrix: DefaultMatrix}, DefaultMatrix}, {"zeros", &Node{Matrix: emptyMatrix}, DefaultMatrix}, - {"other", &Node{Matrix: [16]float64{2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2}}, [16]float64{2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2}}, + {"other", &Node{Matrix: [16]float32{2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2}}, [16]float32{2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -133,11 +133,11 @@ func TestNode_RotationOrDefault(t *testing.T) { tests := []struct { name string n *Node - want [4]float64 + want [4]float32 }{ {"default", &Node{Rotation: DefaultRotation}, DefaultRotation}, {"zeros", &Node{Rotation: emptyRotation}, DefaultRotation}, - {"other", &Node{Rotation: [4]float64{1, 2, 3, 4}}, [4]float64{1, 2, 3, 4}}, + {"other", &Node{Rotation: [4]float32{1, 2, 3, 4}}, [4]float32{1, 2, 3, 4}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -152,11 +152,11 @@ func TestNode_ScaleOrDefault(t *testing.T) { tests := []struct { name string n *Node - want [3]float64 + want [3]float32 }{ {"default", &Node{Scale: DefaultScale}, DefaultScale}, {"zeros", &Node{Scale: emptyScale}, DefaultScale}, - {"other", &Node{Scale: [3]float64{1, 2, 3}}, [3]float64{1, 2, 3}}, + {"other", &Node{Scale: [3]float32{1, 2, 3}}, [3]float32{1, 2, 3}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -171,10 +171,10 @@ func TestNode_TranslationOrDefault(t *testing.T) { tests := []struct { name string n *Node - want [3]float64 + want [3]float32 }{ {"default", &Node{Translation: DefaultTranslation}, DefaultTranslation}, - {"other", &Node{Translation: [3]float64{1, 2, 3}}, [3]float64{1, 2, 3}}, + {"other", &Node{Translation: [3]float32{1, 2, 3}}, [3]float32{1, 2, 3}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -207,10 +207,10 @@ func TestOcclusionTexture_StrengthOrDefault(t *testing.T) { tests := []struct { name string o *OcclusionTexture - want float64 + want float32 }{ {"empty", &OcclusionTexture{}, 1}, - {"other", &OcclusionTexture{Strength: Float64(2)}, 2}, + {"other", &OcclusionTexture{Strength: Float(2)}, 2}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -225,10 +225,10 @@ func TestNormalTexture_ScaleOrDefault(t *testing.T) { tests := []struct { name string n *NormalTexture - want float64 + want float32 }{ {"empty", &NormalTexture{}, 1}, - {"other", &NormalTexture{Scale: Float64(2)}, 2}, + {"other", &NormalTexture{Scale: Float(2)}, 2}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -243,10 +243,10 @@ func TestMaterial_AlphaCutoffOrDefault(t *testing.T) { tests := []struct { name string m *Material - want float64 + want float32 }{ {"empty", &Material{}, 0.5}, - {"other", &Material{AlphaCutoff: Float64(2)}, 2}, + {"other", &Material{AlphaCutoff: Float(2)}, 2}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -261,10 +261,10 @@ func TestPBRMetallicRoughness_MetallicFactorOrDefault(t *testing.T) { tests := []struct { name string p *PBRMetallicRoughness - want float64 + want float32 }{ {"empty", &PBRMetallicRoughness{}, 1}, - {"other", &PBRMetallicRoughness{MetallicFactor: Float64(2)}, 2}, + {"other", &PBRMetallicRoughness{MetallicFactor: Float(2)}, 2}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -279,10 +279,10 @@ func TestPBRMetallicRoughness_RoughnessFactorOrDefault(t *testing.T) { tests := []struct { name string p *PBRMetallicRoughness - want float64 + want float32 }{ {"empty", &PBRMetallicRoughness{}, 1}, - {"other", &PBRMetallicRoughness{RoughnessFactor: Float64(2)}, 2}, + {"other", &PBRMetallicRoughness{RoughnessFactor: Float(2)}, 2}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {