Class: Analysis::GeometricAnalysisJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/analysis/geometric_analysis_job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.load_mesh(file) ⇒ Object



52
53
54
55
# File 'app/jobs/analysis/geometric_analysis_job.rb', line 52

def self.load_mesh(file)
  # TODO: This can be better, but needs changes upstream in Mittsu to allow loaders to parse from an IO object
  loader(file)&.new&.parse(file.attachment.read)
end

.loader(file) ⇒ Object



43
44
45
46
47
48
49
50
# File 'app/jobs/analysis/geometric_analysis_job.rb', line 43

def self.loader(file)
  case file.extension.downcase
  when "stl"
    Mittsu::STLLoader
  when "obj"
    Mittsu::OBJLoader
  end
end

Instance Method Details

#perform(file_id) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/jobs/analysis/geometric_analysis_job.rb', line 9

def perform(file_id)
  # Get model
  file = ModelFile.find(file_id)
  return unless self.class.loader(file)
  if SiteSettings.analyse_manifold
    status[:step] = "jobs.analysis.geometric_analysis.loading_mesh" # i18n-tasks-use t('jobs.analysis.geometric_analysis.loading_mesh')
    # Get mesh
    mesh = self.class.load_mesh(file)
    if mesh
      status[:step] = "jobs.analysis.geometric_analysis.manifold_check" # i18n-tasks-use t('jobs.analysis.geometric_analysis.manifold_check')
      # Check for manifold mesh
      manifold = mesh.manifold?
      Problem.create_or_clear(
        file,
        :non_manifold,
        !manifold
      )
      # Temporarily disabled for release
      # # If the mesh is manifold, we can check if it's inside out
      # if manifold
      # i18n-tasks-use t('jobs.analysis.geometric_analysis.direction_check')
      # status[:step] = "jobs.analysis.geometric_analysis.direction_check"
      #   Problem.create_or_clear(
      #     file,
      #     :inside_out,
      #     !mesh.solid?
      #   )
      # end
    else
      raise MeshLoadError.new
    end
  end
end