1st installment of ModelInstance 3D scale components
This commit is contained in:
parent
e3d44b07fe
commit
0e1843a871
@ -144,6 +144,40 @@ sub new {
|
|||||||
$self->schedule_background_process;
|
$self->schedule_background_process;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# callback to react to gizmo scale
|
||||||
|
my $on_gizmo_scale_3D = sub {
|
||||||
|
my ($scale_x, $scale_y, $scale_z) = @_;
|
||||||
|
|
||||||
|
my ($obj_idx, $object) = $self->selected_object;
|
||||||
|
return if !defined $obj_idx;
|
||||||
|
|
||||||
|
my $model_object = $self->{model}->objects->[$obj_idx];
|
||||||
|
my $model_instance = $model_object->instances->[0];
|
||||||
|
|
||||||
|
$self->stop_background_process;
|
||||||
|
|
||||||
|
#FIXME Scale the layer height profile?
|
||||||
|
# my $variation = $scale / $model_instance->scaling_factor;
|
||||||
|
# foreach my $range (@{ $model_object->layer_height_ranges }) {
|
||||||
|
# $range->[0] *= $variation;
|
||||||
|
# $range->[1] *= $variation;
|
||||||
|
# }
|
||||||
|
|
||||||
|
my $scale = Slic3r::Pointf3->new($scale_x, $scale_y, $scale_z);
|
||||||
|
foreach my $inst (@{ $model_object->instances }) {
|
||||||
|
$inst->set_scaling_factors($scale);
|
||||||
|
}
|
||||||
|
Slic3r::GUI::_3DScene::update_gizmos_data($self->{canvas3D}) if ($self->{canvas3D});
|
||||||
|
|
||||||
|
#update print and start background processing
|
||||||
|
$self->{print}->add_model_object($model_object, $obj_idx);
|
||||||
|
|
||||||
|
$self->selection_changed(1); # refresh info (size, volume etc.)
|
||||||
|
$self->update;
|
||||||
|
$self->schedule_background_process;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
# callback to react to gizmo rotate
|
# callback to react to gizmo rotate
|
||||||
my $on_gizmo_rotate = sub {
|
my $on_gizmo_rotate = sub {
|
||||||
my ($angle) = @_;
|
my ($angle) = @_;
|
||||||
@ -223,6 +257,21 @@ sub new {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# callback to update object's geometry info while using gizmos
|
||||||
|
my $on_update_geometry_3D_info = sub {
|
||||||
|
my ($size_x, $size_y, $size_z, $scale_x, $scale_y, $scale_z) = @_;
|
||||||
|
|
||||||
|
my ($obj_idx, $object) = $self->selected_object;
|
||||||
|
|
||||||
|
if ((defined $obj_idx) && ($self->{object_info_size})) { # have we already loaded the info pane?
|
||||||
|
$self->{object_info_size}->SetLabel(sprintf("%.2f x %.2f x %.2f", $size_x, $size_y, $size_z));
|
||||||
|
my $model_object = $self->{model}->objects->[$obj_idx];
|
||||||
|
if (my $stats = $model_object->mesh_stats) {
|
||||||
|
$self->{object_info_volume}->SetLabel(sprintf('%.2f', $stats->{volume} * $scale_x * $scale_y * $scale_z));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
# callbacks for toolbar
|
# callbacks for toolbar
|
||||||
my $on_action_add = sub {
|
my $on_action_add = sub {
|
||||||
$self->add;
|
$self->add;
|
||||||
@ -312,11 +361,13 @@ sub new {
|
|||||||
Slic3r::GUI::_3DScene::register_on_instance_moved_callback($self->{canvas3D}, $on_instances_moved);
|
Slic3r::GUI::_3DScene::register_on_instance_moved_callback($self->{canvas3D}, $on_instances_moved);
|
||||||
Slic3r::GUI::_3DScene::register_on_enable_action_buttons_callback($self->{canvas3D}, $enable_action_buttons);
|
Slic3r::GUI::_3DScene::register_on_enable_action_buttons_callback($self->{canvas3D}, $enable_action_buttons);
|
||||||
Slic3r::GUI::_3DScene::register_on_gizmo_scale_uniformly_callback($self->{canvas3D}, $on_gizmo_scale_uniformly);
|
Slic3r::GUI::_3DScene::register_on_gizmo_scale_uniformly_callback($self->{canvas3D}, $on_gizmo_scale_uniformly);
|
||||||
|
Slic3r::GUI::_3DScene::register_on_gizmo_scale_3D_callback($self->{canvas3D}, $on_gizmo_scale_3D);
|
||||||
Slic3r::GUI::_3DScene::register_on_gizmo_rotate_callback($self->{canvas3D}, $on_gizmo_rotate);
|
Slic3r::GUI::_3DScene::register_on_gizmo_rotate_callback($self->{canvas3D}, $on_gizmo_rotate);
|
||||||
Slic3r::GUI::_3DScene::register_on_gizmo_rotate_3D_callback($self->{canvas3D}, $on_gizmo_rotate_3D);
|
Slic3r::GUI::_3DScene::register_on_gizmo_rotate_3D_callback($self->{canvas3D}, $on_gizmo_rotate_3D);
|
||||||
Slic3r::GUI::_3DScene::register_on_gizmo_flatten_callback($self->{canvas3D}, $on_gizmo_flatten);
|
Slic3r::GUI::_3DScene::register_on_gizmo_flatten_callback($self->{canvas3D}, $on_gizmo_flatten);
|
||||||
Slic3r::GUI::_3DScene::register_on_gizmo_flatten_3D_callback($self->{canvas3D}, $on_gizmo_flatten_3D);
|
Slic3r::GUI::_3DScene::register_on_gizmo_flatten_3D_callback($self->{canvas3D}, $on_gizmo_flatten_3D);
|
||||||
Slic3r::GUI::_3DScene::register_on_update_geometry_info_callback($self->{canvas3D}, $on_update_geometry_info);
|
Slic3r::GUI::_3DScene::register_on_update_geometry_info_callback($self->{canvas3D}, $on_update_geometry_info);
|
||||||
|
Slic3r::GUI::_3DScene::register_on_update_geometry_3D_info_callback($self->{canvas3D}, $on_update_geometry_3D_info);
|
||||||
Slic3r::GUI::_3DScene::register_action_add_callback($self->{canvas3D}, $on_action_add);
|
Slic3r::GUI::_3DScene::register_action_add_callback($self->{canvas3D}, $on_action_add);
|
||||||
Slic3r::GUI::_3DScene::register_action_delete_callback($self->{canvas3D}, $on_action_delete);
|
Slic3r::GUI::_3DScene::register_action_delete_callback($self->{canvas3D}, $on_action_delete);
|
||||||
Slic3r::GUI::_3DScene::register_action_deleteall_callback($self->{canvas3D}, $on_action_deleteall);
|
Slic3r::GUI::_3DScene::register_action_deleteall_callback($self->{canvas3D}, $on_action_deleteall);
|
||||||
|
@ -124,7 +124,7 @@ sub add_instance {
|
|||||||
|
|
||||||
$new_instance->set_rotations($args{rotation})
|
$new_instance->set_rotations($args{rotation})
|
||||||
if defined $args{rotation};
|
if defined $args{rotation};
|
||||||
$new_instance->set_scaling_factor($args{scaling_factor})
|
$new_instance->set_scaling_factors($args{scaling_factor})
|
||||||
if defined $args{scaling_factor};
|
if defined $args{scaling_factor};
|
||||||
$new_instance->set_offset($args{offset})
|
$new_instance->set_offset($args{offset})
|
||||||
if defined $args{offset};
|
if defined $args{offset};
|
||||||
|
@ -149,6 +149,26 @@ void PerlCallback::call(double a, double b, double c, double d) const
|
|||||||
LEAVE;
|
LEAVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PerlCallback::call(double a, double b, double c, double d, double e, double f) const
|
||||||
|
{
|
||||||
|
if (!m_callback)
|
||||||
|
return;
|
||||||
|
dSP;
|
||||||
|
ENTER;
|
||||||
|
SAVETMPS;
|
||||||
|
PUSHMARK(SP);
|
||||||
|
XPUSHs(sv_2mortal(newSVnv(a)));
|
||||||
|
XPUSHs(sv_2mortal(newSVnv(b)));
|
||||||
|
XPUSHs(sv_2mortal(newSVnv(c)));
|
||||||
|
XPUSHs(sv_2mortal(newSVnv(d)));
|
||||||
|
XPUSHs(sv_2mortal(newSVnv(e)));
|
||||||
|
XPUSHs(sv_2mortal(newSVnv(f)));
|
||||||
|
PUTBACK;
|
||||||
|
perl_call_sv(SvRV((SV*)m_callback), G_DISCARD);
|
||||||
|
FREETMPS;
|
||||||
|
LEAVE;
|
||||||
|
}
|
||||||
|
|
||||||
void PerlCallback::call(bool b) const
|
void PerlCallback::call(bool b) const
|
||||||
{
|
{
|
||||||
call(b ? 1 : 0);
|
call(b ? 1 : 0);
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
void call(double a, double b) const;
|
void call(double a, double b) const;
|
||||||
void call(double a, double b, double c) const;
|
void call(double a, double b, double c) const;
|
||||||
void call(double a, double b, double c, double d) const;
|
void call(double a, double b, double c, double d) const;
|
||||||
|
void call(double a, double b, double c, double d, double e, double f) const;
|
||||||
void call(bool b) const;
|
void call(bool b) const;
|
||||||
private:
|
private:
|
||||||
void *m_callback;
|
void *m_callback;
|
||||||
|
@ -1270,9 +1270,11 @@ namespace Slic3r {
|
|||||||
if ((sx == 0.0) || (sy == 0.0) || (sz == 0.0))
|
if ((sx == 0.0) || (sy == 0.0) || (sz == 0.0))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
// non-uniform scale value, return
|
// non-uniform scale value, return
|
||||||
if ((std::abs(sx - sy) > 0.00001) || (std::abs(sx - sz) > 0.00001))
|
if ((std::abs(sx - sy) > 0.00001) || (std::abs(sx - sz) > 0.00001))
|
||||||
return;
|
return;
|
||||||
|
#endif // !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
double inv_sx = 1.0 / sx;
|
double inv_sx = 1.0 / sx;
|
||||||
double inv_sy = 1.0 / sy;
|
double inv_sy = 1.0 / sy;
|
||||||
@ -1303,7 +1305,11 @@ namespace Slic3r {
|
|||||||
instance.offset(0) = offset_x;
|
instance.offset(0) = offset_x;
|
||||||
instance.offset(1) = offset_y;
|
instance.offset(1) = offset_y;
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
instance.set_scaling_factor(Vec3d(sx, sy, sz));
|
||||||
|
#else
|
||||||
instance.scaling_factor = sx;
|
instance.scaling_factor = sx;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
instance.set_rotation(rotation);
|
instance.set_rotation(rotation);
|
||||||
#else
|
#else
|
||||||
|
@ -31,8 +31,14 @@
|
|||||||
// 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_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
// 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
|
||||||
|
#else
|
||||||
|
// 2 : Added z component of offset
|
||||||
|
// Added x and y components of rotation
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#else
|
#else
|
||||||
// 2 : Added z component of offset.
|
// 2 : Added z component of offset.
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
@ -138,13 +144,22 @@ struct AMFParserContext
|
|||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
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_SCALE
|
||||||
|
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_SCALE
|
||||||
NODE_TYPE_METADATA, // anywhere under amf/*/metadata
|
NODE_TYPE_METADATA, // anywhere under amf/*/metadata
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Instance {
|
struct Instance {
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
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), deltaz_set(false), rx_set(false), ry_set(false), rz_set(false), scale_set(false) {}
|
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rx_set(false), ry_set(false), rz_set(false), scale_set(false) {}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#else
|
#else
|
||||||
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rz_set(false), scale_set(false) {}
|
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rz_set(false), scale_set(false) {}
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
@ -173,9 +188,19 @@ struct AMFParserContext
|
|||||||
// Rotation around the Z axis.
|
// Rotation around the Z axis.
|
||||||
float rz;
|
float rz;
|
||||||
bool rz_set;
|
bool rz_set;
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
// Scaling factors
|
||||||
|
float scalex;
|
||||||
|
bool scalex_set;
|
||||||
|
float scaley;
|
||||||
|
bool scaley_set;
|
||||||
|
float scalez;
|
||||||
|
bool scalez_set;
|
||||||
|
#else
|
||||||
// Scaling factor
|
// Scaling factor
|
||||||
float scale;
|
float scale;
|
||||||
bool scale_set;
|
bool scale_set;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Object {
|
struct Object {
|
||||||
@ -304,6 +329,14 @@ void AMFParserContext::startElement(const char *name, const char **atts)
|
|||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
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_SCALE
|
||||||
|
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_SCALE
|
||||||
else if (strcmp(name, "scale") == 0)
|
else if (strcmp(name, "scale") == 0)
|
||||||
node_type_new = NODE_TYPE_SCALE;
|
node_type_new = NODE_TYPE_SCALE;
|
||||||
}
|
}
|
||||||
@ -371,7 +404,14 @@ void AMFParserContext::characters(const XML_Char *s, int len)
|
|||||||
m_path.back() == NODE_TYPE_RY ||
|
m_path.back() == NODE_TYPE_RY ||
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
m_path.back() == NODE_TYPE_RZ ||
|
m_path.back() == NODE_TYPE_RZ ||
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m_path.back() == NODE_TYPE_SCALEX ||
|
||||||
|
m_path.back() == NODE_TYPE_SCALEY ||
|
||||||
|
m_path.back() == NODE_TYPE_SCALEZ ||
|
||||||
m_path.back() == NODE_TYPE_SCALE)
|
m_path.back() == NODE_TYPE_SCALE)
|
||||||
|
#else
|
||||||
|
m_path.back() == NODE_TYPE_SCALE)
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#else
|
#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)
|
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_OFFSET
|
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
@ -444,10 +484,39 @@ 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_SCALE
|
||||||
|
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 = float(atof(m_value[0].c_str()));
|
||||||
m_instance->scale_set = true;
|
m_instance->scale_set = true;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
m_value[0].clear();
|
m_value[0].clear();
|
||||||
break;
|
break;
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
case NODE_TYPE_SCALEX:
|
||||||
|
assert(m_instance);
|
||||||
|
m_instance->scalex = float(atof(m_value[0].c_str()));
|
||||||
|
m_instance->scalex_set = true;
|
||||||
|
m_value[0].clear();
|
||||||
|
break;
|
||||||
|
case NODE_TYPE_SCALEY:
|
||||||
|
assert(m_instance);
|
||||||
|
m_instance->scaley = float(atof(m_value[0].c_str()));
|
||||||
|
m_instance->scaley_set = true;
|
||||||
|
m_value[0].clear();
|
||||||
|
break;
|
||||||
|
case NODE_TYPE_SCALEZ:
|
||||||
|
assert(m_instance);
|
||||||
|
m_instance->scalez = float(atof(m_value[0].c_str()));
|
||||||
|
m_instance->scalez_set = true;
|
||||||
|
m_value[0].clear();
|
||||||
|
break;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
// Object vertices:
|
// Object vertices:
|
||||||
case NODE_TYPE_VERTEX:
|
case NODE_TYPE_VERTEX:
|
||||||
@ -596,7 +665,11 @@ void AMFParserContext::endDocument()
|
|||||||
#else
|
#else
|
||||||
mi->rotation = instance.rz_set ? instance.rz : 0.f;
|
mi->rotation = instance.rz_set ? instance.rz : 0.f;
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
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->scaling_factor = instance.scale_set ? instance.scale : 1.f;
|
mi->scaling_factor = instance.scale_set ? instance.scale : 1.f;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -904,7 +977,13 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
|
|||||||
" <ry>%lf</ry>\n"
|
" <ry>%lf</ry>\n"
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
" <rz>%lf</rz>\n"
|
" <rz>%lf</rz>\n"
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
" <scalex>%lf</scalex>\n"
|
||||||
|
" <scaley>%lf</scaley>\n"
|
||||||
|
" <scalez>%lf</scalez>\n"
|
||||||
|
#else
|
||||||
" <scale>%lf</scale>\n"
|
" <scale>%lf</scale>\n"
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
" </instance>\n",
|
" </instance>\n",
|
||||||
object_id,
|
object_id,
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
@ -922,7 +1001,13 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
|
|||||||
#else
|
#else
|
||||||
instance->rotation,
|
instance->rotation,
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
instance->get_scaling_factor(X),
|
||||||
|
instance->get_scaling_factor(Y),
|
||||||
|
instance->get_scaling_factor(Z));
|
||||||
|
#else
|
||||||
instance->scaling_factor);
|
instance->scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
//FIXME missing instance->scaling_factor
|
//FIXME missing instance->scaling_factor
|
||||||
instances.append(buf);
|
instances.append(buf);
|
||||||
|
@ -169,7 +169,11 @@ bool load_prus(const char *path, Model *model)
|
|||||||
#else
|
#else
|
||||||
double instance_rotation = 0.;
|
double instance_rotation = 0.;
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
Vec3d instance_scaling_factor = Vec3d::Ones();
|
||||||
|
#else
|
||||||
double instance_scaling_factor = 1.f;
|
double instance_scaling_factor = 1.f;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
Vec3d instance_offset = Vec3d::Zero();
|
Vec3d instance_offset = Vec3d::Zero();
|
||||||
#else
|
#else
|
||||||
@ -197,10 +201,14 @@ bool load_prus(const char *path, Model *model)
|
|||||||
"[%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_SCALE
|
||||||
|
instance_scaling_factor = Vec3d((double)scale[0], (double)scale[1], (double)scale[2]);
|
||||||
|
#else
|
||||||
if (scale[0] == scale[1] && scale[1] == scale[2]) {
|
if (scale[0] == scale[1] && scale[1] == scale[2]) {
|
||||||
instance_scaling_factor = scale[0];
|
instance_scaling_factor = scale[0];
|
||||||
scale[0] = scale[1] = scale[2] = 1.;
|
scale[0] = scale[1] = scale[2] = 1.;
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
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
|
#else
|
||||||
@ -225,7 +233,12 @@ bool load_prus(const char *path, Model *model)
|
|||||||
instance_offset(0) = position[0] - zero[0];
|
instance_offset(0) = position[0] - zero[0];
|
||||||
instance_offset(1) = position[1] - zero[1];
|
instance_offset(1) = position[1] - zero[1];
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
// CHECK_ME -> Is the following correct ?
|
||||||
|
trafo[2][3] = position[2] / instance_scaling_factor(2);
|
||||||
|
#else
|
||||||
trafo[2][3] = position[2] / instance_scaling_factor;
|
trafo[2][3] = position[2] / instance_scaling_factor;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
trafo_set = true;
|
trafo_set = true;
|
||||||
}
|
}
|
||||||
const char *group_tag = "<group>";
|
const char *group_tag = "<group>";
|
||||||
@ -379,7 +392,11 @@ bool load_prus(const char *path, Model *model)
|
|||||||
#else
|
#else
|
||||||
instance->rotation = instance_rotation;
|
instance->rotation = instance_rotation;
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
instance->set_scaling_factor(instance_scaling_factor);
|
||||||
|
#else
|
||||||
instance->scaling_factor = instance_scaling_factor;
|
instance->scaling_factor = instance_scaling_factor;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
instance->set_offset(instance_offset);
|
instance->set_offset(instance_offset);
|
||||||
#else
|
#else
|
||||||
|
@ -1090,11 +1090,23 @@ 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_SCALE
|
||||||
|
// Scale the bounding box along the three axes.
|
||||||
|
for (unsigned int i = 0; i < 3; ++i)
|
||||||
|
{
|
||||||
|
if (std::abs(this->m_scaling_factor(i) - 1.0) > EPSILON)
|
||||||
|
{
|
||||||
|
bbox.min(i) *= this->m_scaling_factor(i);
|
||||||
|
bbox.max(i) *= this->m_scaling_factor(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
// Scale the bounding box uniformly.
|
// Scale the bounding box uniformly.
|
||||||
if (std::abs(this->scaling_factor - 1.) > EPSILON) {
|
if (std::abs(this->scaling_factor - 1.) > EPSILON) {
|
||||||
bbox.min *= this->scaling_factor;
|
bbox.min *= this->scaling_factor;
|
||||||
bbox.max *= this->scaling_factor;
|
bbox.max *= this->scaling_factor;
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
// Translate the bounding box.
|
// Translate the bounding box.
|
||||||
if (! dont_translate) {
|
if (! dont_translate) {
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
@ -1127,7 +1139,12 @@ void ModelInstance::transform_polygon(Polygon* polygon) const
|
|||||||
#else
|
#else
|
||||||
polygon->rotate(this->rotation); // rotate around polygon origin
|
polygon->rotate(this->rotation); // rotate around polygon origin
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
// CHECK_ME -> Is the following correct ?
|
||||||
|
polygon->scale(this->m_scaling_factor(0), this->m_scaling_factor(1)); // scale around polygon origin
|
||||||
|
#else
|
||||||
polygon->scale(this->scaling_factor); // scale around polygon origin
|
polygon->scale(this->scaling_factor); // scale around polygon origin
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
@ -1153,7 +1170,11 @@ Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, b
|
|||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
|
||||||
if (!dont_scale)
|
if (!dont_scale)
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m.scale(m_scaling_factor);
|
||||||
|
#else
|
||||||
m.scale(scaling_factor);
|
m.scale(scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
@ -249,6 +249,9 @@ private:
|
|||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
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
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
Vec3d m_scaling_factor; // Scaling factors along the three axes
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
public:
|
public:
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
@ -256,7 +259,9 @@ public:
|
|||||||
#if !ENABLE_MODELINSTANCE_3D_ROTATION
|
#if !ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
double rotation; // Rotation around the Z axis, in radians around mesh center point
|
double rotation; // Rotation around the Z axis, in radians around mesh center point
|
||||||
#endif // !ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // !ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
double scaling_factor;
|
double scaling_factor;
|
||||||
|
#endif // !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if !ENABLE_MODELINSTANCE_3D_OFFSET
|
#if !ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
Vec2d offset; // in unscaled coordinates
|
Vec2d offset; // in unscaled coordinates
|
||||||
#endif // !ENABLE_MODELINSTANCE_3D_OFFSET
|
#endif // !ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
@ -282,6 +287,14 @@ public:
|
|||||||
void set_rotation(Axis axis, double rotation);
|
void set_rotation(Axis axis, double rotation);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
Vec3d get_scaling_factor() const { return m_scaling_factor; }
|
||||||
|
double get_scaling_factor(Axis axis) const { return m_scaling_factor(axis); }
|
||||||
|
|
||||||
|
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; }
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
// 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;
|
||||||
// Calculate a bounding box of a transformed mesh. To be called on an external mesh.
|
// Calculate a bounding box of a transformed mesh. To be called on an external mesh.
|
||||||
@ -303,9 +316,15 @@ private:
|
|||||||
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
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) :
|
||||||
|
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) : m_rotation(Vec3d::Zero()), scaling_factor(1), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {}
|
ModelInstance(ModelObject *object) : m_rotation(Vec3d::Zero()), scaling_factor(1), 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), scaling_factor(other.scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {}
|
m_rotation(other.m_rotation), scaling_factor(other.scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#else
|
#else
|
||||||
ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {}
|
ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {}
|
||||||
ModelInstance(ModelObject *object, const ModelInstance &other) :
|
ModelInstance(ModelObject *object, const ModelInstance &other) :
|
||||||
|
@ -29,7 +29,12 @@ 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_SCALE
|
||||||
|
// CHECK_ME -> Is the following correct ?
|
||||||
|
tmpmesh.scale(objinst->get_scaling_factor());
|
||||||
|
#else
|
||||||
tmpmesh.scale(objinst->scaling_factor);
|
tmpmesh.scale(objinst->scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
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) {
|
||||||
@ -87,7 +92,11 @@ 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_SCALE
|
||||||
|
tmpmesh.scale(objinst->get_scaling_factor());
|
||||||
|
#else
|
||||||
tmpmesh.scale(objinst->scaling_factor);
|
tmpmesh.scale(objinst->scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
objinst->transform_mesh(&tmpmesh);
|
objinst->transform_mesh(&tmpmesh);
|
||||||
ExPolygons expolys = tmpmesh.horizontal_projection();
|
ExPolygons expolys = tmpmesh.horizontal_projection();
|
||||||
svg.draw(expolys);
|
svg.draw(expolys);
|
||||||
@ -513,7 +522,12 @@ ShapeData2D projectModelFromTop(const Slic3r::Model &model) {
|
|||||||
Slic3r::TriangleMesh tmpmesh = rmesh;
|
Slic3r::TriangleMesh tmpmesh = rmesh;
|
||||||
ClipperLib::PolygonImpl pn;
|
ClipperLib::PolygonImpl pn;
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
// CHECK_ME -> is the following correct ?
|
||||||
|
tmpmesh.scale(objinst->get_scaling_factor());
|
||||||
|
#else
|
||||||
tmpmesh.scale(objinst->scaling_factor);
|
tmpmesh.scale(objinst->scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
// TODO export the exact 2D projection
|
// TODO export the exact 2D projection
|
||||||
auto p = tmpmesh.convex_hull();
|
auto p = tmpmesh.convex_hull();
|
||||||
|
@ -14,6 +14,17 @@ void MultiPoint::scale(double factor)
|
|||||||
pt *= factor;
|
pt *= factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void MultiPoint::scale(double factor_x, double factor_y)
|
||||||
|
{
|
||||||
|
for (Point &pt : points)
|
||||||
|
{
|
||||||
|
pt(0) *= factor_x;
|
||||||
|
pt(1) *= factor_y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
void MultiPoint::translate(double x, double y)
|
void MultiPoint::translate(double x, double y)
|
||||||
{
|
{
|
||||||
Vector v(x, y);
|
Vector v(x, y);
|
||||||
|
@ -26,6 +26,9 @@ 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_SCALE
|
||||||
|
void scale(double factor_x, double factor_y);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
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)); }
|
||||||
|
@ -431,7 +431,14 @@ 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();
|
||||||
v_scale.push_back(boost::lexical_cast<std::string>(mobj.instances[0]->scaling_factor*100) + "%");
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
// CHECK_ME -> Is the following correct ?
|
||||||
|
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) +
|
||||||
|
"% 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_SCALE
|
||||||
if (input_file.empty())
|
if (input_file.empty())
|
||||||
input_file = mobj.input_file;
|
input_file = mobj.input_file;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
#define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0)
|
#define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0)
|
||||||
// Add x and y rotation components to model instances' offset
|
// Add x and y rotation components to model instances' offset
|
||||||
#define ENABLE_MODELINSTANCE_3D_ROTATION (1 && ENABLE_MODELINSTANCE_3D_OFFSET)
|
#define ENABLE_MODELINSTANCE_3D_ROTATION (1 && ENABLE_MODELINSTANCE_3D_OFFSET)
|
||||||
|
// Add scaling factors for all the three axes to model instances
|
||||||
|
#define ENABLE_MODELINSTANCE_3D_SCALE (1 && ENABLE_MODELINSTANCE_3D_ROTATION)
|
||||||
#endif // _technologies_h_
|
#endif // _technologies_h_
|
||||||
|
|
||||||
|
|
||||||
|
@ -201,7 +201,11 @@ GLVolume::GLVolume(float r, float g, float b, float a)
|
|||||||
#else
|
#else
|
||||||
, m_rotation(0.0)
|
, m_rotation(0.0)
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
, m_scaling_factor(Vec3d::Ones())
|
||||||
|
#else
|
||||||
, m_scaling_factor(1.0)
|
, m_scaling_factor(1.0)
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
, 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)
|
||||||
@ -309,6 +313,18 @@ void GLVolume::set_offset(const Vec3d& offset)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void GLVolume::set_scaling_factor(const Vec3d& scaling_factor)
|
||||||
|
{
|
||||||
|
if (m_scaling_factor != scaling_factor)
|
||||||
|
{
|
||||||
|
m_scaling_factor = scaling_factor;
|
||||||
|
m_world_matrix_dirty = true;
|
||||||
|
m_transformed_bounding_box_dirty = true;
|
||||||
|
m_transformed_convex_hull_bounding_box_dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
void GLVolume::set_scaling_factor(double factor)
|
void GLVolume::set_scaling_factor(double factor)
|
||||||
{
|
{
|
||||||
if (m_scaling_factor != factor)
|
if (m_scaling_factor != factor)
|
||||||
@ -319,6 +335,7 @@ void GLVolume::set_scaling_factor(double factor)
|
|||||||
m_transformed_convex_hull_bounding_box_dirty = true;
|
m_transformed_convex_hull_bounding_box_dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
|
void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
|
||||||
{
|
{
|
||||||
@ -356,7 +373,11 @@ const Transform3f& GLVolume::world_matrix() const
|
|||||||
#else
|
#else
|
||||||
m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ()));
|
m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ()));
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m_world_matrix.scale(m_scaling_factor.cast<float>());
|
||||||
|
#else
|
||||||
m_world_matrix.scale((float)m_scaling_factor);
|
m_world_matrix.scale((float)m_scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
m_world_matrix_dirty = false;
|
m_world_matrix_dirty = false;
|
||||||
}
|
}
|
||||||
return m_world_matrix;
|
return m_world_matrix;
|
||||||
@ -438,7 +459,11 @@ void GLVolume::render() const
|
|||||||
#else
|
#else
|
||||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
::glScaled(m_scaling_factor(0), m_scaling_factor(1), m_scaling_factor(2));
|
||||||
|
#else
|
||||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
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
|
||||||
@ -570,7 +595,11 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
|
|||||||
#else
|
#else
|
||||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
::glScaled(m_scaling_factor(0), m_scaling_factor(1), m_scaling_factor(2));
|
||||||
|
#else
|
||||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
if (n_triangles > 0)
|
if (n_triangles > 0)
|
||||||
{
|
{
|
||||||
@ -621,7 +650,11 @@ void GLVolume::render_legacy() const
|
|||||||
#else
|
#else
|
||||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
::glScaled(m_scaling_factor(0), m_scaling_factor(1), m_scaling_factor(2));
|
||||||
|
#else
|
||||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
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);
|
||||||
@ -749,7 +782,11 @@ std::vector<int> GLVolumeCollection::load_object(
|
|||||||
#else
|
#else
|
||||||
v.set_rotation(instance->rotation);
|
v.set_rotation(instance->rotation);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
v.set_scaling_factor(instance->get_scaling_factor());
|
||||||
|
#else
|
||||||
v.set_scaling_factor(instance->scaling_factor);
|
v.set_scaling_factor(instance->scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2112,7 +2149,16 @@ void _3DScene::register_on_enable_action_buttons_callback(wxGLCanvas* canvas, vo
|
|||||||
|
|
||||||
void _3DScene::register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback)
|
void _3DScene::register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback)
|
||||||
{
|
{
|
||||||
|
#if !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
s_canvas_mgr.register_on_gizmo_scale_uniformly_callback(canvas, callback);
|
s_canvas_mgr.register_on_gizmo_scale_uniformly_callback(canvas, callback);
|
||||||
|
#endif // !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
}
|
||||||
|
|
||||||
|
void _3DScene::register_on_gizmo_scale_3D_callback(wxGLCanvas* canvas, void* callback)
|
||||||
|
{
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
s_canvas_mgr.register_on_gizmo_scale_3D_callback(canvas, callback);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
void _3DScene::register_on_gizmo_rotate_callback(wxGLCanvas* canvas, void* callback)
|
void _3DScene::register_on_gizmo_rotate_callback(wxGLCanvas* canvas, void* callback)
|
||||||
@ -2145,7 +2191,16 @@ void _3DScene::register_on_gizmo_flatten_3D_callback(wxGLCanvas* canvas, void* c
|
|||||||
|
|
||||||
void _3DScene::register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback)
|
void _3DScene::register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback)
|
||||||
{
|
{
|
||||||
|
#if !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
s_canvas_mgr.register_on_update_geometry_info_callback(canvas, callback);
|
s_canvas_mgr.register_on_update_geometry_info_callback(canvas, callback);
|
||||||
|
#endif // !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
}
|
||||||
|
|
||||||
|
void _3DScene::register_on_update_geometry_3D_info_callback(wxGLCanvas* canvas, void* callback)
|
||||||
|
{
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
s_canvas_mgr.register_on_update_geometry_3D_info_callback(canvas, callback);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
void _3DScene::register_action_add_callback(wxGLCanvas* canvas, void* callback)
|
void _3DScene::register_action_add_callback(wxGLCanvas* canvas, void* callback)
|
||||||
|
@ -263,8 +263,13 @@ private:
|
|||||||
// Rotation around Z axis of the volume to be rendered.
|
// Rotation around Z axis of the volume to be rendered.
|
||||||
double m_rotation;
|
double m_rotation;
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
// Scale factor along the three axes of the volume to be rendered.
|
||||||
|
Vec3d m_scaling_factor;
|
||||||
|
#else
|
||||||
// Scale factor of the volume to be rendered.
|
// Scale factor of the volume to be rendered.
|
||||||
double m_scaling_factor;
|
double m_scaling_factor;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
// 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.
|
||||||
@ -343,7 +348,11 @@ public:
|
|||||||
const Vec3d& get_offset() const;
|
const Vec3d& get_offset() const;
|
||||||
void set_offset(const Vec3d& offset);
|
void set_offset(const Vec3d& offset);
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void set_scaling_factor(const Vec3d& scaling_factor);
|
||||||
|
#else
|
||||||
void set_scaling_factor(double factor);
|
void set_scaling_factor(double factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
void set_convex_hull(const TriangleMesh& convex_hull);
|
void set_convex_hull(const TriangleMesh& convex_hull);
|
||||||
|
|
||||||
@ -567,11 +576,13 @@ public:
|
|||||||
static void register_on_wipe_tower_moved_callback(wxGLCanvas* canvas, void* callback);
|
static void register_on_wipe_tower_moved_callback(wxGLCanvas* canvas, void* callback);
|
||||||
static void register_on_enable_action_buttons_callback(wxGLCanvas* canvas, void* callback);
|
static void register_on_enable_action_buttons_callback(wxGLCanvas* canvas, void* callback);
|
||||||
static void register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback);
|
static void register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
static void register_on_gizmo_scale_3D_callback(wxGLCanvas* canvas, void* callback);
|
||||||
static void register_on_gizmo_rotate_callback(wxGLCanvas* canvas, void* callback);
|
static void register_on_gizmo_rotate_callback(wxGLCanvas* canvas, void* callback);
|
||||||
static void register_on_gizmo_rotate_3D_callback(wxGLCanvas* canvas, void* callback);
|
static void register_on_gizmo_rotate_3D_callback(wxGLCanvas* canvas, void* callback);
|
||||||
static void register_on_gizmo_flatten_callback(wxGLCanvas* canvas, void* callback);
|
static void register_on_gizmo_flatten_callback(wxGLCanvas* canvas, void* callback);
|
||||||
static void register_on_gizmo_flatten_3D_callback(wxGLCanvas* canvas, void* callback);
|
static void register_on_gizmo_flatten_3D_callback(wxGLCanvas* canvas, void* callback);
|
||||||
static void register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback);
|
static void register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
static void register_on_update_geometry_3D_info_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
|
||||||
static void register_action_add_callback(wxGLCanvas* canvas, void* callback);
|
static void register_action_add_callback(wxGLCanvas* canvas, void* callback);
|
||||||
static void register_action_delete_callback(wxGLCanvas* canvas, void* callback);
|
static void register_action_delete_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
@ -1159,6 +1159,7 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
|
|||||||
if (!gizmo->init())
|
if (!gizmo->init())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
#if !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
// temporary disable x grabbers
|
// temporary disable x grabbers
|
||||||
gizmo->disable_grabber(0);
|
gizmo->disable_grabber(0);
|
||||||
gizmo->disable_grabber(1);
|
gizmo->disable_grabber(1);
|
||||||
@ -1168,6 +1169,7 @@ bool GLCanvas3D::Gizmos::init(GLCanvas3D& parent)
|
|||||||
// temporary disable z grabbers
|
// temporary disable z grabbers
|
||||||
gizmo->disable_grabber(4);
|
gizmo->disable_grabber(4);
|
||||||
gizmo->disable_grabber(5);
|
gizmo->disable_grabber(5);
|
||||||
|
#endif // !ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
m_gizmos.insert(GizmosMap::value_type(Scale, gizmo));
|
m_gizmos.insert(GizmosMap::value_type(Scale, gizmo));
|
||||||
|
|
||||||
@ -1419,6 +1421,26 @@ void GLCanvas3D::Gizmos::set_position(const Vec3d& position)
|
|||||||
reinterpret_cast<GLGizmoMove3D*>(it->second)->set_position(position);
|
reinterpret_cast<GLGizmoMove3D*>(it->second)->set_position(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
Vec3d GLCanvas3D::Gizmos::get_scale() const
|
||||||
|
{
|
||||||
|
if (!m_enabled)
|
||||||
|
return Vec3d::Ones();
|
||||||
|
|
||||||
|
GizmosMap::const_iterator it = m_gizmos.find(Scale);
|
||||||
|
return (it != m_gizmos.end()) ? reinterpret_cast<GLGizmoScale3D*>(it->second)->get_scale() : Vec3d::Ones();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GLCanvas3D::Gizmos::set_scale(const Vec3d& 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);
|
||||||
|
}
|
||||||
|
#else
|
||||||
float GLCanvas3D::Gizmos::get_scale() const
|
float GLCanvas3D::Gizmos::get_scale() const
|
||||||
{
|
{
|
||||||
if (!m_enabled)
|
if (!m_enabled)
|
||||||
@ -1437,6 +1459,7 @@ void GLCanvas3D::Gizmos::set_scale(float scale)
|
|||||||
if (it != m_gizmos.end())
|
if (it != m_gizmos.end())
|
||||||
reinterpret_cast<GLGizmoScale3D*>(it->second)->set_scale(scale);
|
reinterpret_cast<GLGizmoScale3D*>(it->second)->set_scale(scale);
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
Vec3d GLCanvas3D::Gizmos::get_rotation() const
|
Vec3d GLCanvas3D::Gizmos::get_rotation() const
|
||||||
@ -2431,7 +2454,11 @@ void GLCanvas3D::update_gizmos_data()
|
|||||||
#else
|
#else
|
||||||
m_gizmos.set_position(Vec3d(model_instance->offset(0), model_instance->offset(1), 0.0));
|
m_gizmos.set_position(Vec3d(model_instance->offset(0), model_instance->offset(1), 0.0));
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
#endif // ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m_gizmos.set_scale(model_instance->get_scaling_factor());
|
||||||
|
#else
|
||||||
m_gizmos.set_scale(model_instance->scaling_factor);
|
m_gizmos.set_scale(model_instance->scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
m_gizmos.set_rotation(model_instance->get_rotation());
|
m_gizmos.set_rotation(model_instance->get_rotation());
|
||||||
#else
|
#else
|
||||||
@ -2444,7 +2471,11 @@ void GLCanvas3D::update_gizmos_data()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_gizmos.set_position(Vec3d::Zero());
|
m_gizmos.set_position(Vec3d::Zero());
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m_gizmos.set_scale(Vec3d::Ones());
|
||||||
|
#else
|
||||||
m_gizmos.set_scale(1.0f);
|
m_gizmos.set_scale(1.0f);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
m_gizmos.set_rotation(Vec3d::Zero());
|
m_gizmos.set_rotation(Vec3d::Zero());
|
||||||
#else
|
#else
|
||||||
@ -2806,11 +2837,19 @@ void GLCanvas3D::register_on_enable_action_buttons_callback(void* callback)
|
|||||||
m_on_enable_action_buttons_callback.register_callback(callback);
|
m_on_enable_action_buttons_callback.register_callback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void GLCanvas3D::register_on_gizmo_scale_3D_callback(void* callback)
|
||||||
|
{
|
||||||
|
if (callback != nullptr)
|
||||||
|
m_on_gizmo_scale_3D_callback.register_callback(callback);
|
||||||
|
}
|
||||||
|
#else
|
||||||
void GLCanvas3D::register_on_gizmo_scale_uniformly_callback(void* callback)
|
void GLCanvas3D::register_on_gizmo_scale_uniformly_callback(void* callback)
|
||||||
{
|
{
|
||||||
if (callback != nullptr)
|
if (callback != nullptr)
|
||||||
m_on_gizmo_scale_uniformly_callback.register_callback(callback);
|
m_on_gizmo_scale_uniformly_callback.register_callback(callback);
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
void GLCanvas3D::register_on_gizmo_rotate_3D_callback(void* callback)
|
void GLCanvas3D::register_on_gizmo_rotate_3D_callback(void* callback)
|
||||||
@ -2838,11 +2877,19 @@ void GLCanvas3D::register_on_gizmo_flatten_callback(void* callback)
|
|||||||
}
|
}
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void GLCanvas3D::register_on_update_geometry_3D_info_callback(void* callback)
|
||||||
|
{
|
||||||
|
if (callback != nullptr)
|
||||||
|
m_on_update_geometry_3D_info_callback.register_callback(callback);
|
||||||
|
}
|
||||||
|
#else
|
||||||
void GLCanvas3D::register_on_update_geometry_info_callback(void* callback)
|
void GLCanvas3D::register_on_update_geometry_info_callback(void* callback)
|
||||||
{
|
{
|
||||||
if (callback != nullptr)
|
if (callback != nullptr)
|
||||||
m_on_update_geometry_info_callback.register_callback(callback);
|
m_on_update_geometry_info_callback.register_callback(callback);
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
void GLCanvas3D::register_action_add_callback(void* callback)
|
void GLCanvas3D::register_action_add_callback(void* callback)
|
||||||
{
|
{
|
||||||
@ -3123,7 +3170,12 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||||||
{
|
{
|
||||||
case Gizmos::Scale:
|
case Gizmos::Scale:
|
||||||
{
|
{
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
const Vec3d& scale = m_gizmos.get_scale();
|
||||||
|
m_on_gizmo_scale_3D_callback.call(scale(0), scale(1), scale(2));
|
||||||
|
#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_SCALE
|
||||||
update_scale_values();
|
update_scale_values();
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
break;
|
break;
|
||||||
@ -3371,6 +3423,15 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||||||
}
|
}
|
||||||
case Gizmos::Scale:
|
case Gizmos::Scale:
|
||||||
{
|
{
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
// Apply new temporary scale factors
|
||||||
|
const Vec3d& scale = m_gizmos.get_scale();
|
||||||
|
for (GLVolume* v : volumes)
|
||||||
|
{
|
||||||
|
v->set_scaling_factor(scale);
|
||||||
|
}
|
||||||
|
update_scale_values(scale);
|
||||||
|
#else
|
||||||
// Apply new temporary scale factor
|
// Apply new temporary scale factor
|
||||||
float scale_factor = m_gizmos.get_scale();
|
float scale_factor = m_gizmos.get_scale();
|
||||||
for (GLVolume* v : volumes)
|
for (GLVolume* v : volumes)
|
||||||
@ -3378,13 +3439,14 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||||||
v->set_scaling_factor((double)scale_factor);
|
v->set_scaling_factor((double)scale_factor);
|
||||||
}
|
}
|
||||||
update_scale_values((double)scale_factor);
|
update_scale_values((double)scale_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Gizmos::Rotate:
|
case Gizmos::Rotate:
|
||||||
{
|
{
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
// Apply new temporary rotation
|
// Apply new temporary rotation
|
||||||
Vec3d rotation = m_gizmos.get_rotation();
|
const Vec3d& rotation = m_gizmos.get_rotation();
|
||||||
for (GLVolume* v : volumes)
|
for (GLVolume* v : volumes)
|
||||||
{
|
{
|
||||||
v->set_rotation(rotation);
|
v->set_rotation(rotation);
|
||||||
@ -3413,7 +3475,12 @@ 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_SCALE
|
||||||
|
const Vec3d& scale = m_gizmos.get_scale();
|
||||||
|
m_on_update_geometry_3D_info_callback.call(size(0), size(1), size(2), scale(0), scale(1), scale(2));
|
||||||
|
#else
|
||||||
m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale());
|
m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale());
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
m_dirty = true;
|
m_dirty = true;
|
||||||
@ -3539,7 +3606,12 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||||||
}
|
}
|
||||||
case Gizmos::Scale:
|
case Gizmos::Scale:
|
||||||
{
|
{
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
const Vec3d& scale = m_gizmos.get_scale();
|
||||||
|
m_on_gizmo_scale_3D_callback.call(scale(0), scale(1), scale(2));
|
||||||
|
#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_SCALE
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Gizmos::Rotate:
|
case Gizmos::Rotate:
|
||||||
@ -3995,7 +4067,11 @@ void GLCanvas3D::_deregister_callbacks()
|
|||||||
m_on_instance_moved_callback.deregister_callback();
|
m_on_instance_moved_callback.deregister_callback();
|
||||||
m_on_wipe_tower_moved_callback.deregister_callback();
|
m_on_wipe_tower_moved_callback.deregister_callback();
|
||||||
m_on_enable_action_buttons_callback.deregister_callback();
|
m_on_enable_action_buttons_callback.deregister_callback();
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m_on_gizmo_scale_3D_callback.deregister_callback();
|
||||||
|
#else
|
||||||
m_on_gizmo_scale_uniformly_callback.deregister_callback();
|
m_on_gizmo_scale_uniformly_callback.deregister_callback();
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
m_on_gizmo_rotate_3D_callback.deregister_callback();
|
m_on_gizmo_rotate_3D_callback.deregister_callback();
|
||||||
m_on_gizmo_flatten_3D_callback.deregister_callback();
|
m_on_gizmo_flatten_3D_callback.deregister_callback();
|
||||||
@ -4003,7 +4079,11 @@ void GLCanvas3D::_deregister_callbacks()
|
|||||||
m_on_gizmo_rotate_callback.deregister_callback();
|
m_on_gizmo_rotate_callback.deregister_callback();
|
||||||
m_on_gizmo_flatten_callback.deregister_callback();
|
m_on_gizmo_flatten_callback.deregister_callback();
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m_on_update_geometry_3D_info_callback.deregister_callback();
|
||||||
|
#else
|
||||||
m_on_update_geometry_info_callback.deregister_callback();
|
m_on_update_geometry_info_callback.deregister_callback();
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
m_action_add_callback.deregister_callback();
|
m_action_add_callback.deregister_callback();
|
||||||
m_action_delete_callback.deregister_callback();
|
m_action_delete_callback.deregister_callback();
|
||||||
|
@ -384,8 +384,13 @@ class GLCanvas3D
|
|||||||
Vec3d get_position() const;
|
Vec3d get_position() const;
|
||||||
void set_position(const Vec3d& position);
|
void set_position(const Vec3d& position);
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
Vec3d get_scale() const;
|
||||||
|
void set_scale(const Vec3d& scale);
|
||||||
|
#else
|
||||||
float get_scale() const;
|
float get_scale() const;
|
||||||
void set_scale(float scale);
|
void set_scale(float scale);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
Vec3d get_rotation() const;
|
Vec3d get_rotation() const;
|
||||||
@ -515,7 +520,11 @@ class GLCanvas3D
|
|||||||
PerlCallback m_on_instance_moved_callback;
|
PerlCallback m_on_instance_moved_callback;
|
||||||
PerlCallback m_on_wipe_tower_moved_callback;
|
PerlCallback m_on_wipe_tower_moved_callback;
|
||||||
PerlCallback m_on_enable_action_buttons_callback;
|
PerlCallback m_on_enable_action_buttons_callback;
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
PerlCallback m_on_gizmo_scale_3D_callback;
|
||||||
|
#else
|
||||||
PerlCallback m_on_gizmo_scale_uniformly_callback;
|
PerlCallback m_on_gizmo_scale_uniformly_callback;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
PerlCallback m_on_gizmo_rotate_3D_callback;
|
PerlCallback m_on_gizmo_rotate_3D_callback;
|
||||||
PerlCallback m_on_gizmo_flatten_3D_callback;
|
PerlCallback m_on_gizmo_flatten_3D_callback;
|
||||||
@ -523,7 +532,11 @@ class GLCanvas3D
|
|||||||
PerlCallback m_on_gizmo_rotate_callback;
|
PerlCallback m_on_gizmo_rotate_callback;
|
||||||
PerlCallback m_on_gizmo_flatten_callback;
|
PerlCallback m_on_gizmo_flatten_callback;
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
PerlCallback m_on_update_geometry_3D_info_callback;
|
||||||
|
#else
|
||||||
PerlCallback m_on_update_geometry_info_callback;
|
PerlCallback m_on_update_geometry_info_callback;
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
PerlCallback m_action_add_callback;
|
PerlCallback m_action_add_callback;
|
||||||
PerlCallback m_action_delete_callback;
|
PerlCallback m_action_delete_callback;
|
||||||
@ -645,7 +658,11 @@ public:
|
|||||||
void register_on_instance_moved_callback(void* callback);
|
void register_on_instance_moved_callback(void* callback);
|
||||||
void register_on_wipe_tower_moved_callback(void* callback);
|
void register_on_wipe_tower_moved_callback(void* callback);
|
||||||
void register_on_enable_action_buttons_callback(void* callback);
|
void register_on_enable_action_buttons_callback(void* callback);
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void register_on_gizmo_scale_3D_callback(void* callback);
|
||||||
|
#else
|
||||||
void register_on_gizmo_scale_uniformly_callback(void* callback);
|
void register_on_gizmo_scale_uniformly_callback(void* callback);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
void register_on_gizmo_rotate_3D_callback(void* callback);
|
void register_on_gizmo_rotate_3D_callback(void* callback);
|
||||||
void register_on_gizmo_flatten_3D_callback(void* callback);
|
void register_on_gizmo_flatten_3D_callback(void* callback);
|
||||||
@ -653,7 +670,11 @@ public:
|
|||||||
void register_on_gizmo_rotate_callback(void* callback);
|
void register_on_gizmo_rotate_callback(void* callback);
|
||||||
void register_on_gizmo_flatten_callback(void* callback);
|
void register_on_gizmo_flatten_callback(void* callback);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void register_on_update_geometry_3D_info_callback(void* callback);
|
||||||
|
#else
|
||||||
void register_on_update_geometry_info_callback(void* callback);
|
void register_on_update_geometry_info_callback(void* callback);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
void register_action_add_callback(void* callback);
|
void register_action_add_callback(void* callback);
|
||||||
void register_action_delete_callback(void* callback);
|
void register_action_delete_callback(void* callback);
|
||||||
|
@ -692,12 +692,21 @@ void GLCanvas3DManager::register_on_enable_action_buttons_callback(wxGLCanvas* c
|
|||||||
it->second->register_on_enable_action_buttons_callback(callback);
|
it->second->register_on_enable_action_buttons_callback(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void GLCanvas3DManager::register_on_gizmo_scale_3D_callback(wxGLCanvas* canvas, void* callback)
|
||||||
|
{
|
||||||
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||||
|
if (it != m_canvases.end())
|
||||||
|
it->second->register_on_gizmo_scale_3D_callback(callback);
|
||||||
|
}
|
||||||
|
#else
|
||||||
void GLCanvas3DManager::register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback)
|
void GLCanvas3DManager::register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback)
|
||||||
{
|
{
|
||||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||||
if (it != m_canvases.end())
|
if (it != m_canvases.end())
|
||||||
it->second->register_on_gizmo_scale_uniformly_callback(callback);
|
it->second->register_on_gizmo_scale_uniformly_callback(callback);
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
void GLCanvas3DManager::register_on_gizmo_rotate_3D_callback(wxGLCanvas* canvas, void* callback)
|
void GLCanvas3DManager::register_on_gizmo_rotate_3D_callback(wxGLCanvas* canvas, void* callback)
|
||||||
@ -729,12 +738,21 @@ void GLCanvas3DManager::register_on_gizmo_flatten_callback(wxGLCanvas* canvas, v
|
|||||||
}
|
}
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void GLCanvas3DManager::register_on_update_geometry_3D_info_callback(wxGLCanvas* canvas, void* callback)
|
||||||
|
{
|
||||||
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||||
|
if (it != m_canvases.end())
|
||||||
|
it->second->register_on_update_geometry_3D_info_callback(callback);
|
||||||
|
}
|
||||||
|
#else
|
||||||
void GLCanvas3DManager::register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback)
|
void GLCanvas3DManager::register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback)
|
||||||
{
|
{
|
||||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||||
if (it != m_canvases.end())
|
if (it != m_canvases.end())
|
||||||
it->second->register_on_update_geometry_info_callback(callback);
|
it->second->register_on_update_geometry_info_callback(callback);
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
void GLCanvas3DManager::register_action_add_callback(wxGLCanvas* canvas, void* callback)
|
void GLCanvas3DManager::register_action_add_callback(wxGLCanvas* canvas, void* callback)
|
||||||
{
|
{
|
||||||
|
@ -162,7 +162,11 @@ public:
|
|||||||
void register_on_instance_moved_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_instance_moved_callback(wxGLCanvas* canvas, void* callback);
|
||||||
void register_on_wipe_tower_moved_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_wipe_tower_moved_callback(wxGLCanvas* canvas, void* callback);
|
||||||
void register_on_enable_action_buttons_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_enable_action_buttons_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void register_on_gizmo_scale_3D_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
#else
|
||||||
void register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_gizmo_scale_uniformly_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
void register_on_gizmo_rotate_3D_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_gizmo_rotate_3D_callback(wxGLCanvas* canvas, void* callback);
|
||||||
void register_on_gizmo_flatten_3D_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_gizmo_flatten_3D_callback(wxGLCanvas* canvas, void* callback);
|
||||||
@ -170,7 +174,11 @@ public:
|
|||||||
void register_on_gizmo_rotate_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_gizmo_rotate_callback(wxGLCanvas* canvas, void* callback);
|
||||||
void register_on_gizmo_flatten_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_gizmo_flatten_callback(wxGLCanvas* canvas, void* callback);
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void register_on_update_geometry_3D_info_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
#else
|
||||||
void register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback);
|
void register_on_update_geometry_info_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
void register_action_add_callback(wxGLCanvas* canvas, void* callback);
|
void register_action_add_callback(wxGLCanvas* canvas, void* callback);
|
||||||
void register_action_delete_callback(wxGLCanvas* canvas, void* callback);
|
void register_action_delete_callback(wxGLCanvas* canvas, void* callback);
|
||||||
|
@ -987,8 +987,11 @@ void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
|
|||||||
double ratio = calc_ratio(2, mouse_ray, m_starting_box.center());
|
double ratio = calc_ratio(2, mouse_ray, m_starting_box.center());
|
||||||
|
|
||||||
if (ratio > 0.0)
|
if (ratio > 0.0)
|
||||||
m_scale(0) = m_starting_scale(1) * ratio; // << this is temporary
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
// 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_SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
|
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
|
||||||
@ -996,8 +999,11 @@ void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
|
|||||||
double ratio = calc_ratio(1, mouse_ray, m_starting_box.center());
|
double ratio = calc_ratio(1, mouse_ray, m_starting_box.center());
|
||||||
|
|
||||||
if (ratio > 0.0)
|
if (ratio > 0.0)
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m_scale(2) = m_starting_scale(2) * ratio;
|
||||||
|
#else
|
||||||
m_scale(0) = m_starting_scale(2) * ratio; // << this is temporary
|
m_scale(0) = m_starting_scale(2) * ratio; // << this is temporary
|
||||||
// m_scale(2) = m_starting_scale(2) * ratio;
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
|
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
|
||||||
@ -1276,7 +1282,11 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
|
|||||||
::glRotated(inst.rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glRotated(inst.rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||||
::glRotated(inst.rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
|
::glRotated(inst.rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
|
||||||
::glRotated(inst.rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
|
::glRotated(inst.rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
::glScaled(inst.scaling_factor(0), inst.scaling_factor(1), inst.scaling_factor(2));
|
||||||
|
#else
|
||||||
::glScaled(inst.scaling_factor, inst.scaling_factor, inst.scaling_factor);
|
::glScaled(inst.scaling_factor, inst.scaling_factor, inst.scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#else
|
#else
|
||||||
::glTranslated(offset(0), offset(1), offset(2));
|
::glTranslated(offset(0), offset(1), offset(2));
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
@ -1317,7 +1327,11 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
|
|||||||
::glRotated(inst.rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
::glRotated(inst.rotation(2) * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||||
::glRotated(inst.rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
|
::glRotated(inst.rotation(1) * 180.0 / (double)PI, 0.0, 1.0, 0.0);
|
||||||
::glRotated(inst.rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
|
::glRotated(inst.rotation(0) * 180.0 / (double)PI, 1.0, 0.0, 0.0);
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
::glScaled(inst.scaling_factor(0), inst.scaling_factor(1), inst.scaling_factor(2));
|
||||||
|
#else
|
||||||
::glScaled(inst.scaling_factor, inst.scaling_factor, inst.scaling_factor);
|
::glScaled(inst.scaling_factor, inst.scaling_factor, inst.scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#else
|
#else
|
||||||
::glTranslated(offset(0), offset(1), offset(2));
|
::glTranslated(offset(0), offset(1), offset(2));
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
@ -1347,7 +1361,11 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
|
|||||||
for (const auto* instance : m_model_object->instances)
|
for (const auto* instance : m_model_object->instances)
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
m_instances.emplace_back(instance->get_offset(), instance->get_rotation(), instance->get_scaling_factor());
|
||||||
|
#else
|
||||||
m_instances.emplace_back(instance->get_offset(), instance->get_rotation(), instance->scaling_factor);
|
m_instances.emplace_back(instance->get_offset(), instance->get_rotation(), instance->scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#else
|
#else
|
||||||
m_instances_positions.emplace_back(instance->get_offset());
|
m_instances_positions.emplace_back(instance->get_offset());
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
@ -1576,11 +1594,20 @@ bool GLGizmoFlatten::is_plane_update_necessary() const
|
|||||||
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
#if ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
Vec3d GLGizmoFlatten::get_flattening_rotation() const
|
Vec3d GLGizmoFlatten::get_flattening_rotation() const
|
||||||
{
|
{
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
// calculates the rotations in model space, taking in account the scaling factors
|
||||||
|
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m = m_model_object->instances.front()->world_matrix(true, true).matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||||
|
Eigen::Quaterniond q;
|
||||||
|
Vec3d angles = q.setFromTwoVectors(m * m_normal, -Vec3d::UnitZ()).toRotationMatrix().eulerAngles(2, 1, 0);
|
||||||
|
m_normal = Vec3d::Zero();
|
||||||
|
return Vec3d(angles(2), angles(1), angles(0));
|
||||||
|
#else
|
||||||
// calculates the rotations in model space
|
// calculates the rotations in model space
|
||||||
Eigen::Quaterniond q;
|
Eigen::Quaterniond q;
|
||||||
Vec3d angles = q.setFromTwoVectors(m_normal, -Vec3d::UnitZ()).toRotationMatrix().eulerAngles(2, 1, 0);
|
Vec3d angles = q.setFromTwoVectors(m_normal, -Vec3d::UnitZ()).toRotationMatrix().eulerAngles(2, 1, 0);
|
||||||
m_normal = Vec3d::Zero();
|
m_normal = Vec3d::Zero();
|
||||||
return Vec3d(angles(2), angles(1), angles(0));
|
return Vec3d(angles(2), angles(1), angles(0));
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Vec3d GLGizmoFlatten::get_flattening_normal() const {
|
Vec3d GLGizmoFlatten::get_flattening_normal() const {
|
||||||
|
@ -275,6 +275,10 @@ class GLGizmoScale3D : public GLGizmoBase
|
|||||||
public:
|
public:
|
||||||
explicit GLGizmoScale3D(GLCanvas3D& parent);
|
explicit GLGizmoScale3D(GLCanvas3D& parent);
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
const Vec3d& get_scale() const { return m_scale; }
|
||||||
|
void set_scale(const Vec3d& scale) { m_starting_scale = scale; }
|
||||||
|
#else
|
||||||
double get_scale_x() const { return m_scale(0); }
|
double get_scale_x() const { return m_scale(0); }
|
||||||
void set_scale_x(double scale) { m_starting_scale(0) = scale; }
|
void set_scale_x(double scale) { m_starting_scale(0) = scale; }
|
||||||
|
|
||||||
@ -285,6 +289,7 @@ public:
|
|||||||
void set_scale_z(double scale) { m_starting_scale(2) = scale; }
|
void set_scale_z(double scale) { m_starting_scale(2) = scale; }
|
||||||
|
|
||||||
void set_scale(double scale) { m_starting_scale = scale * Vec3d::Ones(); }
|
void set_scale(double scale) { m_starting_scale = scale * Vec3d::Ones(); }
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool on_init();
|
virtual bool on_init();
|
||||||
@ -366,9 +371,15 @@ private:
|
|||||||
{
|
{
|
||||||
Vec3d position;
|
Vec3d position;
|
||||||
Vec3d rotation;
|
Vec3d rotation;
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
Vec3d scaling_factor;
|
||||||
|
|
||||||
|
InstanceData(const Vec3d& position, const Vec3d& rotation, const Vec3d& scaling_factor) : position(position), rotation(rotation), scaling_factor(scaling_factor) {}
|
||||||
|
#else
|
||||||
double scaling_factor;
|
double scaling_factor;
|
||||||
|
|
||||||
InstanceData(const Vec3d& position, const Vec3d& rotation, double scaling_factor) : position(position), rotation(rotation), scaling_factor(scaling_factor) {}
|
InstanceData(const Vec3d& position, const Vec3d& rotation, double scaling_factor) : position(position), rotation(rotation), scaling_factor(scaling_factor) {}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
};
|
};
|
||||||
std::vector<InstanceData> m_instances;
|
std::vector<InstanceData> m_instances;
|
||||||
#else
|
#else
|
||||||
|
@ -1750,6 +1750,18 @@ void update_scale_values()
|
|||||||
auto instance = (*m_objects)[m_selected_object_id]->instances.front();
|
auto instance = (*m_objects)[m_selected_object_id]->instances.front();
|
||||||
auto size = (*m_objects)[m_selected_object_id]->instance_bounding_box(0).size();
|
auto size = (*m_objects)[m_selected_object_id]->instance_bounding_box(0).size();
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
if (g_is_percent_scale) {
|
||||||
|
og->set_value("scale_x", int(instance->get_scaling_factor(X) * 100));
|
||||||
|
og->set_value("scale_y", int(instance->get_scaling_factor(Y) * 100));
|
||||||
|
og->set_value("scale_z", int(instance->get_scaling_factor(Z) * 100));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
og->set_value("scale_x", int(instance->get_scaling_factor(X) * size(0) + 0.5));
|
||||||
|
og->set_value("scale_y", int(instance->get_scaling_factor(Y) * size(1) + 0.5));
|
||||||
|
og->set_value("scale_z", int(instance->get_scaling_factor(Z) * size(2) + 0.5));
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (g_is_percent_scale) {
|
if (g_is_percent_scale) {
|
||||||
auto scale = instance->scaling_factor * 100.0;
|
auto scale = instance->scaling_factor * 100.0;
|
||||||
og->set_value("scale_x", int(scale));
|
og->set_value("scale_x", int(scale));
|
||||||
@ -1761,6 +1773,7 @@ void update_scale_values()
|
|||||||
og->set_value("scale_y", int(instance->scaling_factor * size(1) + 0.5));
|
og->set_value("scale_y", int(instance->scaling_factor * size(1) + 0.5));
|
||||||
og->set_value("scale_z", int(instance->scaling_factor * size(2) + 0.5));
|
og->set_value("scale_z", int(instance->scaling_factor * size(2) + 0.5));
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_position_values()
|
void update_position_values()
|
||||||
@ -1788,6 +1801,24 @@ void update_position_values(const Vec3d& position)
|
|||||||
og->set_value("position_z", int(position(2)));
|
og->set_value("position_z", int(position(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void update_scale_values(const Vec3d& scaling_factor)
|
||||||
|
{
|
||||||
|
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||||
|
|
||||||
|
// 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 (!g_is_percent_scale)
|
||||||
|
og->set_value("scale_unit", _("%"));
|
||||||
|
|
||||||
|
auto scale = scaling_factor * 100.0;
|
||||||
|
og->set_value("scale_x", int(scale(0)));
|
||||||
|
og->set_value("scale_y", int(scale(1)));
|
||||||
|
og->set_value("scale_z", int(scale(2)));
|
||||||
|
}
|
||||||
|
#else
|
||||||
void update_scale_values(double scaling_factor)
|
void update_scale_values(double scaling_factor)
|
||||||
{
|
{
|
||||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||||
@ -1804,6 +1835,7 @@ void update_scale_values(double scaling_factor)
|
|||||||
og->set_value("scale_y", int(scale));
|
og->set_value("scale_y", int(scale));
|
||||||
og->set_value("scale_z", int(scale));
|
og->set_value("scale_z", int(scale));
|
||||||
}
|
}
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
|
||||||
void update_rotation_values()
|
void update_rotation_values()
|
||||||
{
|
{
|
||||||
|
@ -119,7 +119,11 @@ void update_position_values();
|
|||||||
void update_position_values(const Vec3d& position);
|
void update_position_values(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_SCALE
|
||||||
|
void update_scale_values(const Vec3d& scaling_factor);
|
||||||
|
#else
|
||||||
void update_scale_values(double scaling_factor);
|
void update_scale_values(double scaling_factor);
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
// 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"
|
||||||
|
@ -644,6 +644,13 @@ register_on_gizmo_scale_uniformly_callback(canvas, callback)
|
|||||||
CODE:
|
CODE:
|
||||||
_3DScene::register_on_gizmo_scale_uniformly_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
_3DScene::register_on_gizmo_scale_uniformly_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
||||||
|
|
||||||
|
void
|
||||||
|
register_on_gizmo_scale_3D_callback(canvas, callback)
|
||||||
|
SV *canvas;
|
||||||
|
SV *callback;
|
||||||
|
CODE:
|
||||||
|
_3DScene::register_on_gizmo_scale_3D_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
||||||
|
|
||||||
void
|
void
|
||||||
register_on_gizmo_rotate_callback(canvas, callback)
|
register_on_gizmo_rotate_callback(canvas, callback)
|
||||||
SV *canvas;
|
SV *canvas;
|
||||||
@ -679,6 +686,13 @@ register_on_update_geometry_info_callback(canvas, callback)
|
|||||||
CODE:
|
CODE:
|
||||||
_3DScene::register_on_update_geometry_info_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
_3DScene::register_on_update_geometry_info_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
||||||
|
|
||||||
|
void
|
||||||
|
register_on_update_geometry_3D_info_callback(canvas, callback)
|
||||||
|
SV *canvas;
|
||||||
|
SV *callback;
|
||||||
|
CODE:
|
||||||
|
_3DScene::register_on_update_geometry_3D_info_callback((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), (void*)callback);
|
||||||
|
|
||||||
void
|
void
|
||||||
register_action_add_callback(canvas, callback)
|
register_action_add_callback(canvas, callback)
|
||||||
SV *canvas;
|
SV *canvas;
|
||||||
|
@ -371,8 +371,13 @@ ModelMaterial::attributes()
|
|||||||
double rotation()
|
double rotation()
|
||||||
%code%{ RETVAL = THIS->rotation; %};
|
%code%{ RETVAL = THIS->rotation; %};
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
Vec3d* scaling_factor()
|
||||||
|
%code%{ RETVAL = new Vec3d(THIS->get_scaling_factor(X), THIS->get_scaling_factor(Y), THIS->get_scaling_factor(Z)); %};
|
||||||
|
#else
|
||||||
double scaling_factor()
|
double scaling_factor()
|
||||||
%code%{ RETVAL = THIS->scaling_factor; %};
|
%code%{ RETVAL = THIS->scaling_factor; %};
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
Vec2d* offset()
|
Vec2d* offset()
|
||||||
%code%{ RETVAL = new Vec2d(THIS->get_offset(X), THIS->get_offset(Y)); %};
|
%code%{ RETVAL = new Vec2d(THIS->get_offset(X), THIS->get_offset(Y)); %};
|
||||||
@ -387,13 +392,20 @@ ModelMaterial::attributes()
|
|||||||
|
|
||||||
void set_rotations(Vec3d *rotation)
|
void set_rotations(Vec3d *rotation)
|
||||||
%code%{ THIS->set_rotation(*rotation); THIS->get_object()->invalidate_bounding_box(); %};
|
%code%{ THIS->set_rotation(*rotation); THIS->get_object()->invalidate_bounding_box(); %};
|
||||||
|
|
||||||
#else
|
#else
|
||||||
void set_rotation(double val)
|
void set_rotation(double val)
|
||||||
%code%{ THIS->rotation = val; THIS->get_object()->invalidate_bounding_box(); %};
|
%code%{ THIS->rotation = val; THIS->get_object()->invalidate_bounding_box(); %};
|
||||||
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
|
||||||
|
#if ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
|
void set_scaling_factor(double val)
|
||||||
|
%code%{ THIS->set_scaling_factor(X, val); THIS->set_scaling_factor(Y, val); THIS->set_scaling_factor(Z, val); THIS->get_object()->invalidate_bounding_box(); %};
|
||||||
|
|
||||||
|
void set_scaling_factors(Vec3d *scale)
|
||||||
|
%code%{ THIS->set_scaling_factor(*scale); THIS->get_object()->invalidate_bounding_box(); %};
|
||||||
|
#else
|
||||||
void set_scaling_factor(double val)
|
void set_scaling_factor(double val)
|
||||||
%code%{ THIS->scaling_factor = val; THIS->get_object()->invalidate_bounding_box(); %};
|
%code%{ THIS->scaling_factor = val; THIS->get_object()->invalidate_bounding_box(); %};
|
||||||
|
#endif // ENABLE_MODELINSTANCE_3D_SCALE
|
||||||
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
#if ENABLE_MODELINSTANCE_3D_OFFSET
|
||||||
void set_offset(Vec2d *offset)
|
void set_offset(Vec2d *offset)
|
||||||
%code%{
|
%code%{
|
||||||
|
Loading…
Reference in New Issue
Block a user