Merge remote-tracking branch 'origin/dev2' into dev_native

This commit is contained in:
bubnikv 2018-09-20 16:48:40 +02:00
commit 20d0f046d2
34 changed files with 1300 additions and 694 deletions

View file

@ -1284,6 +1284,9 @@ namespace Slic3r {
transform(1, 0) * inv_sx, transform(1, 1) * inv_sy, transform(1, 2) * inv_sz,
transform(2, 0) * inv_sx, transform(2, 1) * inv_sy, transform(2, 2) * inv_sz;
#if ENABLE_MODELINSTANCE_3D_ROTATION
Vec3d rotation = m3x3.eulerAngles(0, 1, 2);
#else
Eigen::AngleAxisd rotation;
rotation.fromRotationMatrix(m3x3);
@ -1292,6 +1295,7 @@ namespace Slic3r {
return;
double angle_z = (rotation.axis() == Vec3d::UnitZ()) ? rotation.angle() : -rotation.angle();
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
#if ENABLE_MODELINSTANCE_3D_OFFSET
instance.set_offset(offset);
@ -1300,7 +1304,11 @@ namespace Slic3r {
instance.offset(1) = offset_y;
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
instance.scaling_factor = sx;
#if ENABLE_MODELINSTANCE_3D_ROTATION
instance.set_rotation(rotation);
#else
instance.rotation = angle_z;
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
}
bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes)

View file

@ -30,7 +30,12 @@
// 0 : .amf, .amf.xml and .zip.amf files saved by older slic3r. No version definition in them.
// 1 : Introduction of amf versioning. No other change in data saved into amf files.
#if ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
// 2 : Added z component of offset
// Added x and y components of rotation
#else
// 2 : Added z component of offset.
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
const unsigned int VERSION_AMF = 2;
#else
const unsigned int VERSION_AMF = 1;
@ -127,6 +132,10 @@ struct AMFParserContext
#if ENABLE_MODELINSTANCE_3D_OFFSET
NODE_TYPE_DELTAZ, // amf/constellation/instance/deltaz
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
NODE_TYPE_RX, // amf/constellation/instance/rx
NODE_TYPE_RY, // amf/constellation/instance/ry
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
NODE_TYPE_RZ, // amf/constellation/instance/rz
NODE_TYPE_SCALE, // amf/constellation/instance/scale
NODE_TYPE_METADATA, // anywhere under amf/*/metadata
@ -134,7 +143,11 @@ struct AMFParserContext
struct Instance {
#if ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rx_set(false), ry_set(false), rz_set(false), scale_set(false) {}
#else
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rz_set(false), scale_set(false) {}
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
#else
Instance() : deltax_set(false), deltay_set(false), rz_set(false), scale_set(false) {}
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
@ -149,6 +162,14 @@ struct AMFParserContext
float deltaz;
bool deltaz_set;
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
// Rotation around the X axis.
float rx;
bool rx_set;
// Rotation around the Y axis.
float ry;
bool ry_set;
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
// Rotation around the Z axis.
float rz;
bool rz_set;
@ -275,6 +296,12 @@ void AMFParserContext::startElement(const char *name, const char **atts)
else if (strcmp(name, "deltaz") == 0)
node_type_new = NODE_TYPE_DELTAZ;
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
else if (strcmp(name, "rx") == 0)
node_type_new = NODE_TYPE_RX;
else if (strcmp(name, "ry") == 0)
node_type_new = NODE_TYPE_RY;
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
else if (strcmp(name, "rz") == 0)
node_type_new = NODE_TYPE_RZ;
else if (strcmp(name, "scale") == 0)
@ -339,7 +366,11 @@ void AMFParserContext::characters(const XML_Char *s, int len)
if (m_path.back() == NODE_TYPE_DELTAX ||
m_path.back() == NODE_TYPE_DELTAY ||
m_path.back() == NODE_TYPE_DELTAZ ||
m_path.back() == NODE_TYPE_RZ ||
#if ENABLE_MODELINSTANCE_3D_ROTATION
m_path.back() == NODE_TYPE_RX ||
m_path.back() == NODE_TYPE_RY ||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
m_path.back() == NODE_TYPE_RZ ||
m_path.back() == NODE_TYPE_SCALE)
#else
if (m_path.back() == NODE_TYPE_DELTAX || m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_RZ || m_path.back() == NODE_TYPE_SCALE)
@ -391,6 +422,20 @@ void AMFParserContext::endElement(const char * /* name */)
m_value[0].clear();
break;
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
case NODE_TYPE_RX:
assert(m_instance);
m_instance->rx = float(atof(m_value[0].c_str()));
m_instance->rx_set = true;
m_value[0].clear();
break;
case NODE_TYPE_RY:
assert(m_instance);
m_instance->ry = float(atof(m_value[0].c_str()));
m_instance->ry_set = true;
m_value[0].clear();
break;
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
case NODE_TYPE_RZ:
assert(m_instance);
m_instance->rz = float(atof(m_value[0].c_str()));
@ -542,12 +587,16 @@ void AMFParserContext::endDocument()
if (instance.deltax_set && instance.deltay_set) {
ModelInstance *mi = m_model.objects[object.second.idx]->add_instance();
#if ENABLE_MODELINSTANCE_3D_OFFSET
mi->set_offset(Vec3d((double)instance.deltax, (double)instance.deltay, (double)instance.deltaz));
mi->set_offset(Vec3d(instance.deltax_set ? (double)instance.deltax : 0.0, instance.deltay_set ? (double)instance.deltay : 0.0, instance.deltaz_set ? (double)instance.deltaz : 0.0));
#else
mi->offset(0) = instance.deltax;
mi->offset(1) = instance.deltay;
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
mi->set_rotation(Vec3d(instance.rx_set ? (double)instance.rx : 0.0, instance.ry_set ? (double)instance.ry : 0.0, instance.rz_set ? (double)instance.rz : 0.0));
#else
mi->rotation = instance.rz_set ? instance.rz : 0.f;
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
mi->scaling_factor = instance.scale_set ? instance.scale : 1.f;
}
}
@ -851,6 +900,10 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
#if ENABLE_MODELINSTANCE_3D_OFFSET
" <deltaz>%lf</deltaz>\n"
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
" <rx>%lf</rx>\n"
" <ry>%lf</ry>\n"
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
" <rz>%lf</rz>\n"
" <scale>%lf</scale>\n"
" </instance>\n",
@ -863,8 +916,15 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
instance->offset(0),
instance->offset(1),
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
#if ENABLE_MODELINSTANCE_3D_ROTATION
instance->get_rotation(X),
instance->get_rotation(Y),
instance->get_rotation(Z),
#else
instance->rotation,
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
instance->scaling_factor);
//FIXME missing instance->scaling_factor
instances.append(buf);
}

View file

@ -164,7 +164,11 @@ bool load_prus(const char *path, Model *model)
const char *zero_tag = "<zero>";
const char *zero_xml = strstr(scene_xml_data.data(), zero_tag);
float trafo[3][4] = { 0 };
#if ENABLE_MODELINSTANCE_3D_ROTATION
Vec3d instance_rotation = Vec3d::Zero();
#else
double instance_rotation = 0.;
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
double instance_scaling_factor = 1.f;
#if ENABLE_MODELINSTANCE_3D_OFFSET
Vec3d instance_offset = Vec3d::Zero();
@ -197,10 +201,14 @@ bool load_prus(const char *path, Model *model)
instance_scaling_factor = scale[0];
scale[0] = scale[1] = scale[2] = 1.;
}
#if ENABLE_MODELINSTANCE_3D_ROTATION
instance_rotation = Vec3d(-(double)rotation[0], -(double)rotation[1], -(double)rotation[2]);
#else
if (rotation[0] == 0. && rotation[1] == 0.) {
instance_rotation = - rotation[2];
rotation[2] = 0.;
}
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
Eigen::Matrix3f mat_rot, mat_scale, mat_trafo;
mat_rot = Eigen::AngleAxisf(-rotation[2], Eigen::Vector3f::UnitZ()) *
Eigen::AngleAxisf(-rotation[1], Eigen::Vector3f::UnitY()) *
@ -366,8 +374,12 @@ bool load_prus(const char *path, Model *model)
model_object = model->add_object(name_utf8.data(), path, std::move(mesh));
volume = model_object->volumes.front();
ModelInstance *instance = model_object->add_instance();
instance->rotation = instance_rotation;
instance->scaling_factor = instance_scaling_factor;
#if ENABLE_MODELINSTANCE_3D_ROTATION
instance->set_rotation(instance_rotation);
#else
instance->rotation = instance_rotation;
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
instance->scaling_factor = instance_scaling_factor;
#if ENABLE_MODELINSTANCE_3D_OFFSET
instance->set_offset(instance_offset);
#else