mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Read OBJ files. #324
This commit is contained in:
		
							parent
							
								
									fbe70ac15b
								
							
						
					
					
						commit
						1998801a58
					
				
					 7 changed files with 35 additions and 6 deletions
				
			
		
							
								
								
									
										23
									
								
								lib/Slic3r/Format/OBJ.pm
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								lib/Slic3r/Format/OBJ.pm
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | |||
| package Slic3r::Format::OBJ; | ||||
| use Moo; | ||||
| 
 | ||||
| sub read_file { | ||||
|     my $self = shift; | ||||
|     my ($file) = @_; | ||||
|      | ||||
|     open my $fh, '<', $file or die "Failed to open $file\n"; | ||||
|     my $vertices = []; | ||||
|     my $facets = []; | ||||
|     while (my $_ = <$fh>) { | ||||
|         if (/^v ([^ ]+)\s+([^ ]+)\s+([^ ]+)/) { | ||||
|             push @$vertices, [$1, $2, $3]; | ||||
|         } elsif (/^f (\d+).*? (\d+).*? (\d+).*?/) { | ||||
|             push @$facets, [ $1-1, $2-1, $3-1 ]; | ||||
|         } | ||||
|     } | ||||
|     close $fh; | ||||
|      | ||||
|     return Slic3r::TriangleMesh->new(vertices => $vertices, facets => $facets); | ||||
| } | ||||
| 
 | ||||
| 1; | ||||
|  | @ -205,7 +205,7 @@ sub load { | |||
|     my $self = shift; | ||||
|      | ||||
|     my $dir = $Slic3r::GUI::SkeinPanel::last_skein_dir || $Slic3r::GUI::SkeinPanel::last_config_dir || ""; | ||||
|     my $dialog = Wx::FileDialog->new($self, 'Choose a STL or AMF file:', $dir, "", $Slic3r::GUI::SkeinPanel::model_wildcard, wxFD_OPEN); | ||||
|     my $dialog = Wx::FileDialog->new($self, 'Choose a file (STL/OBJ/AMF):', $dir, "", $Slic3r::GUI::SkeinPanel::model_wildcard, wxFD_OPEN); | ||||
|     if ($dialog->ShowModal != wxID_OK) { | ||||
|         $dialog->Destroy; | ||||
|         return; | ||||
|  |  | |||
|  | @ -161,7 +161,7 @@ sub new { | |||
|     return $self; | ||||
| } | ||||
| 
 | ||||
| our $model_wildcard = "STL files (*.stl)|*.stl;*.STL|AMF files (*.amf)|*.amf;*.AMF;*.xml;*.XML"; | ||||
| our $model_wildcard = "STL files (*.stl)|*.stl;*.STL|OBJ files (*.obj)|*.obj;*.OBJ|AMF files (*.amf)|*.amf;*.AMF;*.xml;*.XML"; | ||||
| our $ini_wildcard = "INI files *.ini|*.ini;*.INI"; | ||||
| our $gcode_wildcard = "G-code files *.gcode|*.gcode;*.GCODE"; | ||||
| 
 | ||||
|  | @ -188,7 +188,7 @@ sub do_slice { | |||
| 
 | ||||
|         my $input_file; | ||||
|         if (!$params{reslice}) { | ||||
|             my $dialog = Wx::FileDialog->new($self, 'Choose a STL or AMF file to slice:', $dir, "", $model_wildcard, wxFD_OPEN); | ||||
|             my $dialog = Wx::FileDialog->new($self, 'Choose a file to slice (STL/OBJ/AMF):', $dir, "", $model_wildcard, wxFD_OPEN); | ||||
|             if ($dialog->ShowModal != wxID_OK) { | ||||
|                 $dialog->Destroy; | ||||
|                 return; | ||||
|  |  | |||
|  | @ -29,12 +29,16 @@ sub add_object_from_file { | |||
|         my $mesh = Slic3r::Format::STL->read_file($input_file); | ||||
|         $mesh->check_manifoldness; | ||||
|         $object = $self->add_object_from_mesh($mesh); | ||||
|     } elsif ($input_file =~ /\.obj$/i) { | ||||
|         my $mesh = Slic3r::Format::OBJ->read_file($input_file); | ||||
|         $mesh->check_manifoldness; | ||||
|         $object = $self->add_object_from_mesh($mesh); | ||||
|     } elsif ( $input_file =~ /\.amf(\.xml)?$/i) { | ||||
|         my ($materials, $meshes_by_material) = Slic3r::Format::AMF->read_file($input_file); | ||||
|         $_->check_manifoldness for values %$meshes_by_material; | ||||
|         $object = $self->add_object_from_mesh($meshes_by_material->{_} || +(values %$meshes_by_material)[0]); | ||||
|     } else { | ||||
|         die "Input file must have .stl or .amf(.xml) extension\n"; | ||||
|         die "Input file must have .stl, .obj or .amf(.xml) extension\n"; | ||||
|     } | ||||
|     $object->input_file($input_file); | ||||
|     return $object; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Alessandro Ranellucci
						Alessandro Ranellucci