1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-17 04:40:08 -07:00

Change required stl2pov version to 3.3.0

Update used stl2pov version to speed up rendering process
This commit is contained in:
David Hübner 2017-04-19 15:52:03 +02:00
parent 74ccc71ac5
commit 854aa7bae9
2 changed files with 43 additions and 30 deletions

View File

@ -15,14 +15,6 @@ global_settings {
assumed_gamma 2 assumed_gamma 2
} }
camera {
location <-1.3, -1.1, 0.7>
angle 40
sky z
look_at 0
right -1*x
}
#declare Min = min_extent( main_mesh ); #declare Min = min_extent( main_mesh );
#declare Max = max_extent( main_mesh ); #declare Max = max_extent( main_mesh );
@ -32,13 +24,25 @@ camera {
Max.z-Min.z Max.z-Min.z
); );
// Calculate camera distace factor - if object is large on Y axis and Z axis move camera further
#declare cameraDistance = (((Max.x-Min.x)*(1/MaxLength) > 0.3) & ((Max.y-Min.y)*(1/MaxLength) > 0.95) ? 1: 0.9);
camera
{
location <-1.5*cameraDistance, -1*cameraDistance, 1.1*cameraDistance>
angle 45
sky z
look_at 0
translate <0,0.05,-0.15>
right -1*x
}
object object
{ {
main_mesh main_mesh
Center_Trans(main_mesh, x+y+z) Center_Trans(main_mesh, x+y+z)
// rotate <-90,0,0> // rotate <-90,0,0>
rotate <0,90,0> rotate <0,90,0>
texture texture
@ -49,4 +53,3 @@ object
scale (1/MaxLength) scale (1/MaxLength)
} }

View File

@ -85,8 +85,7 @@ class StlRendererService
* *
* Generated file is saved to tmp directory specifed in constructor of this class and path to file is returned * Generated file is saved to tmp directory specifed in constructor of this class and path to file is returned
* *
* * stl2pov (version 3.3.0) - https://rsmith.home.xs4all.nl/software/py-stl-stl2pov.html
* stl2pov (version 2.5.0) - https://rsmith.home.xs4all.nl/software/py-stl-stl2pov.html
* *
* @param string $file The full path to stl file * @param string $file The full path to stl file
* @return string Return the full path to the generated pov scene * @return string Return the full path to the generated pov scene
@ -97,42 +96,54 @@ class StlRendererService
if(!file_exists($file)) { if(!file_exists($file)) {
throw new FileNotFoundException($file); throw new FileNotFoundException($file);
} }
if(pathinfo($file, PATHINFO_EXTENSION) != 'stl') {
throw new ConvertingFailedException($file, 'POV', 'Wrong input filetype');
}
// Save the current working directory and change directory to tmp dir
// stl2pov outputs converted file to current directory and destination can not be changed
$cwd = getcwd();
chdir($this->tmpDir);
$filename = pathinfo($file)['filename'];
// Run stl2pov conversion
$processBuilder = new ProcessBuilder(); $processBuilder = new ProcessBuilder();
$process = $processBuilder->setPrefix($this->stl2pov) $process = $processBuilder->setPrefix($this->stl2pov)
->setArguments([ ->setArguments([
$file $file
]) ])
->getProcess(); ->getProcess();
$process->mustRun();
$process->start(); // Check if file created successfully
if (!file_exists($filename.'.inc')) {
$modelInc = null; throw new ConvertingFailedException($file, 'POV');
}
// Read std output from stl2pov command
foreach ($process as $type => $data) {
if (Process::OUT === $type) {
$modelInc .= $data;
}
};
// Load contents of .inc file to variable
$incFile = file_get_contents($filename.'.inc',LOCK_EX);
// Replace mesh name in loaded inc file to match declaration in scene layout // Replace mesh name in loaded inc file to match declaration in scene layout
$modelInc = preg_replace('/#declare m_(.*) = mesh/','#declare m_MYSOLID = mesh',$modelInc); $incFile = preg_replace('/# declare m_(.*) = mesh/','#declare m_MYSOLID = mesh',$incFile);
// Get filename of new file // Remove no longer needed inc file
$outputFile = $this->tmpDir.DIRECTORY_SEPARATOR.pathinfo($file)['filename'].'.pov'; unlink($filename.'.inc');
chdir($cwd);
// Get desired filepath of new pov file
$outputFile = $this->tmpDir.DIRECTORY_SEPARATOR.$filename.'.pov';
// Load contents of pov-ray layout file // Load contents of pov-ray layout file
$layout = file_get_contents($this->layout); $layout = file_get_contents($this->layout);
// Try to write contents of converted inc file and concat int with scene definition // Try to write contents of converted inc file and concat int with scene definitions
if (!file_put_contents($outputFile, $modelInc, LOCK_EX)) { if (!file_put_contents($outputFile, $incFile, LOCK_EX)) {
throw new ConvertingFailedException($file, 'POV'); throw new ConvertingFailedException($file, 'POV');
} }
if(!file_put_contents($outputFile, $layout, FILE_APPEND | LOCK_EX)) { if(!file_put_contents($outputFile, $layout, FILE_APPEND | LOCK_EX)) {
throw new ConvertingFailedException($file, 'POV'); throw new ConvertingFailedException($file, 'POV');
} }
if (!strlen(file_get_contents($outputFile))) { if (!file_exists($outputFile)) {
throw new ConvertingFailedException($file, 'POV'); throw new ConvertingFailedException($file, 'POV');
} }
@ -183,8 +194,7 @@ class StlRendererService
"+A0.5", "+A0.5",
"-D", "-D",
])->getProcess(); ])->getProcess();
$process->mustRun();
$process->run();
if(!file_exists($outputFile)) { if(!file_exists($outputFile)) {
throw new RenderFailedException("{$to}{$filename}.png"); throw new RenderFailedException("{$to}{$filename}.png");