ModelInstance's full 3D transform set as default

This commit is contained in:
Enrico Turri 2018-10-16 09:51:30 +02:00
parent fb6c1a885c
commit 059ab4a05c
20 changed files with 2 additions and 630 deletions

View File

@ -1253,13 +1253,7 @@ namespace Slic3r {
// we extract from the given matrix only the values currently used // we extract from the given matrix only the values currently used
// translation // translation
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d offset = transform.matrix().block(0, 3, 3, 1); 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 // scale
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m3x3 = transform.matrix().block(0, 0, 3, 3); 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)) if ((scale(0) == 0.0) || (scale(1) == 0.0) || (scale(2) == 0.0))
return; 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 // remove scale
m3x3.col(0).normalize(); m3x3.col(0).normalize();
m3x3.col(1).normalize(); m3x3.col(1).normalize();
m3x3.col(2).normalize(); m3x3.col(2).normalize();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3); Vec3d rotation = Slic3r::Geometry::extract_euler_angles(m3x3);
instance.set_offset(offset); instance.set_offset(offset);
instance.set_scaling_factor(scale); instance.set_scaling_factor(scale);
instance.set_rotation(rotation); 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) bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes)

View File

@ -29,14 +29,10 @@
// VERSION NUMBERS // VERSION NUMBERS
// 0 : .amf, .amf.xml and .zip.amf files saved by older slic3r. No version definition in them. // 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. // 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 // 2 : Added z component of offset
// Added x and y components of rotation // Added x and y components of rotation
// Added x, y and z components of scale // Added x, y and z components of scale
const unsigned int VERSION_AMF = 2; 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* SLIC3RPE_AMF_VERSION = "slic3rpe_amf_version";
const char* SLIC3R_CONFIG_TYPE = "slic3rpe_config"; const char* SLIC3R_CONFIG_TYPE = "slic3rpe_config";
@ -125,34 +121,25 @@ struct AMFParserContext
NODE_TYPE_INSTANCE, // amf/constellation/instance NODE_TYPE_INSTANCE, // amf/constellation/instance
NODE_TYPE_DELTAX, // amf/constellation/instance/deltax NODE_TYPE_DELTAX, // amf/constellation/instance/deltax
NODE_TYPE_DELTAY, // amf/constellation/instance/deltay NODE_TYPE_DELTAY, // amf/constellation/instance/deltay
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
NODE_TYPE_DELTAZ, // amf/constellation/instance/deltaz NODE_TYPE_DELTAZ, // amf/constellation/instance/deltaz
NODE_TYPE_RX, // amf/constellation/instance/rx NODE_TYPE_RX, // amf/constellation/instance/rx
NODE_TYPE_RY, // amf/constellation/instance/ry NODE_TYPE_RY, // amf/constellation/instance/ry
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
NODE_TYPE_RZ, // amf/constellation/instance/rz NODE_TYPE_RZ, // amf/constellation/instance/rz
NODE_TYPE_SCALE, // amf/constellation/instance/scale NODE_TYPE_SCALE, // amf/constellation/instance/scale
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
NODE_TYPE_SCALEX, // amf/constellation/instance/scalex NODE_TYPE_SCALEX, // amf/constellation/instance/scalex
NODE_TYPE_SCALEY, // amf/constellation/instance/scaley NODE_TYPE_SCALEY, // amf/constellation/instance/scaley
NODE_TYPE_SCALEZ, // amf/constellation/instance/scalez NODE_TYPE_SCALEZ, // amf/constellation/instance/scalez
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
NODE_TYPE_METADATA, // anywhere under amf/*/metadata NODE_TYPE_METADATA, // anywhere under amf/*/metadata
}; };
struct Instance { 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) {} 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. // Shift in the X axis.
float deltax; float deltax;
bool deltax_set; bool deltax_set;
// Shift in the Y axis. // Shift in the Y axis.
float deltay; float deltay;
bool deltay_set; bool deltay_set;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Shift in the Z axis. // Shift in the Z axis.
float deltaz; float deltaz;
bool deltaz_set; bool deltaz_set;
@ -162,11 +149,9 @@ struct AMFParserContext
// Rotation around the Y axis. // Rotation around the Y axis.
float ry; float ry;
bool ry_set; bool ry_set;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Rotation around the Z axis. // Rotation around the Z axis.
float rz; float rz;
bool rz_set; bool rz_set;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Scaling factors // Scaling factors
float scalex; float scalex;
bool scalex_set; bool scalex_set;
@ -174,11 +159,6 @@ struct AMFParserContext
bool scaley_set; bool scaley_set;
float scalez; float scalez;
bool scalez_set; bool scalez_set;
#else
// Scaling factor
float scale;
bool scale_set;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
}; };
struct Object { struct Object {
@ -293,24 +273,20 @@ void AMFParserContext::startElement(const char *name, const char **atts)
node_type_new = NODE_TYPE_DELTAX; node_type_new = NODE_TYPE_DELTAX;
else if (strcmp(name, "deltay") == 0) else if (strcmp(name, "deltay") == 0)
node_type_new = NODE_TYPE_DELTAY; node_type_new = NODE_TYPE_DELTAY;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
else if (strcmp(name, "deltaz") == 0) else if (strcmp(name, "deltaz") == 0)
node_type_new = NODE_TYPE_DELTAZ; node_type_new = NODE_TYPE_DELTAZ;
else if (strcmp(name, "rx") == 0) else if (strcmp(name, "rx") == 0)
node_type_new = NODE_TYPE_RX; node_type_new = NODE_TYPE_RX;
else if (strcmp(name, "ry") == 0) else if (strcmp(name, "ry") == 0)
node_type_new = NODE_TYPE_RY; node_type_new = NODE_TYPE_RY;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
else if (strcmp(name, "rz") == 0) else if (strcmp(name, "rz") == 0)
node_type_new = NODE_TYPE_RZ; node_type_new = NODE_TYPE_RZ;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
else if (strcmp(name, "scalex") == 0) else if (strcmp(name, "scalex") == 0)
node_type_new = NODE_TYPE_SCALEX; node_type_new = NODE_TYPE_SCALEX;
else if (strcmp(name, "scaley") == 0) else if (strcmp(name, "scaley") == 0)
node_type_new = NODE_TYPE_SCALEY; node_type_new = NODE_TYPE_SCALEY;
else if (strcmp(name, "scalez") == 0) else if (strcmp(name, "scalez") == 0)
node_type_new = NODE_TYPE_SCALEZ; node_type_new = NODE_TYPE_SCALEZ;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
else if (strcmp(name, "scale") == 0) else if (strcmp(name, "scale") == 0)
node_type_new = NODE_TYPE_SCALE; node_type_new = NODE_TYPE_SCALE;
} }
@ -369,7 +345,6 @@ void AMFParserContext::characters(const XML_Char *s, int len)
{ {
switch (m_path.size()) { switch (m_path.size()) {
case 4: case 4:
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (m_path.back() == NODE_TYPE_DELTAX || if (m_path.back() == NODE_TYPE_DELTAX ||
m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_DELTAY ||
m_path.back() == NODE_TYPE_DELTAZ || 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_SCALEY ||
m_path.back() == NODE_TYPE_SCALEZ || m_path.back() == NODE_TYPE_SCALEZ ||
m_path.back() == NODE_TYPE_SCALE) 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); m_value[0].append(s, len);
break; break;
case 6: case 6:
@ -422,7 +394,6 @@ void AMFParserContext::endElement(const char * /* name */)
m_instance->deltay_set = true; m_instance->deltay_set = true;
m_value[0].clear(); m_value[0].clear();
break; break;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
case NODE_TYPE_DELTAZ: case NODE_TYPE_DELTAZ:
assert(m_instance); assert(m_instance);
m_instance->deltaz = float(atof(m_value[0].c_str())); 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_instance->ry_set = true;
m_value[0].clear(); m_value[0].clear();
break; break;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
case NODE_TYPE_RZ: case NODE_TYPE_RZ:
assert(m_instance); assert(m_instance);
m_instance->rz = float(atof(m_value[0].c_str())); m_instance->rz = float(atof(m_value[0].c_str()));
@ -450,20 +420,14 @@ void AMFParserContext::endElement(const char * /* name */)
break; break;
case NODE_TYPE_SCALE: case NODE_TYPE_SCALE:
assert(m_instance); assert(m_instance);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_instance->scalex = float(atof(m_value[0].c_str())); m_instance->scalex = float(atof(m_value[0].c_str()));
m_instance->scalex_set = true; m_instance->scalex_set = true;
m_instance->scaley = float(atof(m_value[0].c_str())); m_instance->scaley = float(atof(m_value[0].c_str()));
m_instance->scaley_set = true; m_instance->scaley_set = true;
m_instance->scalez = float(atof(m_value[0].c_str())); m_instance->scalez = float(atof(m_value[0].c_str()));
m_instance->scalez_set = true; 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(); m_value[0].clear();
break; break;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
case NODE_TYPE_SCALEX: case NODE_TYPE_SCALEX:
assert(m_instance); assert(m_instance);
m_instance->scalex = float(atof(m_value[0].c_str())); 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_instance->scalez_set = true;
m_value[0].clear(); m_value[0].clear();
break; break;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Object vertices: // Object vertices:
case NODE_TYPE_VERTEX: case NODE_TYPE_VERTEX:
@ -619,16 +582,9 @@ void AMFParserContext::endDocument()
for (const Instance &instance : object.second.instances) for (const Instance &instance : object.second.instances)
if (instance.deltax_set && instance.deltay_set) { if (instance.deltax_set && instance.deltay_set) {
ModelInstance *mi = m_model.objects[object.second.idx]->add_instance(); 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_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_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)); 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" " <instance objectid=\"" PRINTF_ZU "\">\n"
" <deltax>%lf</deltax>\n" " <deltax>%lf</deltax>\n"
" <deltay>%lf</deltay>\n" " <deltay>%lf</deltay>\n"
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
" <deltaz>%lf</deltaz>\n" " <deltaz>%lf</deltaz>\n"
" <rx>%lf</rx>\n" " <rx>%lf</rx>\n"
" <ry>%lf</ry>\n" " <ry>%lf</ry>\n"
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
" <rz>%lf</rz>\n" " <rz>%lf</rz>\n"
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
" <scalex>%lf</scalex>\n" " <scalex>%lf</scalex>\n"
" <scaley>%lf</scaley>\n" " <scaley>%lf</scaley>\n"
" <scalez>%lf</scalez>\n" " <scalez>%lf</scalez>\n"
#else
" <scale>%lf</scale>\n"
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
" </instance>\n", " </instance>\n",
object_id, object_id,
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
instance->get_offset(X), instance->get_offset(X),
instance->get_offset(Y), instance->get_offset(Y),
instance->get_offset(Z), 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(X),
instance->get_scaling_factor(Y), instance->get_scaling_factor(Y),
instance->get_scaling_factor(Z)); 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 //FIXME missing instance->scaling_factor
instances.append(buf); instances.append(buf);

View File

@ -97,15 +97,9 @@ static void extract_model_from_archive(
const char *zero_tag = "<zero>"; const char *zero_tag = "<zero>";
const char *zero_xml = strstr(scene_xml_data.data(), zero_tag); const char *zero_xml = strstr(scene_xml_data.data(), zero_tag);
float trafo[3][4] = { 0 }; float trafo[3][4] = { 0 };
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d instance_rotation = Vec3d::Zero(); Vec3d instance_rotation = Vec3d::Zero();
Vec3d instance_scaling_factor = Vec3d::Ones(); Vec3d instance_scaling_factor = Vec3d::Ones();
Vec3d instance_offset = Vec3d::Zero(); 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; bool trafo_set = false;
unsigned int group_id = (unsigned int)-1; unsigned int group_id = (unsigned int)-1;
unsigned int extruder_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 && "[%f, %f, %f]", scale, scale+1, scale+2) == 3 &&
sscanf(zero_xml+strlen(zero_tag), sscanf(zero_xml+strlen(zero_tag),
"[%f, %f, %f]", zero, zero+1, zero+2) == 3) { "[%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_scaling_factor = Vec3d((double)scale[0], (double)scale[1], (double)scale[2]);
instance_rotation = Vec3d(-(double)rotation[0], -(double)rotation[1], -(double)rotation[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; Eigen::Matrix3f mat_rot, mat_scale, mat_trafo;
mat_rot = Eigen::AngleAxisf(-rotation[2], Eigen::Vector3f::UnitZ()) * mat_rot = Eigen::AngleAxisf(-rotation[2], Eigen::Vector3f::UnitZ()) *
Eigen::AngleAxisf(-rotation[1], Eigen::Vector3f::UnitY()) * 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) for (size_t c = 0; c < 3; ++ c)
trafo[r][c] += mat_trafo(r, 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])); instance_offset = Vec3d((double)(position[0] - zero[0]), (double)(position[1] - zero[1]), (double)(position[2] - zero[2]));
// CHECK_ME -> Is the following correct ? // CHECK_ME -> Is the following correct ?
trafo[2][3] = position[2] / (float)instance_scaling_factor(2); 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; trafo_set = true;
} }
const char *group_tag = "<group>"; 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)); model_object = model->add_object(name, path, std::move(mesh));
volume = model_object->volumes.front(); volume = model_object->volumes.front();
ModelInstance *instance = model_object->add_instance(); ModelInstance *instance = model_object->add_instance();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
instance->set_rotation(instance_rotation); instance->set_rotation(instance_rotation);
instance->set_scaling_factor(instance_scaling_factor); instance->set_scaling_factor(instance_scaling_factor);
instance->set_offset(instance_offset); 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) if (group_id != (size_t)-1)
group_to_model_object[group_id] = model_object; group_to_model_object[group_id] = model_object;
} else { } else {

View File

@ -252,19 +252,11 @@ void Model::center_instances_around_point(const Vec2d &point)
for (size_t i = 0; i < o->instances.size(); ++ i) for (size_t i = 0; i < o->instances.size(); ++ i)
bb.merge(o->instance_bounding_box(i, false)); bb.merge(o->instance_bounding_box(i, false));
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec2d shift2 = point - to_2d(bb.center()); Vec2d shift2 = point - to_2d(bb.center());
Vec3d shift3 = Vec3d(shift2(0), shift2(1), 0.0); Vec3d shift3 = Vec3d(shift2(0), shift2(1), 0.0);
#else
Vec2d shift = point - 0.5 * to_2d(bb.size()) - to_2d(bb.min);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
for (ModelObject *o : this->objects) { for (ModelObject *o : this->objects) {
for (ModelInstance *i : o->instances) for (ModelInstance *i : o->instances)
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
i->set_offset(i->get_offset() + shift3); i->set_offset(i->get_offset() + shift3);
#else
i->offset += shift;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
o->invalidate_bounding_box(); o->invalidate_bounding_box();
} }
} }
@ -330,12 +322,8 @@ bool Model::arrange_objects(coordf_t dist, const BoundingBoxf* bb)
size_t idx = 0; size_t idx = 0;
for (ModelObject *o : this->objects) { for (ModelObject *o : this->objects) {
for (ModelInstance *i : o->instances) { for (ModelInstance *i : o->instances) {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec2d offset_xy = positions[idx] - instance_centers[idx]; Vec2d offset_xy = positions[idx] - instance_centers[idx];
i->set_offset(Vec3d(offset_xy(0), offset_xy(1), i->get_offset(Z))); i->set_offset(Vec3d(offset_xy(0), offset_xy(1), i->get_offset(Z)));
#else
i->offset = positions[idx] - instance_centers[idx];
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
++idx; ++idx;
} }
o->invalidate_bounding_box(); o->invalidate_bounding_box();
@ -360,11 +348,7 @@ void Model::duplicate(size_t copies_num, coordf_t dist, const BoundingBoxf* bb)
for (const ModelInstance *i : instances) { for (const ModelInstance *i : instances) {
for (const Vec2d &pos : positions) { for (const Vec2d &pos : positions) {
ModelInstance *instance = o->add_instance(*i); ModelInstance *instance = o->add_instance(*i);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
instance->set_offset(instance->get_offset() + Vec3d(pos(0), pos(1), 0.0)); instance->set_offset(instance->get_offset() + Vec3d(pos(0), pos(1), 0.0));
#else
instance->offset += pos;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
} }
o->invalidate_bounding_box(); o->invalidate_bounding_box();
@ -394,21 +378,12 @@ void Model::duplicate_objects_grid(size_t x, size_t y, coordf_t dist)
ModelObject* object = this->objects.front(); ModelObject* object = this->objects.front();
object->clear_instances(); object->clear_instances();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d ext_size = object->bounding_box().size() + dist * Vec3d::Ones(); Vec3d ext_size = object->bounding_box().size() + dist * Vec3d::Ones();
#else
Vec3d size = object->bounding_box().size();
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
for (size_t x_copy = 1; x_copy <= x; ++x_copy) { for (size_t x_copy = 1; x_copy <= x; ++x_copy) {
for (size_t y_copy = 1; y_copy <= y; ++y_copy) { for (size_t y_copy = 1; y_copy <= y; ++y_copy) {
ModelInstance* instance = object->add_instance(); ModelInstance* instance = object->add_instance();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
instance->set_offset(Vec3d(ext_size(0) * (double)(x_copy - 1), ext_size(1) * (double)(y_copy - 1), 0.0)); instance->set_offset(Vec3d(ext_size(0) * (double)(x_copy - 1), ext_size(1) * (double)(y_copy - 1), 0.0));
#else
instance->offset(0) = (size(0) + dist) * (x_copy - 1);
instance->offset(1) = (size(1) + dist) * (y_copy - 1);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
} }
} }
@ -728,23 +703,16 @@ void ModelObject::center_around_origin()
this->translate(shift); this->translate(shift);
this->origin_translation += shift; this->origin_translation += shift;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if !ENABLE_EXTENDED_SELECTION #if !ENABLE_EXTENDED_SELECTION
// set z to zero, translation in z has already been done within the mesh // set z to zero, translation in z has already been done within the mesh
shift(2) = 0.0; shift(2) = 0.0;
#endif // !ENABLE_EXTENDED_SELECTION #endif // !ENABLE_EXTENDED_SELECTION
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (!this->instances.empty()) { if (!this->instances.empty()) {
for (ModelInstance *i : this->instances) { for (ModelInstance *i : this->instances) {
// apply rotation and scaling to vector as well before translating instance, // apply rotation and scaling to vector as well before translating instance,
// in order to leave final position unaltered // in order to leave final position unaltered
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
i->set_offset(i->get_offset() + i->transform_vector(-shift, true)); i->set_offset(i->get_offset() + i->transform_vector(-shift, true));
#else
Vec3d i_shift = i->world_matrix(true) * shift;
i->offset -= to_2d(i_shift);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
this->invalidate_bounding_box(); this->invalidate_bounding_box();
} }
@ -1091,7 +1059,6 @@ size_t ModelVolume::split(unsigned int max_extruders)
return idx; return idx;
} }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void ModelInstance::set_rotation(const Vec3d& rotation) void ModelInstance::set_rotation(const Vec3d& rotation)
{ {
set_rotation(X, rotation(0)); set_rotation(X, rotation(0));
@ -1112,7 +1079,6 @@ void ModelInstance::set_rotation(Axis axis, double rotation)
} }
m_rotation(axis) = rotation; m_rotation(axis) = rotation;
} }
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
{ {
@ -1127,7 +1093,6 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes
BoundingBoxf3 bbox = copy.bounding_box(); BoundingBoxf3 bbox = copy.bounding_box();
if (!empty(bbox)) { if (!empty(bbox)) {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Scale the bounding box along the three axes. // Scale the bounding box along the three axes.
for (unsigned int i = 0; i < 3; ++i) for (unsigned int i = 0; i < 3; ++i)
{ {
@ -1143,19 +1108,6 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes
bbox.min += this->m_offset; bbox.min += this->m_offset;
bbox.max += this->m_offset; bbox.max += this->m_offset;
} }
#else
// Scale the bounding box uniformly.
if (std::abs(this->scaling_factor - 1.) > EPSILON) {
bbox.min *= this->scaling_factor;
bbox.max *= this->scaling_factor;
}
// Translate the bounding box.
if (!dont_translate) {
Eigen::Map<Vec2d>(bbox.min.data()) += this->offset;
Eigen::Map<Vec2d>(bbox.max.data()) += this->offset;
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
return bbox; return bbox;
} }
@ -1172,38 +1124,18 @@ Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
void ModelInstance::transform_polygon(Polygon* polygon) const void ModelInstance::transform_polygon(Polygon* polygon) const
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// CHECK_ME -> Is the following correct or it should take in account all three rotations ? // CHECK_ME -> Is the following correct or it should take in account all three rotations ?
polygon->rotate(this->m_rotation(2)); // rotate around polygon origin polygon->rotate(this->m_rotation(2)); // rotate around polygon origin
// CHECK_ME -> Is the following correct ? // CHECK_ME -> Is the following correct ?
polygon->scale(this->m_scaling_factor(0), this->m_scaling_factor(1)); // scale around polygon origin polygon->scale(this->m_scaling_factor(0), this->m_scaling_factor(1)); // scale around polygon origin
#else
polygon->rotate(this->rotation); // rotate around polygon origin
polygon->scale(this->scaling_factor); // scale around polygon origin
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d translation = dont_translate ? Vec3d::Zero() : m_offset; Vec3d translation = dont_translate ? Vec3d::Zero() : m_offset;
Vec3d rotation = dont_rotate ? Vec3d::Zero() : m_rotation; Vec3d rotation = dont_rotate ? Vec3d::Zero() : m_rotation;
Vec3d scale = dont_scale ? Vec3d::Ones() : m_scaling_factor; Vec3d scale = dont_scale ? Vec3d::Ones() : m_scaling_factor;
return Geometry::assemble_transform(translation, rotation, scale); return Geometry::assemble_transform(translation, rotation, scale);
#else
Transform3d m = Transform3d::Identity();
if (!dont_translate)
m.translate(Vec3d(offset(0), offset(1), 0.0));
if (!dont_rotate)
m.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ()));
if (!dont_scale)
m.scale(scaling_factor);
return m;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
} }

View File

@ -247,25 +247,17 @@ public:
friend class ModelObject; friend class ModelObject;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
private: private:
Vec3d m_offset; // in unscaled coordinates Vec3d m_offset; // in unscaled coordinates
Vec3d m_rotation; // Rotation around the three axes, in radians around mesh center point Vec3d m_rotation; // Rotation around the three axes, in radians around mesh center point
Vec3d m_scaling_factor; // Scaling factors along the three axes Vec3d m_scaling_factor; // Scaling factors along the three axes
public: public:
#else
double rotation; // Rotation around the Z axis, in radians around mesh center point
double scaling_factor;
Vec2d offset; // in unscaled coordinates
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// flag showing the position of this instance with respect to the print volume (set by Print::validate() using ModelObject::check_instances_print_volume_state()) // flag showing the position of this instance with respect to the print volume (set by Print::validate() using ModelObject::check_instances_print_volume_state())
EPrintVolumeState print_volume_state; EPrintVolumeState print_volume_state;
ModelObject* get_object() const { return this->object; } ModelObject* get_object() const { return this->object; }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& get_offset() const { return m_offset; } const Vec3d& get_offset() const { return m_offset; }
double get_offset(Axis axis) const { return m_offset(axis); } double get_offset(Axis axis) const { return m_offset(axis); }
@ -283,7 +275,6 @@ public:
void set_scaling_factor(const Vec3d& scaling_factor) { m_scaling_factor = scaling_factor; } void set_scaling_factor(const Vec3d& scaling_factor) { m_scaling_factor = scaling_factor; }
void set_scaling_factor(Axis axis, double scaling_factor) { m_scaling_factor(axis) = scaling_factor; } void set_scaling_factor(Axis axis, double scaling_factor) { m_scaling_factor(axis) = scaling_factor; }
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// To be called on an external mesh // To be called on an external mesh
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
@ -304,15 +295,9 @@ private:
// Parent object, owning this instance. // Parent object, owning this instance.
ModelObject* object; ModelObject* object;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
ModelInstance(ModelObject *object) : m_rotation(Vec3d::Zero()), m_scaling_factor(Vec3d::Ones()), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {} ModelInstance(ModelObject *object) : m_rotation(Vec3d::Zero()), m_scaling_factor(Vec3d::Ones()), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {}
ModelInstance(ModelObject *object, const ModelInstance &other) : ModelInstance(ModelObject *object, const ModelInstance &other) :
m_rotation(other.m_rotation), m_scaling_factor(other.m_scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {} m_rotation(other.m_rotation), m_scaling_factor(other.m_scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {}
#else
ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), offset(Vec2d::Zero()), object(object), print_volume_state(PVS_Inside) {}
ModelInstance(ModelObject *object, const ModelInstance &other) :
rotation(other.rotation), scaling_factor(other.scaling_factor), offset(other.offset), object(object), print_volume_state(PVS_Inside) {}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
}; };

View File

@ -29,12 +29,8 @@ std::string toString(const Model& model, bool holes = true) {
if(!objinst) continue; if(!objinst) continue;
Slic3r::TriangleMesh tmpmesh = rmesh; Slic3r::TriangleMesh tmpmesh = rmesh;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// CHECK_ME -> Is the following correct ? // CHECK_ME -> Is the following correct ?
tmpmesh.scale(objinst->get_scaling_factor()); tmpmesh.scale(objinst->get_scaling_factor());
#else
tmpmesh.scale(objinst->scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
objinst->transform_mesh(&tmpmesh); objinst->transform_mesh(&tmpmesh);
ExPolygons expolys = tmpmesh.horizontal_projection(); ExPolygons expolys = tmpmesh.horizontal_projection();
for(auto& expoly_complex : expolys) { for(auto& expoly_complex : expolys) {
@ -92,11 +88,7 @@ void toSVG(SVG& svg, const Model& model) {
if(!objinst) continue; if(!objinst) continue;
Slic3r::TriangleMesh tmpmesh = rmesh; Slic3r::TriangleMesh tmpmesh = rmesh;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
tmpmesh.scale(objinst->get_scaling_factor()); tmpmesh.scale(objinst->get_scaling_factor());
#else
tmpmesh.scale(objinst->scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
objinst->transform_mesh(&tmpmesh); objinst->transform_mesh(&tmpmesh);
ExPolygons expolys = tmpmesh.horizontal_projection(); ExPolygons expolys = tmpmesh.horizontal_projection();
svg.draw(expolys); svg.draw(expolys);
@ -522,12 +514,8 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) {
Slic3r::TriangleMesh tmpmesh = rmesh; Slic3r::TriangleMesh tmpmesh = rmesh;
ClipperLib::PolygonImpl pn; ClipperLib::PolygonImpl pn;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// CHECK_ME -> is the following correct ? // CHECK_ME -> is the following correct ?
tmpmesh.scale(objinst->get_scaling_factor()); tmpmesh.scale(objinst->get_scaling_factor());
#else
tmpmesh.scale(objinst->scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// TODO export the exact 2D projection // TODO export the exact 2D projection
auto p = tmpmesh.convex_hull(); auto p = tmpmesh.convex_hull();
@ -541,20 +529,11 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) {
// Invalid geometries would throw exceptions when arranging // Invalid geometries would throw exceptions when arranging
if(item.vertexCount() > 3) { if(item.vertexCount() > 3) {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// CHECK_ME -> is the following correct or it should take in account all three rotations ? // CHECK_ME -> is the following correct or it should take in account all three rotations ?
item.rotation(objinst->get_rotation(Z)); item.rotation(objinst->get_rotation(Z));
#else
item.rotation(objinst->rotation);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
item.translation({ item.translation({
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
ClipperLib::cInt(objinst->get_offset(X)/SCALING_FACTOR), ClipperLib::cInt(objinst->get_offset(X)/SCALING_FACTOR),
ClipperLib::cInt(objinst->get_offset(Y)/SCALING_FACTOR) ClipperLib::cInt(objinst->get_offset(Y)/SCALING_FACTOR)
#else
ClipperLib::cInt(objinst->offset(0)/SCALING_FACTOR),
ClipperLib::cInt(objinst->offset(1)/SCALING_FACTOR)
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
}); });
ret.emplace_back(objinst, item); ret.emplace_back(objinst, item);
} }
@ -691,7 +670,6 @@ void applyResult(
// appropriately // appropriately
auto off = item.translation(); auto off = item.translation();
Radians rot = item.rotation(); Radians rot = item.rotation();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d foff(off.X*SCALING_FACTOR + batch_offset, Vec3d foff(off.X*SCALING_FACTOR + batch_offset,
off.Y*SCALING_FACTOR, off.Y*SCALING_FACTOR,
0.0); 0.0);
@ -699,13 +677,6 @@ void applyResult(
// write the transformation data into the model instance // write the transformation data into the model instance
inst_ptr->set_rotation(Z, rot); inst_ptr->set_rotation(Z, rot);
inst_ptr->set_offset(foff); inst_ptr->set_offset(foff);
#else
Vec2d foff(off.X*SCALING_FACTOR + batch_offset, off.Y*SCALING_FACTOR);
// write the transformation data into the model instance
inst_ptr->rotation = rot;
inst_ptr->offset = foff;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
} }

View File

@ -14,7 +14,6 @@ void MultiPoint::scale(double factor)
pt *= factor; pt *= factor;
} }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void MultiPoint::scale(double factor_x, double factor_y) void MultiPoint::scale(double factor_x, double factor_y)
{ {
for (Point &pt : points) for (Point &pt : points)
@ -23,7 +22,6 @@ void MultiPoint::scale(double factor_x, double factor_y)
pt(1) *= factor_y; pt(1) *= factor_y;
} }
} }
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void MultiPoint::translate(double x, double y) void MultiPoint::translate(double x, double y)
{ {

View File

@ -26,9 +26,7 @@ public:
MultiPoint& operator=(const MultiPoint &other) { points = other.points; return *this; } MultiPoint& operator=(const MultiPoint &other) { points = other.points; return *this; }
MultiPoint& operator=(MultiPoint &&other) { points = std::move(other.points); return *this; } MultiPoint& operator=(MultiPoint &&other) { points = std::move(other.points); return *this; }
void scale(double factor); void scale(double factor);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void scale(double factor_x, double factor_y); void scale(double factor_x, double factor_y);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void translate(double x, double y); void translate(double x, double y);
void translate(const Point &vector); void translate(const Point &vector);
void rotate(double angle) { this->rotate(cos(angle), sin(angle)); } void rotate(double angle) { this->rotate(cos(angle), sin(angle)); }

View File

@ -431,14 +431,10 @@ void Print::add_model_object(ModelObject* model_object, int idx)
std::vector<std::string> v_scale; std::vector<std::string> v_scale;
for (const PrintObject *object : m_objects) { for (const PrintObject *object : m_objects) {
const ModelObject &mobj = *object->model_object(); const ModelObject &mobj = *object->model_object();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// CHECK_ME -> Is the following correct ? // CHECK_ME -> Is the following correct ?
v_scale.push_back("x:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(X) * 100) + v_scale.push_back("x:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(X) * 100) +
"% y:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(Y) * 100) + "% y:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(Y) * 100) +
"% z:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(Z) * 100) + "%"); "% z:" + boost::lexical_cast<std::string>(mobj.instances[0]->get_scaling_factor(Z) * 100) + "%");
#else
v_scale.push_back(boost::lexical_cast<std::string>(mobj.instances[0]->scaling_factor * 100) + "%");
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (input_file.empty()) if (input_file.empty())
input_file = mobj.input_file; input_file = mobj.input_file;
} }

View File

@ -113,16 +113,11 @@ bool PrintObject::reload_model_instances()
copies.reserve(m_model_object->instances.size()); copies.reserve(m_model_object->instances.size());
for (const ModelInstance *mi : m_model_object->instances) for (const ModelInstance *mi : m_model_object->instances)
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (mi->is_printable()) if (mi->is_printable())
{ {
const Vec3d& offset = mi->get_offset(); const Vec3d& offset = mi->get_offset();
copies.emplace_back(Point::new_scale(offset(0), offset(1))); copies.emplace_back(Point::new_scale(offset(0), offset(1)));
} }
#else
if (mi->is_printable())
copies.emplace_back(Point::new_scale(mi->offset(0), mi->offset(1)));
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
return this->set_copies(copies); return this->set_copies(copies);
} }

View File

@ -4,16 +4,12 @@
// 1.42.0 techs // 1.42.0 techs
#define ENABLE_1_42_0 1 #define ENABLE_1_42_0 1
// Add z coordinate to model instances' offset
// Add x and y rotation components to model instances' rotation
// Add scaling factors for all the three axes to model instances
#define ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM (1 && ENABLE_1_42_0)
// Add double click on gizmo grabbers to reset transformation components to their default value // Add double click on gizmo grabbers to reset transformation components to their default value
#define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0) #define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0)
// Uses a unique opengl context // Uses a unique opengl context
#define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0) #define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0)
// New selections // New selections
#define ENABLE_EXTENDED_SELECTION (1 && ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM) #define ENABLE_EXTENDED_SELECTION (1 && ENABLE_1_42_0)
#endif // _technologies_h_ #endif // _technologies_h_

View File

@ -196,13 +196,8 @@ const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f };
GLVolume::GLVolume(float r, float g, float b, float a) GLVolume::GLVolume(float r, float g, float b, float a)
: m_offset(Vec3d::Zero()) : m_offset(Vec3d::Zero())
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
, m_rotation(Vec3d::Zero()) , m_rotation(Vec3d::Zero())
, m_scaling_factor(Vec3d::Ones()) , m_scaling_factor(Vec3d::Ones())
#else
, m_rotation(0.0)
, m_scaling_factor(1.0)
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
, m_world_matrix(Transform3f::Identity()) , m_world_matrix(Transform3f::Identity())
, m_world_matrix_dirty(true) , m_world_matrix_dirty(true)
, m_transformed_bounding_box_dirty(true) , m_transformed_bounding_box_dirty(true)
@ -262,7 +257,6 @@ void GLVolume::set_render_color()
set_render_color(color, 4); set_render_color(color, 4);
} }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& GLVolume::get_rotation() const const Vec3d& GLVolume::get_rotation() const
{ {
return m_rotation; return m_rotation;
@ -295,23 +289,6 @@ void GLVolume::set_rotation(const Vec3d& rotation)
m_transformed_convex_hull_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true;
} }
} }
#else
double GLVolume::get_rotation() const
{
return m_rotation;
}
void GLVolume::set_rotation(double rotation)
{
if (m_rotation != rotation)
{
m_rotation = rotation;
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& GLVolume::get_offset() const const Vec3d& GLVolume::get_offset() const
{ {
@ -329,7 +306,6 @@ void GLVolume::set_offset(const Vec3d& offset)
} }
} }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
const Vec3d& GLVolume::get_scaling_factor() const const Vec3d& GLVolume::get_scaling_factor() const
{ {
@ -347,18 +323,6 @@ void GLVolume::set_scaling_factor(const Vec3d& scaling_factor)
m_transformed_convex_hull_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true;
} }
} }
#else
void GLVolume::set_scaling_factor(double factor)
{
if (m_scaling_factor != factor)
{
m_scaling_factor = factor;
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void GLVolume::set_convex_hull(const TriangleMesh& convex_hull) void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
{ {
@ -389,14 +353,7 @@ const Transform3f& GLVolume::world_matrix() const
{ {
if (m_world_matrix_dirty) if (m_world_matrix_dirty)
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_world_matrix = Geometry::assemble_transform(m_offset, m_rotation, m_scaling_factor).cast<float>(); m_world_matrix = Geometry::assemble_transform(m_offset, m_rotation, m_scaling_factor).cast<float>();
#else
m_world_matrix = Transform3f::Identity();
m_world_matrix.translate(m_offset.cast<float>());
m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ()));
m_world_matrix.scale((float)m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_world_matrix_dirty = false; m_world_matrix_dirty = false;
} }
return m_world_matrix; return m_world_matrix;
@ -471,13 +428,7 @@ void GLVolume::render() const
::glCullFace(GL_BACK); ::glCullFace(GL_BACK);
::glPushMatrix(); ::glPushMatrix();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glMultMatrixf(world_matrix().data()); ::glMultMatrixf(world_matrix().data());
#else
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (this->indexed_vertex_array.indexed()) if (this->indexed_vertex_array.indexed())
this->indexed_vertex_array.render(this->tverts_range, this->qverts_range); this->indexed_vertex_array.render(this->tverts_range, this->qverts_range);
else else
@ -602,13 +553,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
::glPushMatrix(); ::glPushMatrix();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glMultMatrixf(world_matrix().data()); ::glMultMatrixf(world_matrix().data());
#else
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (n_triangles > 0) if (n_triangles > 0)
{ {
@ -652,13 +597,7 @@ void GLVolume::render_legacy() const
::glPushMatrix(); ::glPushMatrix();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glMultMatrixf(world_matrix().data()); ::glMultMatrixf(world_matrix().data());
#else
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (n_triangles > 0) if (n_triangles > 0)
::glDrawElements(GL_TRIANGLES, n_triangles, GL_UNSIGNED_INT, indexed_vertex_array.triangle_indices.data() + tverts_range.first); ::glDrawElements(GL_TRIANGLES, n_triangles, GL_UNSIGNED_INT, indexed_vertex_array.triangle_indices.data() + tverts_range.first);
@ -787,15 +726,9 @@ std::vector<int> GLVolumeCollection::load_object(
} }
v.is_modifier = ! model_volume->is_model_part(); v.is_modifier = ! model_volume->is_model_part();
v.shader_outside_printer_detection_enabled = model_volume->is_model_part(); v.shader_outside_printer_detection_enabled = model_volume->is_model_part();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
v.set_offset(instance->get_offset()); v.set_offset(instance->get_offset());
v.set_rotation(instance->get_rotation()); v.set_rotation(instance->get_rotation());
v.set_scaling_factor(instance->get_scaling_factor()); v.set_scaling_factor(instance->get_scaling_factor());
#else
v.set_offset(Vec3d(instance->offset(0), instance->offset(1), 0.0));
v.set_rotation(instance->rotation);
v.set_scaling_factor(instance->scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
} }

View File

@ -256,17 +256,10 @@ public:
private: private:
// Offset of the volume to be rendered. // Offset of the volume to be rendered.
Vec3d m_offset; Vec3d m_offset;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Rotation around three axes of the volume to be rendered. // Rotation around three axes of the volume to be rendered.
Vec3d m_rotation; Vec3d m_rotation;
// Scale factor along the three axes of the volume to be rendered. // Scale factor along the three axes of the volume to be rendered.
Vec3d m_scaling_factor; Vec3d m_scaling_factor;
#else
// Rotation around Z axis of the volume to be rendered.
double m_rotation;
// Scale factor of the volume to be rendered.
double m_scaling_factor;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// World matrix of the volume to be rendered. // World matrix of the volume to be rendered.
mutable Transform3f m_world_matrix; mutable Transform3f m_world_matrix;
// Whether or not is needed to recalculate the world matrix. // Whether or not is needed to recalculate the world matrix.
@ -336,7 +329,6 @@ public:
// Sets render color in dependence of current state // Sets render color in dependence of current state
void set_render_color(); void set_render_color();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& get_rotation() const; const Vec3d& get_rotation() const;
void set_rotation(const Vec3d& rotation); void set_rotation(const Vec3d& rotation);
@ -344,12 +336,6 @@ public:
const Vec3d& get_scaling_factor() const; const Vec3d& get_scaling_factor() const;
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
void set_scaling_factor(const Vec3d& scaling_factor); void set_scaling_factor(const Vec3d& scaling_factor);
#else
double get_rotation() const;
void set_rotation(double rotation);
void set_scaling_factor(double factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& get_offset() const; const Vec3d& get_offset() const;
void set_offset(const Vec3d& offset); void set_offset(const Vec3d& offset);

View File

@ -1830,11 +1830,6 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
if (!gizmo->init()) if (!gizmo->init())
return false; return false;
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// temporary disable z grabber
gizmo->disable_grabber(2);
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_gizmos.insert(GizmosMap::value_type(Move, gizmo)); m_gizmos.insert(GizmosMap::value_type(Move, gizmo));
gizmo = new GLGizmoScale3D(parent); gizmo = new GLGizmoScale3D(parent);
@ -1844,18 +1839,6 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
if (!gizmo->init()) if (!gizmo->init())
return false; return false;
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// temporary disable x grabbers
gizmo->disable_grabber(0);
gizmo->disable_grabber(1);
// temporary disable y grabbers
gizmo->disable_grabber(2);
gizmo->disable_grabber(3);
// temporary disable z grabbers
gizmo->disable_grabber(4);
gizmo->disable_grabber(5);
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_gizmos.insert(GizmosMap::value_type(Scale, gizmo)); m_gizmos.insert(GizmosMap::value_type(Scale, gizmo));
gizmo = new GLGizmoRotate3D(parent); gizmo = new GLGizmoRotate3D(parent);
@ -1871,12 +1854,6 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
return false; return false;
} }
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// temporary disable x and y grabbers
gizmo->disable_grabber(0);
gizmo->disable_grabber(1);
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_gizmos.insert(GizmosMap::value_type(Rotate, gizmo)); m_gizmos.insert(GizmosMap::value_type(Rotate, gizmo));
gizmo = new GLGizmoFlatten(parent); gizmo = new GLGizmoFlatten(parent);
@ -2161,7 +2138,6 @@ void GLCanvas3D::Gizmos::set_position(const Vec3d& position)
} }
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d GLCanvas3D::Gizmos::get_scale() const Vec3d GLCanvas3D::Gizmos::get_scale() const
{ {
if (!m_enabled) if (!m_enabled)
@ -2208,54 +2184,6 @@ Vec3d GLCanvas3D::Gizmos::get_flattening_rotation() const
GizmosMap::const_iterator it = m_gizmos.find(Flatten); GizmosMap::const_iterator it = m_gizmos.find(Flatten);
return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoFlatten*>(it->second)->get_flattening_rotation() : Vec3d::Zero(); return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoFlatten*>(it->second)->get_flattening_rotation() : Vec3d::Zero();
} }
#else
float GLCanvas3D::Gizmos::get_scale() const
{
if (!m_enabled)
return 1.0f;
GizmosMap::const_iterator it = m_gizmos.find(Scale);
return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoScale3D*>(it->second)->get_scale_x() : 1.0f;
}
void GLCanvas3D::Gizmos::set_scale(float scale)
{
if (!m_enabled)
return;
GizmosMap::const_iterator it = m_gizmos.find(Scale);
if (it != m_gizmos.end())
reinterpret_cast<GLGizmoScale3D*>(it->second)->set_scale(scale);
}
float GLCanvas3D::Gizmos::get_angle_z() const
{
if (!m_enabled)
return 0.0f;
GizmosMap::const_iterator it = m_gizmos.find(Rotate);
return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoRotate3D*>(it->second)->get_angle_z() : 0.0f;
}
void GLCanvas3D::Gizmos::set_angle_z(float angle_z)
{
if (!m_enabled)
return;
GizmosMap::const_iterator it = m_gizmos.find(Rotate);
if (it != m_gizmos.end())
reinterpret_cast<GLGizmoRotate3D*>(it->second)->set_angle_z(angle_z);
}
Vec3d GLCanvas3D::Gizmos::get_flattening_normal() const
{
if (!m_enabled)
return Vec3d::Zero();
GizmosMap::const_iterator it = m_gizmos.find(Flatten);
return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoFlatten*>(it->second)->get_flattening_normal() : Vec3d::Zero();
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void GLCanvas3D::Gizmos::set_flattening_data(const ModelObject* model_object) void GLCanvas3D::Gizmos::set_flattening_data(const ModelObject* model_object)
{ {
@ -3306,15 +3234,9 @@ void GLCanvas3D::update_gizmos_data()
ModelInstance* model_instance = model_object->instances[0]; ModelInstance* model_instance = model_object->instances[0];
if (model_instance != nullptr) if (model_instance != nullptr)
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_gizmos.set_position(model_instance->get_offset()); m_gizmos.set_position(model_instance->get_offset());
m_gizmos.set_scale(model_instance->get_scaling_factor()); m_gizmos.set_scale(model_instance->get_scaling_factor());
m_gizmos.set_rotation(model_instance->get_rotation()); m_gizmos.set_rotation(model_instance->get_rotation());
#else
m_gizmos.set_position(Vec3d(model_instance->offset(0), model_instance->offset(1), 0.0));
m_gizmos.set_scale(model_instance->scaling_factor);
m_gizmos.set_angle_z(model_instance->rotation);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_gizmos.set_flattening_data(model_object); m_gizmos.set_flattening_data(model_object);
} }
} }
@ -3322,13 +3244,8 @@ void GLCanvas3D::update_gizmos_data()
else else
{ {
m_gizmos.set_position(Vec3d::Zero()); m_gizmos.set_position(Vec3d::Zero());
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_gizmos.set_scale(Vec3d::Ones()); m_gizmos.set_scale(Vec3d::Ones());
m_gizmos.set_rotation(Vec3d::Zero()); m_gizmos.set_rotation(Vec3d::Zero());
#else
m_gizmos.set_scale(1.0f);
m_gizmos.set_angle_z(0.0f);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_gizmos.set_flattening_data(nullptr); m_gizmos.set_flattening_data(nullptr);
} }
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
@ -3862,17 +3779,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
{ {
case Gizmos::Scale: case Gizmos::Scale:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
m_regenerate_volumes = false; m_regenerate_volumes = false;
m_selection.scale(m_gizmos.get_scale()); m_selection.scale(m_gizmos.get_scale());
_on_scale(); _on_scale();
#else
post_event(Vec3dEvent(EVT_GIZMO_SCALE, m_gizmos.get_scale()));
#endif // ENABLE_EXTENDED_SELECTION
#else #else
m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale()); m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale());
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM #endif // ENABLE_EXTENDED_SELECTION
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
wxGetApp().obj_manipul()->update_settings_value(m_selection); wxGetApp().obj_manipul()->update_settings_value(m_selection);
#else #else
@ -3883,7 +3796,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
} }
case Gizmos::Rotate: case Gizmos::Rotate:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
m_regenerate_volumes = false; m_regenerate_volumes = false;
m_selection.rotate(m_gizmos.get_rotation()); m_selection.rotate(m_gizmos.get_rotation());
@ -3891,9 +3803,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
#else #else
post_event(Vec3dEvent(EVT_GIZMO_ROTATE, std::move(m_gizmos.get_rotation()))); post_event(Vec3dEvent(EVT_GIZMO_ROTATE, std::move(m_gizmos.get_rotation())));
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#else
m_on_gizmo_rotate_callback.call((double)m_gizmos.get_angle_z());
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
wxGetApp().obj_manipul()->update_settings_value(m_selection); wxGetApp().obj_manipul()->update_settings_value(m_selection);
#else #else
@ -3969,18 +3878,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
if (m_gizmos.get_current_type() == Gizmos::Flatten) { if (m_gizmos.get_current_type() == Gizmos::Flatten) {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Rotate the object so the normal points downward: // Rotate the object so the normal points downward:
post_event(Vec3dEvent(EVT_GIZMO_FLATTEN, m_gizmos.get_flattening_rotation())); post_event(Vec3dEvent(EVT_GIZMO_FLATTEN, m_gizmos.get_flattening_rotation()));
#else
// Rotate the object so the normal points downward:
Vec3d normal = m_gizmos.get_flattening_normal();
if (normal(0) != 0.0 || normal(1) != 0.0 || normal(2) != 0.0) {
Vec3d axis = normal(2) > 0.999 ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ()).normalized();
float angle = acos(clamp(-1.0, 1.0, -normal(2)));
m_on_gizmo_flatten_callback.call(angle, (float)axis(0), (float)axis(1), (float)axis(2));
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
m_dirty = true; m_dirty = true;
@ -4215,7 +4114,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
} }
case Gizmos::Scale: case Gizmos::Scale:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Apply new temporary scale factors // Apply new temporary scale factors
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
m_selection.scale(m_gizmos.get_scale()); m_selection.scale(m_gizmos.get_scale());
@ -4228,20 +4126,10 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
} }
wxGetApp().obj_manipul()->update_scale_value(scale); wxGetApp().obj_manipul()->update_scale_value(scale);
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#else
// Apply new temporary scale factor
float scale_factor = m_gizmos.get_scale();
for (GLVolume* v : volumes)
{
v->set_scaling_factor((double)scale_factor);
}
wxGetApp().obj_manipul()->update_scale_values((double)scale_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
break; break;
} }
case Gizmos::Rotate: case Gizmos::Rotate:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// Apply new temporary rotations // Apply new temporary rotations
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
m_selection.rotate(m_gizmos.get_rotation()); m_selection.rotate(m_gizmos.get_rotation());
@ -4255,15 +4143,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
} }
wxGetApp().obj_manipul()->update_rotation_value(rotation); wxGetApp().obj_manipul()->update_rotation_value(rotation);
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#else
// Apply new temporary angle_z
float angle_z = m_gizmos.get_angle_z();
for (GLVolume* v : volumes)
{
v->set_rotation((double)angle_z);
}
update_rotation_value((double)angle_z, Z);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
break; break;
} }
default: default:
@ -4280,12 +4159,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
bb.merge(volume->transformed_bounding_box()); bb.merge(volume->transformed_bounding_box());
} }
const Vec3d& size = bb.size(); const Vec3d& size = bb.size();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& scale = m_gizmos.get_scale(); const Vec3d& scale = m_gizmos.get_scale();
post_event(Vec3dsEvent<2>(EVT_GLCANVAS_UPDATE_GEOMETRY, {size, scale})); post_event(Vec3dsEvent<2>(EVT_GLCANVAS_UPDATE_GEOMETRY, {size, scale}));
#else
m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale());
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
@ -4428,28 +4303,20 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
} }
case Gizmos::Scale: case Gizmos::Scale:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
m_regenerate_volumes = false; m_regenerate_volumes = false;
_on_scale(); _on_scale();
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#else
m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale());
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
break; break;
} }
case Gizmos::Rotate: case Gizmos::Rotate:
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
m_regenerate_volumes = false; m_regenerate_volumes = false;
_on_rotate(); _on_rotate();
#else #else
post_event(Vec3dEvent(EVT_GIZMO_ROTATE, m_gizmos.get_rotation())); post_event(Vec3dEvent(EVT_GIZMO_ROTATE, m_gizmos.get_rotation()));
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#else
m_on_gizmo_rotate_callback.call((double)m_gizmos.get_angle_z());
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
break; break;
} }
default: default:
@ -6625,12 +6492,7 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
ModelObject* model_object = m_model->objects[obj_idx]; ModelObject* model_object = m_model->objects[obj_idx];
if (model_object != nullptr) if (model_object != nullptr)
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
model_object->instances[instance_idx]->set_offset(volume->get_offset()); model_object->instances[instance_idx]->set_offset(volume->get_offset());
#else
const Vec3d& offset = volume->get_offset();
model_object->instances[instance_idx]->offset = Vec2d(offset(0), offset(1));
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
model_object->invalidate_bounding_box(); model_object->invalidate_bounding_box();
wxGetApp().obj_manipul()->update_position_values(); wxGetApp().obj_manipul()->update_position_values();
object_moved = true; object_moved = true;

View File

@ -589,7 +589,6 @@ private:
void set_position(const Vec3d& position); void set_position(const Vec3d& position);
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d get_scale() const; Vec3d get_scale() const;
void set_scale(const Vec3d& scale); void set_scale(const Vec3d& scale);
@ -597,15 +596,6 @@ private:
void set_rotation(const Vec3d& rotation); void set_rotation(const Vec3d& rotation);
Vec3d get_flattening_rotation() const; Vec3d get_flattening_rotation() const;
#else
float get_scale() const;
void set_scale(float scale);
float get_angle_z() const;
void set_angle_z(float angle_z);
Vec3d get_flattening_normal() const;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void set_flattening_data(const ModelObject* model_object); void set_flattening_data(const ModelObject* model_object);

View File

@ -1086,11 +1086,7 @@ void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
if (ratio > 0.0) if (ratio > 0.0)
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_scale(1) = m_starting_scale(1) * ratio; m_scale(1) = m_starting_scale(1) * ratio;
#else
m_scale(0) = m_starting_scale(1) * ratio;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray) void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
@ -1102,11 +1098,7 @@ void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
if (ratio > 0.0) if (ratio > 0.0)
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_scale(2) = m_starting_scale(2) * ratio; m_scale(2) = m_starting_scale(2) * ratio;
#else
m_scale(0) = m_starting_scale(2) * ratio; // << this is temporary
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray) void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
@ -1490,18 +1482,11 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
else else
::glColor4f(0.9f, 0.9f, 0.9f, 0.5f); ::glColor4f(0.9f, 0.9f, 0.9f, 0.5f);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
for (const InstanceData& inst : m_instances) { for (const InstanceData& inst : m_instances) {
Transform3d m = inst.matrix; Transform3d m = inst.matrix;
m.pretranslate(dragged_offset); m.pretranslate(dragged_offset);
::glPushMatrix(); ::glPushMatrix();
::glMultMatrixd(m.data()); ::glMultMatrixd(m.data());
#else
for (Vec2d offset : m_instances_positions) {
offset += to_2d(dragged_offset);
::glPushMatrix();
::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glBegin(GL_POLYGON); ::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices) for (const Vec3d& vertex : m_planes[i].vertices)
::glVertex3dv(vertex.data()); ::glVertex3dv(vertex.data());
@ -1524,15 +1509,9 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
for (unsigned int i = 0; i < m_planes.size(); ++i) for (unsigned int i = 0; i < m_planes.size(); ++i)
{ {
::glColor3f(1.0f, 1.0f, picking_color_component(i)); ::glColor3f(1.0f, 1.0f, picking_color_component(i));
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
for (const InstanceData& inst : m_instances) { for (const InstanceData& inst : m_instances) {
::glPushMatrix(); ::glPushMatrix();
::glMultMatrixd(inst.matrix.data()); ::glMultMatrixd(inst.matrix.data());
#else
for (const Vec2d& offset : m_instances_positions) {
::glPushMatrix();
::glTranslatef((GLfloat)offset(0), (GLfloat)offset(1), 0.0f);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glBegin(GL_POLYGON); ::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices) for (const Vec3d& vertex : m_planes[i].vertices)
::glVertex3dv(vertex.data()); ::glVertex3dv(vertex.data());
@ -1548,17 +1527,9 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
// ...and save the updated positions of the object instances: // ...and save the updated positions of the object instances:
if (m_model_object && !m_model_object->instances.empty()) { if (m_model_object && !m_model_object->instances.empty()) {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_instances.clear(); m_instances.clear();
#else
m_instances_positions.clear();
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
for (const auto* instance : m_model_object->instances) for (const auto* instance : m_model_object->instances)
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_instances.emplace_back(instance->world_matrix()); m_instances.emplace_back(instance->world_matrix());
#else
m_instances_positions.emplace_back(instance->offset);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
if (is_plane_update_necessary()) if (is_plane_update_necessary())
@ -1572,10 +1543,6 @@ void GLGizmoFlatten::update_planes()
ch.merge(vol->get_convex_hull()); ch.merge(vol->get_convex_hull());
ch = ch.convex_hull_3d(); ch = ch.convex_hull_3d();
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
ch.scale(m_model_object->instances.front()->scaling_factor);
ch.rotate_z(m_model_object->instances.front()->rotation);
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& bb_size = ch.bounding_box().size(); const Vec3d& bb_size = ch.bounding_box().size();
double min_bb_face_area = std::min(bb_size(0) * bb_size(1), std::min(bb_size(0) * bb_size(2), bb_size(1) * bb_size(2))); double min_bb_face_area = std::min(bb_size(0) * bb_size(1), std::min(bb_size(0) * bb_size(2), bb_size(1) * bb_size(2)));
@ -1741,10 +1708,6 @@ void GLGizmoFlatten::update_planes()
m_source_data.bounding_boxes.clear(); m_source_data.bounding_boxes.clear();
for (const auto& vol : m_model_object->volumes) for (const auto& vol : m_model_object->volumes)
m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box()); m_source_data.bounding_boxes.push_back(vol->get_convex_hull().bounding_box());
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_source_data.scaling_factor = m_model_object->instances.front()->scaling_factor;
m_source_data.rotation = m_model_object->instances.front()->rotation;
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex(); const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex();
m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]); m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]);
} }
@ -1756,13 +1719,7 @@ bool GLGizmoFlatten::is_plane_update_necessary() const
if (m_state != On || !m_model_object || m_model_object->instances.empty()) if (m_state != On || !m_model_object || m_model_object->instances.empty())
return false; return false;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size()) if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size())
#else
if (m_model_object->volumes.size() != m_source_data.bounding_boxes.size()
|| m_model_object->instances.front()->scaling_factor != m_source_data.scaling_factor
|| m_model_object->instances.front()->rotation != m_source_data.rotation)
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
return true; return true;
// now compare the bounding boxes: // now compare the bounding boxes:
@ -1778,7 +1735,6 @@ bool GLGizmoFlatten::is_plane_update_necessary() const
return false; return false;
} }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d GLGizmoFlatten::get_flattening_rotation() const Vec3d GLGizmoFlatten::get_flattening_rotation() const
{ {
// calculates the rotations in model space, taking in account the scaling factors // calculates the rotations in model space, taking in account the scaling factors
@ -1788,13 +1744,6 @@ Vec3d GLGizmoFlatten::get_flattening_rotation() const
m_normal = Vec3d::Zero(); m_normal = Vec3d::Zero();
return Vec3d(angles(2), angles(1), angles(0)); return Vec3d(angles(2), angles(1), angles(0));
} }
#else
Vec3d GLGizmoFlatten::get_flattening_normal() const {
Vec3d normal = m_model_object->instances.front()->world_matrix(true).matrix().block(0, 0, 3, 3).inverse() * m_normal;
m_normal = Vec3d::Zero();
return normal.normalized();
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} // namespace GUI } // namespace GUI
} // namespace Slic3r } // namespace Slic3r

View File

@ -230,19 +230,8 @@ class GLGizmoRotate3D : public GLGizmoBase
public: public:
explicit GLGizmoRotate3D(GLCanvas3D& parent); explicit GLGizmoRotate3D(GLCanvas3D& parent);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d get_rotation() const { return Vec3d(m_gizmos[X].get_angle(), m_gizmos[Y].get_angle(), m_gizmos[Z].get_angle()); } Vec3d get_rotation() const { return Vec3d(m_gizmos[X].get_angle(), m_gizmos[Y].get_angle(), m_gizmos[Z].get_angle()); }
void set_rotation(const Vec3d& rotation) { m_gizmos[X].set_angle(rotation(0)); m_gizmos[Y].set_angle(rotation(1)); m_gizmos[Z].set_angle(rotation(2)); } void set_rotation(const Vec3d& rotation) { m_gizmos[X].set_angle(rotation(0)); m_gizmos[Y].set_angle(rotation(1)); m_gizmos[Z].set_angle(rotation(2)); }
#else
double get_angle_x() const { return m_gizmos[X].get_angle(); }
void set_angle_x(double angle) { m_gizmos[X].set_angle(angle); }
double get_angle_y() const { return m_gizmos[Y].get_angle(); }
void set_angle_y(double angle) { m_gizmos[Y].set_angle(angle); }
double get_angle_z() const { return m_gizmos[Z].get_angle(); }
void set_angle_z(double angle) { m_gizmos[Z].set_angle(angle); }
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
protected: protected:
virtual bool on_init(); virtual bool on_init();
@ -329,25 +318,12 @@ class GLGizmoScale3D : public GLGizmoBase
public: public:
explicit GLGizmoScale3D(GLCanvas3D& parent); explicit GLGizmoScale3D(GLCanvas3D& parent);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& get_scale() const { return m_scale; } const Vec3d& get_scale() const { return m_scale; }
#if ENABLE_EXTENDED_SELECTION #if ENABLE_EXTENDED_SELECTION
void set_scale(const Vec3d& scale) { m_starting_scale = scale; m_scale = scale; } void set_scale(const Vec3d& scale) { m_starting_scale = scale; m_scale = scale; }
#else #else
void set_scale(const Vec3d& scale) { m_starting_scale = scale; } void set_scale(const Vec3d& scale) { m_starting_scale = scale; }
#endif // ENABLE_EXTENDED_SELECTION #endif // ENABLE_EXTENDED_SELECTION
#else
double get_scale_x() const { return m_scale(0); }
void set_scale_x(double scale) { m_starting_scale(0) = scale; }
double get_scale_y() const { return m_scale(1); }
void set_scale_y(double scale) { m_starting_scale(1) = scale; }
double get_scale_z() const { return m_scale(2); }
void set_scale_z(double scale) { m_starting_scale(2) = scale; }
void set_scale(double scale) { m_starting_scale = scale * Vec3d::Ones(); }
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
protected: protected:
virtual bool on_init(); virtual bool on_init();
@ -444,10 +420,6 @@ private:
}; };
struct SourceDataSummary { struct SourceDataSummary {
std::vector<BoundingBoxf3> bounding_boxes; // bounding boxes of convex hulls of individual volumes std::vector<BoundingBoxf3> bounding_boxes; // bounding boxes of convex hulls of individual volumes
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
float scaling_factor;
float rotation;
#endif // !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d mesh_first_point; Vec3d mesh_first_point;
}; };
@ -455,16 +427,12 @@ private:
SourceDataSummary m_source_data; SourceDataSummary m_source_data;
std::vector<PlaneData> m_planes; std::vector<PlaneData> m_planes;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
struct InstanceData struct InstanceData
{ {
Transform3d matrix; Transform3d matrix;
InstanceData(const Transform3d& matrix) : matrix(matrix) {} InstanceData(const Transform3d& matrix) : matrix(matrix) {}
}; };
std::vector<InstanceData> m_instances; std::vector<InstanceData> m_instances;
#else
std::vector<Vec2d> m_instances_positions;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d m_starting_center; Vec3d m_starting_center;
const ModelObject* m_model_object = nullptr; const ModelObject* m_model_object = nullptr;
@ -475,11 +443,7 @@ public:
explicit GLGizmoFlatten(GLCanvas3D& parent); explicit GLGizmoFlatten(GLCanvas3D& parent);
void set_flattening_data(const ModelObject* model_object); void set_flattening_data(const ModelObject* model_object);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d get_flattening_rotation() const; Vec3d get_flattening_rotation() const;
#else
Vec3d get_flattening_normal() const;
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
protected: protected:
virtual bool on_init(); virtual bool on_init();

View File

@ -375,7 +375,6 @@ void ObjectManipulation::update_scale_values()
auto instance = objects[selection]->instances.front(); auto instance = objects[selection]->instances.front();
auto size = objects[selection]->instance_bounding_box(0).size(); auto size = objects[selection]->instance_bounding_box(0).size();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (m_is_percent_scale) { if (m_is_percent_scale) {
m_og->set_value("scale_x", int(instance->get_scaling_factor(X) * 100)); m_og->set_value("scale_x", int(instance->get_scaling_factor(X) * 100));
m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * 100)); m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * 100));
@ -386,34 +385,15 @@ void ObjectManipulation::update_scale_values()
m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * size(1) + 0.5)); m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * size(1) + 0.5));
m_og->set_value("scale_z", int(instance->get_scaling_factor(Z) * size(2) + 0.5)); m_og->set_value("scale_z", int(instance->get_scaling_factor(Z) * size(2) + 0.5));
} }
#else
if (m_is_percent_scale) {
auto scale = instance->scaling_factor * 100.0;
m_og->set_value("scale_x", int(scale));
m_og->set_value("scale_y", int(scale));
m_og->set_value("scale_z", int(scale));
}
else {
m_og->set_value("scale_x", int(instance->scaling_factor * size(0) + 0.5));
m_og->set_value("scale_y", int(instance->scaling_factor * size(1) + 0.5));
m_og->set_value("scale_z", int(instance->scaling_factor * size(2) + 0.5));
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
void ObjectManipulation::update_position_values() void ObjectManipulation::update_position_values()
{ {
auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front(); auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_og->set_value("position_x", int(instance->get_offset(X))); m_og->set_value("position_x", int(instance->get_offset(X)));
m_og->set_value("position_y", int(instance->get_offset(Y))); m_og->set_value("position_y", int(instance->get_offset(Y)));
m_og->set_value("position_z", int(instance->get_offset(Z))); m_og->set_value("position_z", int(instance->get_offset(Z)));
#else
m_og->set_value("position_x", int(instance->offset(0)));
m_og->set_value("position_y", int(instance->offset(1)));
m_og->set_value("position_z", 0);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
void ObjectManipulation::update_position_value(const Vec3d& position) void ObjectManipulation::update_position_value(const Vec3d& position)
@ -423,7 +403,6 @@ void ObjectManipulation::update_position_value(const Vec3d& position)
m_og->set_value("position_z", int(position(2))); m_og->set_value("position_z", int(position(2)));
} }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor) void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor)
{ {
// this is temporary // this is temporary
@ -438,33 +417,10 @@ void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor)
m_og->set_value("scale_y", int(scale(1))); m_og->set_value("scale_y", int(scale(1)));
m_og->set_value("scale_z", int(scale(2))); m_og->set_value("scale_z", int(scale(2)));
} }
#else
void ObjectManipulation::update_scale_values(double scaling_factor)
{
// this is temporary
// to be able to update the values as size
// we need to store somewhere the original size
// or have it passed as parameter
if (!m_is_percent_scale)
m_og->set_value("scale_unit", _("%"));
auto scale = scaling_factor * 100.0;
m_og->set_value("scale_x", int(scale));
m_og->set_value("scale_y", int(scale));
m_og->set_value("scale_z", int(scale));
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void ObjectManipulation::update_rotation_values() void ObjectManipulation::update_rotation_values()
{ {
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
update_rotation_value(wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front()->get_rotation()); update_rotation_value(wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front()->get_rotation());
#else
auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front();
m_og->set_value("rotation_x", 0);
m_og->set_value("rotation_y", 0);
m_og->set_value("rotation_z", int(Geometry::rad2deg(instance->rotation)));
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
} }
void ObjectManipulation::update_rotation_value(double angle, Axis axis) void ObjectManipulation::update_rotation_value(double angle, Axis axis)
@ -485,14 +441,12 @@ void ObjectManipulation::update_rotation_value(double angle, Axis axis)
m_og->set_value(axis_str, round_nearest(int(Geometry::rad2deg(angle)), 0)); m_og->set_value(axis_str, round_nearest(int(Geometry::rad2deg(angle)), 0));
} }
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void ObjectManipulation::update_rotation_value(const Vec3d& rotation) void ObjectManipulation::update_rotation_value(const Vec3d& rotation)
{ {
m_og->set_value("rotation_x", int(round_nearest(Geometry::rad2deg(rotation(0)), 0))); m_og->set_value("rotation_x", int(round_nearest(Geometry::rad2deg(rotation(0)), 0)));
m_og->set_value("rotation_y", int(round_nearest(Geometry::rad2deg(rotation(1)), 0))); m_og->set_value("rotation_y", int(round_nearest(Geometry::rad2deg(rotation(1)), 0)));
m_og->set_value("rotation_z", int(round_nearest(Geometry::rad2deg(rotation(2)), 0))); m_og->set_value("rotation_z", int(round_nearest(Geometry::rad2deg(rotation(2)), 0)));
} }
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void ObjectManipulation::show_object_name(bool show) void ObjectManipulation::show_object_name(bool show)
{ {

View File

@ -61,18 +61,12 @@ public:
void update_position_value(const Vec3d& position); void update_position_value(const Vec3d& position);
// update scale values after scale unit changing or "gizmos" // update scale values after scale unit changing or "gizmos"
void update_scale_values(); void update_scale_values();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void update_scale_value(const Vec3d& scaling_factor); void update_scale_value(const Vec3d& scaling_factor);
#else
void update_scale_values(double scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
// update rotation values object selection changing // update rotation values object selection changing
void update_rotation_values(); void update_rotation_values();
// update rotation value after "gizmos" // update rotation value after "gizmos"
void update_rotation_value(double angle, Axis axis); void update_rotation_value(double angle, Axis axis);
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void update_rotation_value(const Vec3d& rotation); void update_rotation_value(const Vec3d& rotation);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; } void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; }

View File

@ -295,7 +295,6 @@ ModelMaterial::attributes()
Ref<ModelObject> object() Ref<ModelObject> object()
%code%{ RETVAL = THIS->get_object(); %}; %code%{ RETVAL = THIS->get_object(); %};
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d* rotation() Vec3d* rotation()
%code%{ RETVAL = new Vec3d(THIS->get_rotation(X), THIS->get_rotation(Y), THIS->get_rotation(Z)); %}; %code%{ RETVAL = new Vec3d(THIS->get_rotation(X), THIS->get_rotation(Y), THIS->get_rotation(Z)); %};
@ -322,25 +321,6 @@ ModelMaterial::attributes()
THIS->set_offset(X, (*offset)(0)); THIS->set_offset(X, (*offset)(0));
THIS->set_offset(Y, (*offset)(1)); THIS->set_offset(Y, (*offset)(1));
%}; %};
#else
double rotation()
%code%{ RETVAL = THIS->rotation; %};
double scaling_factor()
%code%{ RETVAL = THIS->scaling_factor; %};
Ref<Vec2d> offset()
%code%{ RETVAL = &THIS->offset; %};
void set_rotation(double val)
%code%{ THIS->rotation = val; THIS->get_object()->invalidate_bounding_box(); %};
void set_scaling_factor(double val)
%code%{ THIS->scaling_factor = val; THIS->get_object()->invalidate_bounding_box(); %};
void set_offset(Vec2d *offset)
%code%{ THIS->offset = *offset; %};
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const; void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
void transform_polygon(Polygon* polygon) const; void transform_polygon(Polygon* polygon) const;