Class: Assimp::Mesh

Inherits:
FFI::Struct
  • Object
show all
Extended by:
StructAccessors
Defined in:
lib/assimp/mesh.rb

Instance Method Summary collapse

Methods included from StructAccessors

extended, has_ref?, struct_array_attr_accessor, struct_array_attr_checker, struct_array_attr_reader, struct_array_attr_writer, struct_attr_accessor, struct_attr_reader, struct_attr_writer, struct_ref_array_attr_accessor, struct_ref_array_attr_reader, struct_ref_array_attr_writer

Instance Method Details

#colorsObject



214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/assimp/mesh.rb', line 214

def colors
  cs = self[:colors].to_a
  cs.collect { |c_ptr|
    if c_ptr.null?
      nil
    else
      s = Color4D.size
      num_vertices.times.collect { |i|
        Color4D::new(c_ptr+i*s)
      }
    end
  }
end

#set_colors(index, colors) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/assimp/mesh.rb', line 228

def set_colors(index, colors)
  @colors = [nil]*MAX_NUMBER_OF_COLOR_SETS unless @colors
  raise "Invalid colors index #{index}!" if index < 0 || index >= MAX_NUMBER_OF_COLOR_SETS
  unless colors && colors.length > 0
    @colors[index] = nil
    return self
  end
  raise "Invalid colors count: #{colors.length}!" if num_vertices != colors.length
  ptr = FFI::MemoryPointer::new(Assimp::Color4D, num_vertices)
  s = Assimp::Color4D.size
  colors.each_with_index { |v, i|
    ptr.put_array_of_uint8(i*s, v.pointer.read_array_of_uint8(s))
  }
  @colors[index] = ptr
  self[:colors][index] = ptr
  self
end

#set_texture_coords(index, uvs) ⇒ Object



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/assimp/mesh.rb', line 260

def set_texture_coords(index, uvs)
  @texture_coords = [nil]*MAX_NUMBER_OF_TEXTURECOORDS unless @texture_coords
  raise "Invalid texture_coords index #{index}!" if index < 0 || index >= MAX_NUMBER_OF_TEXTURECOORDS
  unless uvs && uvs.length > 0
    @texture_coords[index] = nil
    return self
  end
  raise "Invalid texture_coords count: #{uvs.length}!" if num_vertices != uvs.length
  ptr = FFI::MemoryPointer::new(Assimp::Vector3D, num_vertices)
  s = Assimp::Vector3D.size
  uvs.each_with_index { |v, i|
    ptr.put_array_of_uint8(i*s, v.pointer.read_array_of_uint8(s))
  }
  @texture_coords[index] = ptr
  self[:texture_coords][index] = ptr
  self
end

#texture_coordsObject



246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/assimp/mesh.rb', line 246

def texture_coords
  tcs = self[:texture_coords].to_a
  tcs.collect { |tc_ptr|
    if tc_ptr.null?
      nil
    else
      s = Vector3D.size
      num_vertices.times.collect { |i|
        Vector3D::new(tc_ptr+i*s)
      }
    end
  }
end