@@ -694,3 +694,53 @@ func TestReadColor64(t *testing.T) {
694694 })
695695 }
696696}
697+
698+ func TestReadInverseBindMatrices (t * testing.T ) {
699+ type args struct {
700+ data []byte
701+ acr * gltf.Accessor
702+ buffer [][4 ][4 ]float32
703+ }
704+ tests := []struct {
705+ name string
706+ args args
707+ want [][4 ][4 ]float32
708+ wantErr bool
709+ }{
710+ {"base" , args {[]byte {
711+ 0 , 0 , 128 , 63 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
712+ 0 , 0 , 0 , 64 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
713+ 0 , 0 , 64 , 64 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
714+ 0 , 0 , 128 , 64 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
715+ }, & gltf.Accessor {BufferView : gltf .Index (0 ), Count : 1 , Type : gltf .AccessorMat4 , ComponentType : gltf .ComponentFloat }, nil },
716+ [][4 ][4 ]float32 {{{1 , 2 , 3 , 4 }}}, false ,
717+ },
718+ {"incorrect-type" , args {[]byte {}, & gltf.Accessor {
719+ BufferView : gltf .Index (0 ), Type : gltf .AccessorMat2 , ComponentType : gltf .ComponentFloat ,
720+ }, nil }, nil , true },
721+ {"incorrect-componenttype" , args {[]byte {}, & gltf.Accessor {
722+ BufferView : gltf .Index (0 ), Type : gltf .AccessorMat4 , ComponentType : gltf .ComponentByte ,
723+ }, nil }, nil , true },
724+ }
725+ for _ , tt := range tests {
726+ t .Run (tt .name , func (t * testing.T ) {
727+ doc := & gltf.Document {
728+ BufferViews : []* gltf.BufferView {
729+ {Buffer : 0 , ByteLength : len (tt .args .data )},
730+ },
731+ Buffers : []* gltf.Buffer {
732+ {Data : tt .args .data , ByteLength : len (tt .args .data )},
733+ },
734+ }
735+ got , err := modeler .ReadInverseBindMatrices (doc , tt .args .acr , tt .args .buffer )
736+ if (err != nil ) != tt .wantErr {
737+ t .Errorf ("ReadInverseBindMatrices() error = %v, wantErr %v" , err , tt .wantErr )
738+ return
739+ }
740+ if ! reflect .DeepEqual (got , tt .want ) {
741+ t .Errorf ("ReadInverseBindMatrices() = %v, want %v" , got , tt .want )
742+ }
743+ })
744+ }
745+
746+ }
0 commit comments