This library provides PHP 7 functionality for reading and writing from and to 3D objects stored in STereoLithography (STL) files, useful for manipulating 3D objects for 3D Printing.
Add this to your composer.json file:
[...]
"require": {
[...]
"php3d/stl": "1.*"
}
Then run composer:
composer.phar install
Read an STL file:
use php3d\stl\STL;
use php3d\stl\STLFacetNormal;
$stl = STL::fromString(file_get_contents("/path/to/file.stl"));
Add a new facet:
$stl->addFacetNormal(STLFacetNormal::fromArray(array(
"coordinates" => array( 1, 2, 3), // Facet normal coordinates.
"vertex" => array(
array(
3, 4, 5
),
array(
3, 4, 5
),
array(
3, 4, 5
)
)
)));
To split an object:
(new STLSplit($stl))->split();
Write back to file:
file_put_contents("/path/to/file.stl", $stl->toString());