Prevent writing empty materials to AMF files. Also add a note about material-id = 0 being reserved by AMF spec. #2871
This commit is contained in:
parent
e26022a2f2
commit
fbea32a81c
2 changed files with 4 additions and 1 deletions
|
@ -36,7 +36,9 @@ sub write_file {
|
||||||
printf $fh qq{<amf unit="millimeter">\n};
|
printf $fh qq{<amf unit="millimeter">\n};
|
||||||
printf $fh qq{ <metadata type="cad">Slic3r %s</metadata>\n}, $Slic3r::VERSION;
|
printf $fh qq{ <metadata type="cad">Slic3r %s</metadata>\n}, $Slic3r::VERSION;
|
||||||
for my $material_id (sort @{ $model->material_names }) {
|
for my $material_id (sort @{ $model->material_names }) {
|
||||||
|
next if $material_id eq '';
|
||||||
my $material = $model->get_material($material_id);
|
my $material = $model->get_material($material_id);
|
||||||
|
# note that material-id must never be 0 since it's reserved by the AMF spec
|
||||||
printf $fh qq{ <material id="%s">\n}, $material_id;
|
printf $fh qq{ <material id="%s">\n}, $material_id;
|
||||||
for (keys %{$material->attributes}) {
|
for (keys %{$material->attributes}) {
|
||||||
printf $fh qq{ <metadata type=\"%s\">%s</metadata>\n}, $_, $material->attributes->{$_};
|
printf $fh qq{ <metadata type=\"%s\">%s</metadata>\n}, $_, $material->attributes->{$_};
|
||||||
|
|
|
@ -690,7 +690,8 @@ ModelVolume::assign_unique_material()
|
||||||
{
|
{
|
||||||
Model* model = this->get_object()->get_model();
|
Model* model = this->get_object()->get_model();
|
||||||
|
|
||||||
this->_material_id = 1 + model->materials.size();
|
// as material-id "0" is reserved by the AMF spec we start from 1
|
||||||
|
this->_material_id = 1 + model->materials.size(); // watchout for implicit cast
|
||||||
return model->add_material(this->_material_id);
|
return model->add_material(this->_material_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue