The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

CAD::Mesh3D::FormatSTL - read/write 3D stereolithography files

DON'T USE

Please don't use this module. CAD::Mesh3D::FormatSTL exists only for CAD::Mesh3D::STL to use during testing and to overcome limitations in CAD::Format::STL. If you think you want to use this directly, use CAD::Format::STL instead, and encourage the author to implement and release the known bug-fix that is in the existing issues, possibly patching it per the instructions in the "Known Issues" in CAD::Mesh3D::STL.

SYNOPSIS

Reading:

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

Writing:

my $stl = CAD::Mesh3D::FormatSTL->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::Mesh3D::FormatSTL->reader("foo.stl");
my $writer = CAD::Mesh3D::FormatSTL->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::Mesh3D::FormatSTL->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/

COPYRIGHT

CAD::Format::STL Copyright (C) 2007 Eric L. Wilhelm, All Rights Reserved. CAD::Mesh3D::FormatSTL Copyright (C) 2021 Peter C. Jones, 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, the CAD::Mesh3D developer feels justified in providing the patched version along with CAD::Mesh3D, which requires the patched version to be used in Windows. However, to avoid offense and confusion, the file/module that includes the patch has been renamed to CAD::Mesh3D::FormatSTL in this distribution.

If the original author of CAD::Format::STL ever publishes a newer version that doesn't contain the bug, this patched version will not be used by CAD::Mesh3D, and the official module will be used instead.