mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-09-24 06:53:16 +08:00
Compensate for origin_translation when exporting AMF files in order to preserve alignment of further added parts. #3348
This commit is contained in:
parent
a5b10287d6
commit
4c78e54a46
@ -528,18 +528,23 @@ AMF::write(Model& model, std::string output_file)
|
|||||||
std::vector<int> vertices_offsets;
|
std::vector<int> vertices_offsets;
|
||||||
int num_vertices = 0;
|
int num_vertices = 0;
|
||||||
for (ModelVolume *volume : object->volumes) {
|
for (ModelVolume *volume : object->volumes) {
|
||||||
|
volume->mesh.check_topology();
|
||||||
vertices_offsets.push_back(num_vertices);
|
vertices_offsets.push_back(num_vertices);
|
||||||
if (! volume->mesh.repaired)
|
|
||||||
CONFESS("store_amf() requires repair()");
|
|
||||||
auto &stl = volume->mesh.stl;
|
auto &stl = volume->mesh.stl;
|
||||||
if (stl.v_shared == NULL)
|
if (stl.v_shared == NULL)
|
||||||
stl_generate_shared_vertices(&stl);
|
stl_generate_shared_vertices(&stl);
|
||||||
for (size_t i = 0; i < stl.stats.shared_vertices; ++ i) {
|
for (size_t i = 0; i < stl.stats.shared_vertices; ++ i) {
|
||||||
|
// Subtract origin_translation in order to restore the coordinates of the parts
|
||||||
|
// before they were imported. Otherwise, when this AMF file is reimported parts
|
||||||
|
// will be placed in the plater correctly, but we will have lost origin_translation
|
||||||
|
// thus any additional part added will not align with the others.
|
||||||
|
// In order to do this we compensate for this translation in the instance placement
|
||||||
|
// below.
|
||||||
fprintf(file, " <vertex>\n");
|
fprintf(file, " <vertex>\n");
|
||||||
fprintf(file, " <coordinates>\n");
|
fprintf(file, " <coordinates>\n");
|
||||||
fprintf(file, " <x>%f</x>\n", stl.v_shared[i].x);
|
fprintf(file, " <x>%f</x>\n", stl.v_shared[i].x - object->origin_translation.x);
|
||||||
fprintf(file, " <y>%f</y>\n", stl.v_shared[i].y);
|
fprintf(file, " <y>%f</y>\n", stl.v_shared[i].y - object->origin_translation.y);
|
||||||
fprintf(file, " <z>%f</z>\n", stl.v_shared[i].z);
|
fprintf(file, " <z>%f</z>\n", stl.v_shared[i].z - object->origin_translation.z);
|
||||||
fprintf(file, " </coordinates>\n");
|
fprintf(file, " </coordinates>\n");
|
||||||
fprintf(file, " </vertex>\n");
|
fprintf(file, " </vertex>\n");
|
||||||
}
|
}
|
||||||
@ -569,24 +574,21 @@ AMF::write(Model& model, std::string output_file)
|
|||||||
}
|
}
|
||||||
fprintf(file, " </mesh>\n");
|
fprintf(file, " </mesh>\n");
|
||||||
fprintf(file, " </object>\n");
|
fprintf(file, " </object>\n");
|
||||||
if (! object->instances.empty()) {
|
for (const ModelInstance* instance : object->instances) {
|
||||||
for (ModelInstance *instance : object->instances) {
|
char buf[512];
|
||||||
char buf[512];
|
sprintf(buf,
|
||||||
sprintf(buf,
|
" <instance objectid=\"%zu\">\n"
|
||||||
" <instance objectid=\"%zu\">\n"
|
" <deltax>%lf</deltax>\n"
|
||||||
" <deltax>%lf</deltax>\n"
|
" <deltay>%lf</deltay>\n"
|
||||||
" <deltay>%lf</deltay>\n"
|
" <rz>%lf</rz>\n"
|
||||||
" <rz>%lf</rz>\n"
|
" <scale>%lf</scale>\n"
|
||||||
" <scale>%lf</scale>\n"
|
" </instance>\n",
|
||||||
" </instance>\n",
|
object_id,
|
||||||
object_id,
|
instance->offset.x + object->origin_translation.x,
|
||||||
instance->offset.x,
|
instance->offset.y + object->origin_translation.y,
|
||||||
instance->offset.y,
|
instance->rotation,
|
||||||
instance->rotation,
|
instance->scaling_factor);
|
||||||
instance->scaling_factor);
|
instances.append(buf);
|
||||||
//FIXME missing instance->scaling_factor
|
|
||||||
instances.append(buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (! instances.empty()) {
|
if (! instances.empty()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user