++ed by:
1 non-PAUSE user
Author image Peter C. Jones
and 1 contributors

NAME

CAD::Format::STL - read/write 3D stereolithography files

SYNOPSIS

Reading:

  my $stl = CAD::Format::STL->new->load("foo.stl");
  # what about the part/multipart?
  my @facets = $stl->part->facets;

Writing:

  my $stl = CAD::Format::STL->new;
  my $part = $stl->add_part("my part");
  $part->add_facets(@faces);
  $stl->save("foo.stl");
  # or $stl->save(binary => "foo.stl");

Streaming read/write:

  my $reader = CAD::Format::STL->reader("foo.stl");
  my $writer = CAD::Format::STL->writer(binary => "bar.stl");
  while(my $part = $reader->next_part) {
    my $part_name = $part->name;
    $writer->start_solid($part_name);
    while(my @data = $part->facet) {
      my ($normal, @vertices) = @data;
      my @v1 = @{$vertices[0]};
      my @v2 = @{$vertices[0]};
      my @v3 = @{$vertices[0]};
      # that's just for illustration
      $writer->facet(\@v1, \@v2, \@v3);
      # note the omitted normal
    }
    $writer->end_solid;
  }

ABOUT

This module provides object-oriented methods to read and write the STL (Stereo Lithography) file format in both binary and ASCII forms. The STL format is a simple set of 3D triangles.

Constructor

new

  my $stl = CAD::Format::STL->new;

add_part

Create a new part in the stl.

  my $part = $stl->add_part("name");

Optionally, add the faces directly:

  my $part = $stl->add_part("name", @faces);

part

Get the part at $index. Negative indices are valid.

  my $part = $stl->part($index);

Throws an error if there is no such part.

I/O Methods

load

Load an STL file (auto-detects binary/ascii)

  $stl = $stl->load("filename.stl");

Optionally, explicitly declare binary mode:

  $stl = $stl->load(binary => "filename.stl");

The $self object is returned to allow e.g. chaining to new().

The filename may also be a filehandle.

_read_ascii

  $self->_read_ascii($filehandle);

get_<something>

These functions are currently only used internally.

get_triangle
get_ulong
get_float32
get_short

_read_binary

  $self->_read_binary($filehandle);

save

  $stl->save("filename.stl");

  $stl->save(binary => "filename.stl");

_write_binary

  $self->_write_binary($filehandle);

_write_ascii

  $self->_write_ascii($filehandle);

AUTHOR

Eric Wilhelm @ <ewilhelm at cpan dot org>

http://scratchcomputing.com/

BUGS

If you found this module on CPAN, please report any bugs or feature requests through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

If you pulled this development version from my /svn/, please contact me directly.

COPYRIGHT

Copyright (C) 2007 Eric L. Wilhelm, All Rights Reserved.

NO WARRANTY

Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

PATCHED BY CAD::Mesh3D

Per the LICENSE following the same terms as Perl, the Artistic License allows publishing a modified or patched version under the same name as long as it is made freely available or by allowing the original copyright holder to include my modifications in the standard version of the package. As the core modifications have been in CAD::Format::STL's issue tracker since Feb 2013, I feel justified in providing the patched version along with CAD::Mesh3D, which requires the patched version to be used in Windows.

If the original author ever publishes a newer version that doesn't contain the bug, this patched version will not be installed by CAD::Mesh3D's installation procedure.