Class: Bayonetta::BoneInfos

Inherits:
LibBin::Structure
  • Object
show all
Defined in:
lib/bayonetta/wmb.rb

Instance Method Summary collapse

Constructor Details

#initializeBoneInfos

Returns a new instance of BoneInfos.



529
530
531
532
# File 'lib/bayonetta/wmb.rb', line 529

def initialize
  @indexes = UByteList::new
  @weights = UByteList::new
end

Instance Method Details

#get_indexesObject



544
545
546
# File 'lib/bayonetta/wmb.rb', line 544

def get_indexes
  get_indexes_and_weights.collect { |bi, _| bi }
end

#get_indexes_and_weightsObject



534
535
536
537
538
539
540
541
542
# File 'lib/bayonetta/wmb.rb', line 534

def get_indexes_and_weights
  res = []
  4.times { |i|
    bi = (@indexes.data >> (i*8)) & 0xff
    bw = (@weights.data >> (i*8)) & 0xff
    res.push [bi, bw] if bw > 0
  }
  res
end

#get_weightsObject



548
549
550
# File 'lib/bayonetta/wmb.rb', line 548

def get_weights
  get_indexes_and_weights.collect { |_, bw| bw }
end

#remap_indexes(map) ⇒ Object



552
553
554
555
556
# File 'lib/bayonetta/wmb.rb', line 552

def remap_indexes(map)
  new_bone_info = get_indexes_and_weights.collect { |bi, bw| [map[bi], bw] }
  set_indexes_and_weights(new_bone_info)
  self
end

#set_indexes_and_weights(bone_info) ⇒ Object



558
559
560
561
562
563
564
565
566
567
568
569
570
# File 'lib/bayonetta/wmb.rb', line 558

def set_indexes_and_weights(bone_info)
  raise "Too many bone information #{bone_info.inspect}!" if bone_info.length > 4
  @indexes.data = 0
  @weights.data = 0
  bone_info.each_with_index { |(bi, bw), i|
    raise "Invalid bone index #{bi}!" if bi > 255 || bi < 0
    @indexes.data |= ( bi << (i*8) )
    bw = 0 if bw < 0
    bw = 255 if bw > 255
    @weights.data |= (bw << (i*8) )
  }
  self
end

#to_aObject



572
573
574
# File 'lib/bayonetta/wmb.rb', line 572

def to_a
  get_indexes_and_weights
end