Class: Collada::Parser::Controller::Skin::VertexWeights

Inherits:
Sampler
  • Object
show all
Includes:
Enumerable
Defined in:
lib/collada/parser/controller.rb

Instance Attribute Summary collapse

Attributes inherited from Sampler

#id, #inputs

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sampler

#[], parse_inputs

Constructor Details

#initialize(id, inputs, counts, vertices) ⇒ VertexWeights

Returns a new instance of VertexWeights.



33
34
35
36
37
38
39
40
41
# File 'lib/collada/parser/controller.rb', line 33

def initialize(id, inputs, counts, vertices)
	super id, inputs
	
	@counts = counts
	@vertices = vertices
	
	# The number of indices per vertex:
	@stride = @inputs.sort_by(&:offset).last.offset + 1
end

Instance Attribute Details

#countsObject (readonly)

Returns the value of attribute counts.



43
44
45
# File 'lib/collada/parser/controller.rb', line 43

def counts
  @counts
end

#verticesObject (readonly)

Returns the value of attribute vertices.



44
45
46
# File 'lib/collada/parser/controller.rb', line 44

def vertices
  @vertices
end

Class Method Details

.parse(doc, element, sources) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/collada/parser/controller.rb', line 76

def self.parse(doc, element, sources)
	inputs = parse_inputs(doc, element, sources)
	
	counts = element.elements['vcount'].text.split(/\s+/).collect &:to_i
	vertices = element.elements['v'].text.split(/\s+/).collect &:to_i
	
	self.new(element.attributes['id'], inputs, counts, vertices)
end

Instance Method Details

#eachObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/collada/parser/controller.rb', line 61

def each
	vertex_offset = 0
	
	@counts.each do |count|
		# Grap all the vertices
		weights = count.times.collect do |vertex_index|
			vertex(vertex_offset + vertex_index)
		end
		
		yield weights
		
		vertex_offset += count
	end
end

#sizeObject



46
47
48
# File 'lib/collada/parser/controller.rb', line 46

def size
	@counts.size
end

#vertex(index) ⇒ Object

Vertices by index:



51
52
53
54
55
56
57
58
59
# File 'lib/collada/parser/controller.rb', line 51

def vertex(index)
	offset = @stride * index
	
	attributes = @inputs.collect do |input|
		input[@vertices[offset + input.offset]]
	end
	
	return Attribute.flatten(attributes)
end