src/STL.php
public static function fromString(string $stlFileContentString) : STL
    {
        $class = new self();

        // Extract name.
        $lines = explode("\n", $stlFileContentString);
        preg_match("/solid (.+)/", $lines[0], $matches);
        $class->setSolidName($matches[1]);

        // Extract facets.
        foreach ($lines as $line) {
            if (preg_match("/facet normal (.+)/", $line)) {
                // Get this line and the following, making a block of facets.
                $string = next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $class->addFacetNormal(STLFacetNormal::fromString($string));
            }
        }

        return $class;
    }
public static function fromString(string $stlFileContentString) : STL
    {
        $class = new self();

        // Extract name.
        $lines = explode("\n", $stlFileContentString);
        preg_match("/solid (.+)/", $lines[0], $matches);
        $class->setSolidName($matches[1]);

        // Extract facets.
        foreach ($lines as $line) {
            if (preg_match("/facet normal (.+)/", $line)) {
                // Get this line and the following, making a block of facets.
                $string = next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $string .= next($lines) . "\n";
                $class->addFacetNormal(STLFacetNormal::fromString($string));
            }
        }

        return $class;
    }
public static function fromString ( string $ stlFileContentString ) : STL { $ class = new self ( ) ; // Extract name. $ lines = explode ( "\n" , $ stlFileContentString ) ; preg_match ( "/solid (.+)/" , $ lines [ 0 ] , $ matches ) ; $ class -> setSolidName ( $ matches [ 1 ] ) ; // Extract facets. foreach ( $ lines as $ line ) { if ( preg_match ( "/facet normal (.+)/" , $ line ) ) { // Get this line and the following, making a block of facets. $ string = next ( $ lines ) . "\n" ; $ string .= next ( $ lines ) . "\n" ; $ string .= next ( $ lines ) . "\n" ; $ string .= next ( $ lines ) . "\n" ; $ string .= next ( $ lines ) . "\n" ; $ string .= next ( $ lines ) . "\n" ; $ string .= next ( $ lines ) . "\n" ; $ class -> addFacetNormal ( STLFacetNormal :: fromString ( $ string ) ) ; } } return $ class ; }
Class constructor from an STL string.

Example STL file string: see STLTest $stlFileString property.

@param string $stlFileContentString
@return STL
Class constructor from an STL string .