Sha256: f387d50df1a0f7405b506bea07fef544bc173d492141de18b7d7406feede83f5

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

############################################
# mesh_to_vbo.rb
# a ruby library to convert toxi.mesh object
# to vbo (PShape) written by Martin Prout
# make use of Processing::Proxy mixin
############################################
class MeshToVBO
  include Processing::Proxy
  
  attr_reader :parent
  
  def initialize(parent)
    @parent = parent   
  end
  
  def meshToVBO(mesh, smth)
    retained = parent.createShape()
    retained.begin_shape(PShape::TRIANGLES)
    if (smth)
      mesh.computeVertexNormals()
      mesh.getFaces.each do |f|
        retained.normal(f.a.normal.x, f.a.normal.y, f.a.normal.z)
        retained.vertex(f.a.x, f.a.y, f.a.z)
        retained.normal(f.b.normal.x, f.b.normal.y, f.b.normal.z)
        retained.vertex(f.b.x, f.b.y, f.b.z)
        retained.normal(f.c.normal.x, f.c.normal.y, f.c.normal.z)
        retained.vertex(f.c.x, f.c.y, f.c.z)
      end
    else
      mesh.getFaces.each do |f|
        retained.normal(f.normal.x, f.normal.y, f.normal.z)
        retained.vertex(f.a.x, f.a.y, f.a.z)
        retained.vertex(f.b.x, f.b.y, f.b.z)
        retained.vertex(f.c.x, f.c.y, f.c.z)
      end
    end
    retained.end_shape()
    return retained
  end
  
  # variant
  # input array of meshes, output an array of shapes
  def meshToRetained(mesh, smth)
    rshapes = []
    (0 ... mesh.length).each do |i|
      rshapes.push(meshToVBO(mesh[i], smth))
    end
    return rshapes
  end
end


Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
ruby-processing-2.6.3 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.6.2 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.6.1 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.6.0 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.5.1 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.5.0 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.4.4 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.4.3 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.4.2 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb
ruby-processing-2.4.1 samples/external_library/java_processing/toxiclibs/library/vbo/mesh_to_vbo.rb