-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for non-manifold mesh errors #1981
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
79e3e73
Add tests for mesh manifold check
Floppy 03070ca
add manifold? method to mittsu geometry classes
Floppy e5c3e86
working manifold analysis for Mittsu::Geometry
Floppy 3733cda
remove buffergeometry test and method
Floppy 58c9bea
move solid? and manifold? to Object3D instead of Geometry
Floppy 8298513
improve tests
Floppy a10d76e
detect solid objects
Floppy 942f6be
change to use our own mittsu fork
Floppy 372d2a2
lint
Floppy be544d1
add non-manifold and inside-out problem categories
Floppy 37ba60f
add loader support for STL
Floppy 048d04e
refactor expectations for model file analysis tests
Floppy 731442b
change mesh analysis to included module
Floppy 2da170d
enqueue geometric analysis job when necessary
Floppy ad13378
create problems for non-manifold and inside-out meshes
Floppy 72739bf
add partials for non manifold and inside out errors
Floppy 89d74be
add translations for manifold errors
Floppy 9cb8eeb
fix duplicate lists showing in the wrong place
Floppy dbd6956
update mittsu to get STL loader fix
Floppy 540e1a9
update messages
Floppy e736cde
add a lower-priority queue for deep analysis jobs
Floppy f6222b8
things with no geometry are manifold and solid
Floppy 4a66e66
traverse object children to make sure they're all manifold
Floppy 38c82aa
lint
Floppy fe11d96
don't use Object3D#traverse it seems to take forever
Floppy 1f7f143
improve tests a little
Floppy 4df741a
only recalculate digest and queue geometric check if it looks like th…
Floppy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Scan::GeometricAnalysisJob < ApplicationJob | ||
queue_as :analysis | ||
|
||
def perform(file_id) | ||
# Get model | ||
file = ModelFile.find(file_id) | ||
return if file.nil? | ||
# Get mesh | ||
mesh = file.mesh | ||
if mesh | ||
# Check for manifold mesh | ||
manifold = mesh.manifold? | ||
Problem.create_or_clear( | ||
file, | ||
:non_manifold, | ||
!manifold | ||
) | ||
# If the mesh is manifold, we can check if it's inside out | ||
if manifold | ||
Problem.create_or_clear( | ||
file, | ||
:inside_out, | ||
!mesh.solid? | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module MeshAnalysis | ||
def solid? | ||
# Shortcut if there is nothing here | ||
return true if geometry.nil? && children.empty? | ||
# Recurse children to see if they are solid | ||
children_are_solid = children.map { |x| x.solid? }.all? | ||
solid = true | ||
if geometry | ||
# Make sure material is double sided | ||
prev_side = material.side | ||
material.side = Mittsu::DoubleSide | ||
# Make a raycaster from a vertex and the face normal | ||
face = geometry.faces.first | ||
r = Mittsu::Raycaster.new(geometry.vertices[face.b], face.normal, 1e-9) | ||
intersections = r.intersect_object(self, true) | ||
# Restore material | ||
material.side = prev_side | ||
# We want an even number of intersections | ||
solid = (intersections.length % 2 == 0) | ||
end | ||
solid && children_are_solid | ||
end | ||
|
||
def manifold? | ||
# Shortcut if there is nothing here | ||
return true if geometry.nil? && children.empty? | ||
# Recurse children to see if they are manifold | ||
children_are_manifold = children.map { |x| x.manifold? }.all? | ||
# Detect manifold geometry in this object | ||
edges = {} | ||
# For each face, record its edges in the edge hash | ||
geometry&.faces&.each do |face| | ||
update_edge_hash face.a, face.b, edges | ||
update_edge_hash face.b, face.c, edges | ||
update_edge_hash face.c, face.a, edges | ||
end | ||
# If there's anything left in the edge hash, then either | ||
# we have holes, or we have badly oriented faces | ||
edges.empty? && children_are_manifold | ||
end | ||
|
||
private | ||
|
||
# Updates edge hash with the passed vertex indexes | ||
# First, the reverse edge is searched for in the hash | ||
# If found, it's removed as we've got a match | ||
# If not, we record this edge in the hash | ||
def update_edge_hash(v1, v2, edges) | ||
return if edges.delete "#{v2}->#{v1}" | ||
edges["#{v1}->#{v2}"] = true | ||
end | ||
end | ||
|
||
module Mittsu | ||
class Object3D | ||
include MeshAnalysis | ||
end | ||
|
||
class Face3 | ||
def flip! | ||
tmp = @a | ||
@a = @c | ||
@c = tmp | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<td><%= icon("files", t(".title")) %></td> | ||
<td><%= link_to problem.problematic.name, [problem.problematic.model.library, problem.problematic.model, problem.problematic] %></td> | ||
<td><%= t ".title" %></td> | ||
<td><%= link_to "Open", [problem.problematic.model.library, problem.problematic.model, problem.problematic], class: "btn btn-primary" %></td> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<td><%= icon("files", t(".title")) %></td> | ||
<td><%= link_to problem.problematic.name, [problem.problematic.model.library, problem.problematic.model, problem.problematic] %></td> | ||
<td><%= t ".title" %></td> | ||
<td><%= link_to "Open", [problem.problematic.model.library, problem.problematic.model, problem.problematic], class: "btn btn-primary" %></td> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Load mittsu extensions | ||
require Rails.root.join("app/lib/mesh_analysis") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method
perform
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.