Fix inherited 3MF triangle property group resolution
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 50s
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 50s
This commit is contained in:
@@ -2,7 +2,11 @@
|
||||
|
||||
namespace Tests\Unit;
|
||||
|
||||
use App\Services\ManufacturingFileValidator;
|
||||
use App\Services\ProductImageRenderer;
|
||||
use App\Services\ThreeMfGeometryExtractor;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use RuntimeException;
|
||||
use Tests\TestCase;
|
||||
use ZipArchive;
|
||||
@@ -131,6 +135,91 @@ class ThreeMfGeometryExtractorTest extends TestCase
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
private function validatedTetrahedron(string $triangleProperties): string
|
||||
{
|
||||
$faces = '';
|
||||
foreach ([[0, 2, 1], [0, 1, 3], [0, 3, 2], [1, 2, 3]] as [$v1, $v2, $v3]) {
|
||||
$faces .= '<triangle v1="'.$v1.'" v2="'.$v2.'" v3="'.$v3.'" '.$triangleProperties.'/>';
|
||||
}
|
||||
$resources = '<m:colorgroup xmlns:m="http://schemas.microsoft.com/3dmanufacturing/material/2015/02" id="2">'
|
||||
.'<m:color color="#FF0000"/><m:color color="#0000FF"/><m:color color="#00FF0080"/></m:colorgroup>'
|
||||
.'<object id="1" type="model" pid="2" pindex="0"><mesh><vertices>'
|
||||
.'<vertex x="0" y="0" z="0"/><vertex x="10" y="0" z="0"/>'
|
||||
.'<vertex x="0" y="10" z="0"/><vertex x="0" y="0" z="10"/>'
|
||||
.'</vertices><triangles>'.$faces.'</triangles></mesh></object>';
|
||||
$path = $this->validArchive($this->model($resources, '<item objectid="1"/>'));
|
||||
try {
|
||||
$validated = (new ManufacturingFileValidator)->validate(new UploadedFile($path, 'tetrahedron.3mf', test: true));
|
||||
$this->assertSame('3mf', $validated['extension']);
|
||||
} catch (\Throwable $exception) {
|
||||
unlink($path);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/** @return array<string, array{string}> */
|
||||
public static function flatInheritedProperties(): array
|
||||
{
|
||||
return [
|
||||
'p2 and p3 default to p1' => ['p1="1"'],
|
||||
'all vertex properties specified' => ['p1="1" p2="1" p3="1"'],
|
||||
];
|
||||
}
|
||||
|
||||
#[DataProvider('flatInheritedProperties')]
|
||||
public function test_inherited_triangle_property_group_applies_flat_override_through_png_rendering(string $properties): void
|
||||
{
|
||||
$path = $this->validatedTetrahedron($properties);
|
||||
try {
|
||||
$scene = $this->extractor->extract($path);
|
||||
$this->assertSame(4, $scene['triangle_count']);
|
||||
foreach ($scene['triangles'] as $triangle) {
|
||||
$this->assertSame([0, 0, 255, 255], $triangle['color']);
|
||||
}
|
||||
$rendered = (new ProductImageRenderer)->render($scene['triangles']);
|
||||
$this->assertSame('image/png', $rendered['mime']);
|
||||
$image = imagecreatefromstring($rendered['bytes']);
|
||||
$this->assertNotFalse($image);
|
||||
try {
|
||||
$pixel = imagecolorsforindex($image, imagecolorat($image, 256, 256));
|
||||
$this->assertSame(0, $pixel['red']);
|
||||
$this->assertSame(0, $pixel['green']);
|
||||
$this->assertGreaterThan(0, $pixel['blue']);
|
||||
$this->assertSame(0, $pixel['alpha']);
|
||||
} finally {
|
||||
imagedestroy($image);
|
||||
}
|
||||
} finally {
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_inherited_triangle_property_group_rejects_interpolated_override(): void
|
||||
{
|
||||
$path = $this->validatedTetrahedron('p1="0" p2="1" p3="0"');
|
||||
try {
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessageMatches('/interpolat/i');
|
||||
(new ProductImageRenderer)->render($this->extractor->extract($path)['triangles']);
|
||||
} finally {
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_inherited_triangle_property_group_rejects_transparent_override(): void
|
||||
{
|
||||
$path = $this->validatedTetrahedron('p1="2"');
|
||||
try {
|
||||
$this->expectException(RuntimeException::class);
|
||||
$this->expectExceptionMessageMatches('/transparen/i');
|
||||
(new ProductImageRenderer)->render($this->extractor->extract($path)['triangles']);
|
||||
} finally {
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
|
||||
public function test_resolves_object_level_color_from_a_colorgroup(): void
|
||||
{
|
||||
$resources = '<colorgroup id="5"><color color="#00CC33"/></colorgroup>'
|
||||
|
||||
Reference in New Issue
Block a user