Skip to content

Commit

Permalink
Add Option for Mesh Repair (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimfoltz authored and thomthom committed Feb 28, 2017
1 parent c40a136 commit 9520b0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/sketchup-stl/html/importer.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<input type="checkbox" id="chkMergeCoplanar" />
<span class="ui_string">Merge coplanar faces</span>
</label>

<label id="repair" class="checkbox">
<input type="checkbox" id="chkRepair" />
<span class="ui_string">Attempt to repair non-solids</span>
</label>
</fieldset>

<fieldset id="scale">
Expand Down
17 changes: 13 additions & 4 deletions src/sketchup-stl/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def initialize
@stl_units = UNIT_MILLIMETERS
@stl_merge = false
@stl_preserve_origin = true
@stl_repair = true
@option_window = nil # (See comment at top of `stl_dialog()`.)
end

Expand All @@ -72,7 +73,7 @@ def do_options
stl_dialog
end

def load_file(path,status)
def load_file(path, status)
begin
status = main(path)
rescue => exception
Expand All @@ -91,6 +92,7 @@ def main(filename)
@stl_merge = read_setting('merge_faces', @stl_merge)
@stl_units = read_setting('import_units', @stl_units)
@stl_preserve_origin = read_setting('preserve_origin', @stl_preserve_origin)
@stl_repair = read_setting('repair', @stl_repair)
# Wrap everything into one operation, ensuring compatibility with older
# SketchUp versions that did not feature the disable_ui argument.
model = Sketchup.active_model
Expand Down Expand Up @@ -132,8 +134,9 @@ def main(filename)
end
# Check if the imported geometry is a solid. If not, attempt to
# automatically repair it.
unless is_solid?(container.entities)
if @stl_repair && !is_solid?(container.entities)
Sketchup.status_text = STL.translate('Repairing geometry...')
puts 'Repairing...' # TODO(thomthom): Temp debug! Remove!
heal_geometry(container.entities)
end
# Clean up geometry.
Expand Down Expand Up @@ -334,7 +337,7 @@ def stl_dialog
:left => 300,
:top => 200,
:width => 330,
:height => 265
:height => 300
}

window = UI::WebDialog.new(window_options)
Expand All @@ -347,14 +350,17 @@ def stl_dialog
merge_faces = read_setting('merge_faces', @stl_merge)
current_unit = read_setting('import_units', @stl_units)
preserve_origin = read_setting('preserve_origin', @stl_preserve_origin)
stl_repair = read_setting('repair', @stl_stl_repair)
# Ensure they are in proper format. (Recovers from old settings)
merge_faces = ( merge_faces == true )
current_unit = current_unit.to_i
preserve_origin = ( preserve_origin == true )
stl_repair = ( stl_repair == true )
# Update webdialog values.
dialog.update_value('chkMergeCoplanar', merge_faces)
dialog.update_value('lstUnits', current_unit)
dialog.update_value('chkPreserveOrigin', preserve_origin)
dialog.update_value('chkRepair', stl_repair)
# Localize UI
ui_strings = window.parse_params(params)
translated_ui_strings = ui_strings.map { |string|
Expand All @@ -368,18 +374,21 @@ def stl_dialog
options = {
:merge_coplanar => dialog.get_element_value('chkMergeCoplanar'),
:units => dialog.get_element_value('lstUnits'),
:preserve_origin => dialog.get_element_value('chkPreserveOrigin')
:preserve_origin => dialog.get_element_value('chkPreserveOrigin'),
:repair => dialog.get_element_value('chkRepair')
}
dialog.close
#p options # DEBUG
# Convert to Ruby values.
@stl_merge = (options[:merge_coplanar] == 'true')
@stl_preserve_origin = (options[:preserve_origin] == 'true')
@stl_units = options[:units].to_i
@stl_stl_repair = (options[:repair] == 'true')
# Store last used preferences.
write_setting('merge_faces', @stl_merge)
write_setting('import_units', @stl_units)
write_setting('preserve_origin', @stl_preserve_origin)
write_setting('repair', @stl_stl_repair)
}

window.add_action_callback('Event_Cancel') { |dialog, params|
Expand Down

0 comments on commit 9520b0b

Please sign in to comment.