manyfold3d/mittsu-mesh_analysis

View on GitHub
lib/mittsu/mesh_analysis/progressive_mesh.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
require "mittsu/mesh_analysis/vertex_split"

module Mittsu::MeshAnalysis
  class ProgressiveMesh < Mittsu::Mesh
    attr_reader :vertex_splits

    def initialize(geometry = Geometry.new, material = Mittsu::MeshBasicMaterial.new(color: (rand * 0xffffff).to_i))
      super
      @vertex_splits = []
    end

    def progressify(ratio: 0.95)
      decimator = Mittsu::MeshAnalysis::Decimator.new(@geometry)
      @geometry, @vertex_splits = decimator.decimate(
        @geometry.faces.count * (1 - ratio),
        vertex_splits: true
      )
    end
  end
end