Sha256: 0617383ff828f6b964f5ce4e96cea341eb2c50891cc4739a09a9e863be7a25a1

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 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: nil, smooth: false)
    retained = parent.createShape()
    retained.begin_shape(PShape::TRIANGLES)
    if (smooth)
      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_array: [], smooth: false)
    rshapes = []
    (0 ... mesh.length).each do |i|
      rshapes.push(meshToVBO(mesh: mesh[i], smooth: smth))
    end
    return rshapes
  end
end


Version data entries

6 entries across 6 versions & 1 rubygems

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