Skip to content

Commit ea04ddf

Browse files
committed
move mittsu mesh loading into geom analysis job
only place it's now used
1 parent 8d449c3 commit ea04ddf

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

app/jobs/analysis/geometric_analysis_job.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class Analysis::GeometricAnalysisJob < ApplicationJob
99
def perform(file_id)
1010
# Get model
1111
file = ModelFile.find(file_id)
12-
return unless file.loadable?
12+
return unless self.class.loader(file)
1313
if SiteSettings.analyse_manifold
1414
status[:step] = "jobs.analysis.geometric_analysis.loading_mesh" # i18n-tasks-use t('jobs.analysis.geometric_analysis.loading_mesh')
1515
# Get mesh
16-
mesh = file.mesh
16+
mesh = self.class.load_mesh(file)
1717
if mesh
1818
status[:step] = "jobs.analysis.geometric_analysis.manifold_check" # i18n-tasks-use t('jobs.analysis.geometric_analysis.manifold_check')
1919
# Check for manifold mesh
@@ -39,4 +39,18 @@ def perform(file_id)
3939
end
4040
end
4141
end
42+
43+
def self.loader(file)
44+
case file.extension
45+
when "stl"
46+
Mittsu::STLLoader
47+
when "obj"
48+
Mittsu::OBJLoader
49+
end
50+
end
51+
52+
def self.load_mesh(file)
53+
# TODO: This can be better, but needs changes upstream in Mittsu to allow loaders to parse from an IO object
54+
loader(file)&.new&.parse(file.attachment.read)
55+
end
4256
end

app/models/model_file.rb

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,6 @@ def scene
178178
end
179179
end
180180

181-
def mesh
182-
# TODO: This can be better, but needs changes upstream in Mittsu to allow loaders to parse from an IO object
183-
loader&.new&.parse(attachment.read)
184-
end
185-
memoize :mesh
186-
187181
def reattach!
188182
if attachment.id != path_within_library || attachment.storage_key != model.library.storage_key
189183
old_path = attachment.id
@@ -201,7 +195,7 @@ def convert_later(format, delay: 0.seconds)
201195
end
202196

203197
def loadable?
204-
loader.present?
198+
true
205199
end
206200

207201
delegate :manifold?, to: :mesh
@@ -269,15 +263,6 @@ def presupported_version_is_presupported
269263
end
270264
end
271265

272-
def loader
273-
case extension
274-
when "stl"
275-
Mittsu::STLLoader
276-
when "obj"
277-
Mittsu::OBJLoader
278-
end
279-
end
280-
281266
def clear_presupported_relation
282267
unsupported_version&.update presupported_version: nil
283268
end

spec/jobs/analysis/geometric_analysis_job_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,41 @@
1010
end
1111

1212
before do
13-
allow(file).to receive(:mesh).and_return(mesh)
13+
allow(described_class).to receive(:load_mesh).with(file).and_return(mesh)
1414
allow(ModelFile).to receive(:find).and_call_original
1515
allow(ModelFile).to receive(:find).with(file.id).and_return(file)
1616
allow(SiteSettings).to receive(:analyse_manifold).and_return(true)
1717
end
1818

1919
it "does not create Problems for a good mesh" do
20-
allow(file).to receive(:mesh).and_return(mesh)
20+
allow(described_class).to receive(:load_mesh).with(file).and_return(mesh)
2121
expect { described_class.perform_now(file.id) }.not_to change(Problem, :count)
2222
end
2323

2424
it "creates a Problem for a non-manifold mesh" do # rubocop:todo RSpec/MultipleExpectations
2525
allow(mesh).to receive(:manifold?).and_return(false)
26-
allow(file).to receive(:mesh).and_return(mesh)
26+
allow(described_class).to receive(:load_mesh).with(file).and_return(mesh)
2727
expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(0).to(1)
2828
expect(Problem.first.category).to eq "non_manifold"
2929
end
3030

3131
it "removes a manifold problem if the mesh is OK" do
32-
allow(file).to receive(:mesh).and_return(mesh)
32+
allow(described_class).to receive(:load_mesh).with(file).and_return(mesh)
3333
create(:problem, problematic: file, category: :non_manifold)
3434
expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(1).to(0)
3535
end
3636

3737
it "creates a Problem for an inside-out mesh" do # rubocop:todo RSpec/MultipleExpectations
3838
pending "not currently working reliably"
3939
allow(mesh).to receive(:solid?).and_return(false)
40-
allow(file).to receive(:mesh).and_return(mesh)
40+
allow(described_class).to receive(:load_mesh).with(file).and_return(mesh)
4141
expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(0).to(1)
4242
expect(Problem.first.category).to eq "inside_out"
4343
end
4444

4545
it "removes an inside-out problem if the mesh is OK" do
4646
pending "not currently working reliably"
47-
allow(file).to receive(:mesh).and_return(mesh)
47+
allow(described_class).to receive(:load_mesh).with(file).and_return(mesh)
4848
create(:problem, problematic: file, category: :inside_out)
4949
expect { described_class.perform_now(file.id) }.to change(Problem, :count).from(1).to(0)
5050
end

0 commit comments

Comments
 (0)