Class: Stagecraft::Skin

Inherits:
Object
  • Object
show all
Defined in:
lib/stagecraft/core/skin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(joints:, inverse_bind_matrices: nil, skeleton: nil) ⇒ Skin

Returns a new instance of Skin.



7
8
9
10
11
12
13
14
# File 'lib/stagecraft/core/skin.rb', line 7

def initialize(joints:, inverse_bind_matrices: nil, skeleton: nil)
  @joints = joints.freeze
  @inverse_bind_matrices = inverse_bind_matrices || Array.new(joints.length) { Larb::Mat4.identity }
  @skeleton = skeleton
  unless @inverse_bind_matrices.length == joints.length
    raise ArgumentError, "inverse bind matrix count must match joint count"
  end
end

Instance Attribute Details

#inverse_bind_matricesObject (readonly)

Returns the value of attribute inverse_bind_matrices.



5
6
7
# File 'lib/stagecraft/core/skin.rb', line 5

def inverse_bind_matrices
  @inverse_bind_matrices
end

#jointsObject (readonly)

Returns the value of attribute joints.



5
6
7
# File 'lib/stagecraft/core/skin.rb', line 5

def joints
  @joints
end

#skeletonObject (readonly)

Returns the value of attribute skeleton.



5
6
7
# File 'lib/stagecraft/core/skin.rb', line 5

def skeleton
  @skeleton
end

Instance Method Details

#joint_matrices(mesh) ⇒ Object



16
17
18
19
20
21
# File 'lib/stagecraft/core/skin.rb', line 16

def joint_matrices(mesh)
  mesh_inverse = mesh.world_matrix.inverse
  joints.each_with_index.map do |joint, index|
    inverse_bind_matrices[index] * joint.world_matrix * mesh_inverse
  end
end