mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-22 22:24:01 -06:00
ModelInstance's full 3D transform set as default
This commit is contained in:
parent
fb6c1a885c
commit
059ab4a05c
20 changed files with 2 additions and 630 deletions
|
@ -1253,13 +1253,7 @@ namespace Slic3r {
|
|||
// we extract from the given matrix only the values currently used
|
||||
|
||||
// translation
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
Vec3d offset = transform.matrix().block(0, 3, 3, 1);
|
||||
#else
|
||||
double offset_x = transform(0, 3);
|
||||
double offset_y = transform(1, 3);
|
||||
double offset_z = transform(2, 3);
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
|
||||
// scale
|
||||
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m3x3 = transform.matrix().block(0, 0, 3, 3);
|
||||
|
@ -1269,35 +1263,16 @@ namespace Slic3r {
|
|||
if ((scale(0) == 0.0) || (scale(1) == 0.0) || (scale(2) == 0.0))
|
||||
return;
|
||||
|
||||
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
// non-uniform scale value, return
|
||||
if ((std::abs(scale(0) - scale(1)) > 0.00001) || (std::abs(scale(0) - scale(2)) > 0.00001))
|
||||
return;
|
||||
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
|
||||
// remove scale
|
||||
m3x3.col(0).normalize();
|
||||
m3x3.col(1).normalize();
|
||||
m3x3.col(2).normalize();
|
||||
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3);
|
||||
|
||||
instance.set_offset(offset);
|
||||
instance.set_scaling_factor(scale);
|
||||
instance.set_rotation(rotation);
|
||||
#else
|
||||
Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3);
|
||||
|
||||
// invalid rotation, we currently handle only rotations around Z axis
|
||||
if ((rotation(0) != 0.0) || (rotation(1) != 0.0))
|
||||
return;
|
||||
|
||||
instance.offset(0) = offset_x;
|
||||
instance.offset(1) = offset_y;
|
||||
instance.scaling_factor = scale(0);
|
||||
instance.rotation = rotation(2);
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
}
|
||||
|
||||
bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes)
|
||||
|
|
|
@ -29,14 +29,10 @@
|
|||
// VERSION NUMBERS
|
||||
// 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_FULL_TRANSFORM
|
||||
// 2 : Added z component of offset
|
||||
// Added x and y components of rotation
|
||||
// Added x, y and z components of scale
|
||||
const unsigned int VERSION_AMF = 2;
|
||||
#else
|
||||
const unsigned int VERSION_AMF = 1;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
const char* SLIC3RPE_AMF_VERSION = "slic3rpe_amf_version";
|
||||
|
||||
const char* SLIC3R_CONFIG_TYPE = "slic3rpe_config";
|
||||
|
@ -125,34 +121,25 @@ struct AMFParserContext
|
|||
NODE_TYPE_INSTANCE, // amf/constellation/instance
|
||||
NODE_TYPE_DELTAX, // amf/constellation/instance/deltax
|
||||
NODE_TYPE_DELTAY, // amf/constellation/instance/deltay
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
NODE_TYPE_DELTAZ, // amf/constellation/instance/deltaz
|
||||
NODE_TYPE_RX, // amf/constellation/instance/rx
|
||||
NODE_TYPE_RY, // amf/constellation/instance/ry
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
NODE_TYPE_RZ, // amf/constellation/instance/rz
|
||||
NODE_TYPE_SCALE, // amf/constellation/instance/scale
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
NODE_TYPE_SCALEX, // amf/constellation/instance/scalex
|
||||
NODE_TYPE_SCALEY, // amf/constellation/instance/scaley
|
||||
NODE_TYPE_SCALEZ, // amf/constellation/instance/scalez
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
NODE_TYPE_METADATA, // anywhere under amf/*/metadata
|
||||
};
|
||||
|
||||
struct Instance {
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rx_set(false), ry_set(false), rz_set(false), scalex_set(false), scaley_set(false), scalez_set(false) {}
|
||||
#else
|
||||
Instance() : deltax_set(false), deltay_set(false), rz_set(false), scale_set(false) {}
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
// Shift in the X axis.
|
||||
float deltax;
|
||||
bool deltax_set;
|
||||
// Shift in the Y axis.
|
||||
float deltay;
|
||||
bool deltay_set;
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
// Shift in the Z axis.
|
||||
float deltaz;
|
||||
bool deltaz_set;
|
||||
|
@ -162,11 +149,9 @@ struct AMFParserContext
|
|||
// Rotation around the Y axis.
|
||||
float ry;
|
||||
bool ry_set;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
// Rotation around the Z axis.
|
||||
float rz;
|
||||
bool rz_set;
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
// Scaling factors
|
||||
float scalex;
|
||||
bool scalex_set;
|
||||
|
@ -174,11 +159,6 @@ struct AMFParserContext
|
|||
bool scaley_set;
|
||||
float scalez;
|
||||
bool scalez_set;
|
||||
#else
|
||||
// Scaling factor
|
||||
float scale;
|
||||
bool scale_set;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
};
|
||||
|
||||
struct Object {
|
||||
|
@ -293,24 +273,20 @@ void AMFParserContext::startElement(const char *name, const char **atts)
|
|||
node_type_new = NODE_TYPE_DELTAX;
|
||||
else if (strcmp(name, "deltay") == 0)
|
||||
node_type_new = NODE_TYPE_DELTAY;
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
else if (strcmp(name, "deltaz") == 0)
|
||||
node_type_new = NODE_TYPE_DELTAZ;
|
||||
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_FULL_TRANSFORM
|
||||
else if (strcmp(name, "rz") == 0)
|
||||
node_type_new = NODE_TYPE_RZ;
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
else if (strcmp(name, "scalex") == 0)
|
||||
node_type_new = NODE_TYPE_SCALEX;
|
||||
else if (strcmp(name, "scaley") == 0)
|
||||
node_type_new = NODE_TYPE_SCALEY;
|
||||
else if (strcmp(name, "scalez") == 0)
|
||||
node_type_new = NODE_TYPE_SCALEZ;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
else if (strcmp(name, "scale") == 0)
|
||||
node_type_new = NODE_TYPE_SCALE;
|
||||
}
|
||||
|
@ -369,7 +345,6 @@ void AMFParserContext::characters(const XML_Char *s, int len)
|
|||
{
|
||||
switch (m_path.size()) {
|
||||
case 4:
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
if (m_path.back() == NODE_TYPE_DELTAX ||
|
||||
m_path.back() == NODE_TYPE_DELTAY ||
|
||||
m_path.back() == NODE_TYPE_DELTAZ ||
|
||||
|
@ -380,9 +355,6 @@ void AMFParserContext::characters(const XML_Char *s, int len)
|
|||
m_path.back() == NODE_TYPE_SCALEY ||
|
||||
m_path.back() == NODE_TYPE_SCALEZ ||
|
||||
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)
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
m_value[0].append(s, len);
|
||||
break;
|
||||
case 6:
|
||||
|
@ -422,7 +394,6 @@ void AMFParserContext::endElement(const char * /* name */)
|
|||
m_instance->deltay_set = true;
|
||||
m_value[0].clear();
|
||||
break;
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
case NODE_TYPE_DELTAZ:
|
||||
assert(m_instance);
|
||||
m_instance->deltaz = float(atof(m_value[0].c_str()));
|
||||
|
@ -441,7 +412,6 @@ void AMFParserContext::endElement(const char * /* name */)
|
|||
m_instance->ry_set = true;
|
||||
m_value[0].clear();
|
||||
break;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
case NODE_TYPE_RZ:
|
||||
assert(m_instance);
|
||||
m_instance->rz = float(atof(m_value[0].c_str()));
|
||||
|
@ -450,20 +420,14 @@ void AMFParserContext::endElement(const char * /* name */)
|
|||
break;
|
||||
case NODE_TYPE_SCALE:
|
||||
assert(m_instance);
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
m_instance->scalex = float(atof(m_value[0].c_str()));
|
||||
m_instance->scalex_set = true;
|
||||
m_instance->scaley = float(atof(m_value[0].c_str()));
|
||||
m_instance->scaley_set = true;
|
||||
m_instance->scalez = float(atof(m_value[0].c_str()));
|
||||
m_instance->scalez_set = true;
|
||||
#else
|
||||
m_instance->scale = float(atof(m_value[0].c_str()));
|
||||
m_instance->scale_set = true;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
m_value[0].clear();
|
||||
break;
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
case NODE_TYPE_SCALEX:
|
||||
assert(m_instance);
|
||||
m_instance->scalex = float(atof(m_value[0].c_str()));
|
||||
|
@ -482,7 +446,6 @@ void AMFParserContext::endElement(const char * /* name */)
|
|||
m_instance->scalez_set = true;
|
||||
m_value[0].clear();
|
||||
break;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
|
||||
// Object vertices:
|
||||
case NODE_TYPE_VERTEX:
|
||||
|
@ -619,16 +582,9 @@ void AMFParserContext::endDocument()
|
|||
for (const Instance &instance : object.second.instances)
|
||||
if (instance.deltax_set && instance.deltay_set) {
|
||||
ModelInstance *mi = m_model.objects[object.second.idx]->add_instance();
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
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));
|
||||
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));
|
||||
mi->set_scaling_factor(Vec3d(instance.scalex_set ? (double)instance.scalex : 1.0, instance.scaley_set ? (double)instance.scaley : 1.0, instance.scalez_set ? (double)instance.scalez : 1.0));
|
||||
#else
|
||||
mi->offset(0) = instance.deltax;
|
||||
mi->offset(1) = instance.deltay;
|
||||
mi->rotation = instance.rz_set ? instance.rz : 0.f;
|
||||
mi->scaling_factor = instance.scale_set ? instance.scale : 1.f;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -928,22 +884,15 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
|
|||
" <instance objectid=\"" PRINTF_ZU "\">\n"
|
||||
" <deltax>%lf</deltax>\n"
|
||||
" <deltay>%lf</deltay>\n"
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
" <deltaz>%lf</deltaz>\n"
|
||||
" <rx>%lf</rx>\n"
|
||||
" <ry>%lf</ry>\n"
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
" <rz>%lf</rz>\n"
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
" <scalex>%lf</scalex>\n"
|
||||
" <scaley>%lf</scaley>\n"
|
||||
" <scalez>%lf</scalez>\n"
|
||||
#else
|
||||
" <scale>%lf</scale>\n"
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
" </instance>\n",
|
||||
object_id,
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
instance->get_offset(X),
|
||||
instance->get_offset(Y),
|
||||
instance->get_offset(Z),
|
||||
|
@ -953,12 +902,6 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
|
|||
instance->get_scaling_factor(X),
|
||||
instance->get_scaling_factor(Y),
|
||||
instance->get_scaling_factor(Z));
|
||||
#else
|
||||
instance->offset(0),
|
||||
instance->offset(1),
|
||||
instance->rotation,
|
||||
instance->scaling_factor);
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
|
||||
//FIXME missing instance->scaling_factor
|
||||
instances.append(buf);
|
||||
|
|
|
@ -97,15 +97,9 @@ static void extract_model_from_archive(
|
|||
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_FULL_TRANSFORM
|
||||
Vec3d instance_rotation = Vec3d::Zero();
|
||||
Vec3d instance_scaling_factor = Vec3d::Ones();
|
||||
Vec3d instance_offset = Vec3d::Zero();
|
||||
#else
|
||||
double instance_rotation = 0.;
|
||||
double instance_scaling_factor = 1.f;
|
||||
Vec2d instance_offset(0., 0.);
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
bool trafo_set = false;
|
||||
unsigned int group_id = (unsigned int)-1;
|
||||
unsigned int extruder_id = (unsigned int)-1;
|
||||
|
@ -128,19 +122,8 @@ static void extract_model_from_archive(
|
|||
"[%f, %f, %f]", scale, scale+1, scale+2) == 3 &&
|
||||
sscanf(zero_xml+strlen(zero_tag),
|
||||
"[%f, %f, %f]", zero, zero+1, zero+2) == 3) {
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
instance_scaling_factor = Vec3d((double)scale[0], (double)scale[1], (double)scale[2]);
|
||||
instance_rotation = Vec3d(-(double)rotation[0], -(double)rotation[1], -(double)rotation[2]);
|
||||
#else
|
||||
if (scale[0] == scale[1] && scale[1] == scale[2]) {
|
||||
instance_scaling_factor = scale[0];
|
||||
scale[0] = scale[1] = scale[2] = 1.;
|
||||
}
|
||||
if (rotation[0] == 0. && rotation[1] == 0.) {
|
||||
instance_rotation = -rotation[2];
|
||||
rotation[2] = 0.;
|
||||
}
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
Eigen::Matrix3f mat_rot, mat_scale, mat_trafo;
|
||||
mat_rot = Eigen::AngleAxisf(-rotation[2], Eigen::Vector3f::UnitZ()) *
|
||||
Eigen::AngleAxisf(-rotation[1], Eigen::Vector3f::UnitY()) *
|
||||
|
@ -151,15 +134,9 @@ static void extract_model_from_archive(
|
|||
for (size_t c = 0; c < 3; ++ c)
|
||||
trafo[r][c] += mat_trafo(r, c);
|
||||
}
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
instance_offset = Vec3d((double)(position[0] - zero[0]), (double)(position[1] - zero[1]), (double)(position[2] - zero[2]));
|
||||
// CHECK_ME -> Is the following correct ?
|
||||
trafo[2][3] = position[2] / (float)instance_scaling_factor(2);
|
||||
#else
|
||||
instance_offset(0) = position[0] - zero[0];
|
||||
instance_offset(1) = position[1] - zero[1];
|
||||
trafo[2][3] = position[2] / instance_scaling_factor;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
trafo_set = true;
|
||||
}
|
||||
const char *group_tag = "<group>";
|
||||
|
@ -315,15 +292,9 @@ static void extract_model_from_archive(
|
|||
model_object = model->add_object(name, path, std::move(mesh));
|
||||
volume = model_object->volumes.front();
|
||||
ModelInstance *instance = model_object->add_instance();
|
||||
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
instance->set_rotation(instance_rotation);
|
||||
instance->set_scaling_factor(instance_scaling_factor);
|
||||
instance->set_offset(instance_offset);
|
||||
#else
|
||||
instance->rotation = instance_rotation;
|
||||
instance->scaling_factor = instance_scaling_factor;
|
||||
instance->offset = instance_offset;
|
||||
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
|
||||
if (group_id != (size_t)-1)
|
||||
group_to_model_object[group_id] = model_object;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue