Class: Collada::Parser::Accessor
- Inherits:
-
Object
- Object
- Collada::Parser::Accessor
- Includes:
- Enumerable
- Defined in:
- lib/collada/parser/support.rb
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
Returns the value of attribute array.
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#stride ⇒ Object
readonly
Returns the value of attribute stride.
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each ⇒ Object
-
#initialize(array, parameters, count, options = {}) ⇒ Accessor
constructor
A new instance of Accessor.
- #read(index) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(array, parameters, count, options = {}) ⇒ Accessor
Returns a new instance of Accessor.
221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/collada/parser/support.rb', line 221 def initialize(array, parameters, count, = {}) @array = array @parameters = parameters @count = count # Chunk size and stride are usually the same in many cases. @chunk_size = @parameters.inject(0) {|sum, parameter| sum + parameter.size} @offset = ([:offset] || 0).to_i @stride = ([:stride] || @chunk_size).to_i end |
Instance Attribute Details
#array ⇒ Object (readonly)
Returns the value of attribute array.
233 234 235 |
# File 'lib/collada/parser/support.rb', line 233 def array @array end |
#count ⇒ Object (readonly)
Returns the value of attribute count.
237 238 239 |
# File 'lib/collada/parser/support.rb', line 237 def count @count end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
235 236 237 |
# File 'lib/collada/parser/support.rb', line 235 def names @names end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
238 239 240 |
# File 'lib/collada/parser/support.rb', line 238 def offset @offset end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
234 235 236 |
# File 'lib/collada/parser/support.rb', line 234 def parameters @parameters end |
#stride ⇒ Object (readonly)
Returns the value of attribute stride.
239 240 241 |
# File 'lib/collada/parser/support.rb', line 239 def stride @stride end |
Class Method Details
.parse(doc, element, arrays = {}) ⇒ Object
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/collada/parser/support.rb', line 268 def self.parse(doc, element, arrays = {}) if (array_id = element.attributes['source']) array_id.sub!(/^#/, '') array = arrays[array_id] else array = Mesh.parse_arrays(doc, element).first end raise UnsupportedFeature.new("Source array binding must be valid (id=#{array_id})") unless array parameters = parse_parameters(doc, element) count = element.attributes['count'].to_i = { :offset => element.attributes['offset'], :stride => element.attributes['stride'], } self.new(array, parameters, count, ) end |
.parse_parameters(doc, element) ⇒ Object
262 263 264 265 266 |
# File 'lib/collada/parser/support.rb', line 262 def self.parse_parameters(doc, element) OrderedMap.parse(element, 'param', 'name') do |param_element| Parameter.parse(doc, param_element) end end |
Instance Method Details
#[](index) ⇒ Object
248 249 250 |
# File 'lib/collada/parser/support.rb', line 248 def [] index read(index).delete_if{|(name, value)| name == nil} end |
#each ⇒ Object
256 257 258 259 260 |
# File 'lib/collada/parser/support.rb', line 256 def each size.times.each do |i| yield self[i] end end |
#read(index) ⇒ Object
241 242 243 244 245 246 |
# File 'lib/collada/parser/support.rb', line 241 def read index base = @offset + (index * @stride) values = @array[base, @chunk_size] @parameters.collect{|parameter| [parameter.name, parameter.read(values.shift(parameter.size))]} end |
#size ⇒ Object
252 253 254 |
# File 'lib/collada/parser/support.rb', line 252 def size (@array.size - @offset) / @stride end |