Class: Collada::Conversion::VertexFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/collada/conversion/mesh.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(format) ⇒ VertexFormat

Returns a new instance of VertexFormat.



27
28
29
# File 'lib/collada/conversion/mesh.rb', line 27

def initialize(format)
	@format = format
end

Class Method Details

.[](format) ⇒ Object



48
49
50
# File 'lib/collada/conversion/mesh.rb', line 48

def self.[] (format)
	self.new(format)
end

Instance Method Details

#call(attributes) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/collada/conversion/mesh.rb', line 31

def call(attributes)
	attributes = Collada::Parser::Attribute.to_hash(attributes) unless Hash === attributes
	
	@format.collect do |name, components|
		value = attributes[name]
	
		raise ArgumentError.new("Invalid vertex format, undefined property #{name} for #{attributes.inspect}!") unless value
	
		case components
		when Array
			components.collect{|key| value[key]}
		else
			components.call(value)
		end
	end.flatten
end

#merge(extra_format) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/collada/conversion/mesh.rb', line 52

def merge(extra_format)
	format = @format.dup
	
	extra_format.each do |key, value|
		format[key] = value
	end
	
	self.class.new(format)
end

#with_vertex_indexObject



62
63
64
# File 'lib/collada/conversion/mesh.rb', line 62

def with_vertex_index
	merge(vertex: [:index])
end