mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-21 13:47:59 -06:00
NEW:add section view at assemble_view
Change-Id: I05b77e96e0d382b34ef80f622c71deca1eeb93b8
This commit is contained in:
parent
c02dd81c61
commit
143c0f3750
7 changed files with 377 additions and 23 deletions
|
@ -541,5 +541,172 @@ void SupportsClipper::render_cut() const
|
|||
}
|
||||
|
||||
|
||||
|
||||
using namespace AssembleViewDataObjects;
|
||||
AssembleViewDataPool::AssembleViewDataPool(GLCanvas3D* canvas)
|
||||
: m_canvas(canvas)
|
||||
{
|
||||
using c = AssembleViewDataID;
|
||||
m_data[c::ModelObjectsInfo].reset(new ModelObjectsInfo(this));
|
||||
m_data[c::ModelObjectsClipper].reset(new ModelObjectsClipper(this));
|
||||
}
|
||||
|
||||
void AssembleViewDataPool::update(AssembleViewDataID required)
|
||||
{
|
||||
assert(check_dependencies(required));
|
||||
for (auto& [id, data] : m_data) {
|
||||
if (int(required) & int(AssembleViewDataID(id)))
|
||||
data->update();
|
||||
else
|
||||
if (data->is_valid())
|
||||
data->release();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ModelObjectsInfo* AssembleViewDataPool::model_objects_info() const
|
||||
{
|
||||
ModelObjectsInfo* sel_info = dynamic_cast<ModelObjectsInfo*>(m_data.at(AssembleViewDataID::ModelObjectsInfo).get());
|
||||
assert(sel_info);
|
||||
return sel_info->is_valid() ? sel_info : nullptr;
|
||||
}
|
||||
|
||||
|
||||
ModelObjectsClipper* AssembleViewDataPool::model_objects_clipper() const
|
||||
{
|
||||
ModelObjectsClipper* oc = dynamic_cast<ModelObjectsClipper*>(m_data.at(AssembleViewDataID::ModelObjectsClipper).get());
|
||||
// ObjectClipper is used from outside the gizmos to report current clipping plane.
|
||||
// This function can be called when oc is nullptr.
|
||||
return (oc && oc->is_valid()) ? oc : nullptr;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Check the required resources one by one and return true if all
|
||||
// dependencies are met.
|
||||
bool AssembleViewDataPool::check_dependencies(AssembleViewDataID required) const
|
||||
{
|
||||
// This should iterate over currently required data. Each of them should
|
||||
// be asked about its dependencies and it must check that all dependencies
|
||||
// are also in required and before the current one.
|
||||
for (auto& [id, data] : m_data) {
|
||||
// in case we don't use this, the deps are irrelevant
|
||||
if (!(int(required) & int(AssembleViewDataID(id))))
|
||||
continue;
|
||||
|
||||
|
||||
AssembleViewDataID deps = data->get_dependencies();
|
||||
assert(int(deps) == (int(deps) & int(required)));
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif // NDEBUG
|
||||
|
||||
|
||||
|
||||
|
||||
void ModelObjectsInfo::on_update()
|
||||
{
|
||||
if (!get_pool()->get_canvas()->get_model()->objects.empty()) {
|
||||
m_model_objects = get_pool()->get_canvas()->get_model()->objects;
|
||||
}
|
||||
}
|
||||
|
||||
void ModelObjectsInfo::on_release()
|
||||
{
|
||||
m_model_objects.clear();
|
||||
}
|
||||
|
||||
//int ModelObjectsInfo::get_active_instance() const
|
||||
//{
|
||||
// const Selection& selection = get_pool()->get_canvas()->get_selection();
|
||||
// return selection.get_instance_idx();
|
||||
//}
|
||||
|
||||
|
||||
void ModelObjectsClipper::on_update()
|
||||
{
|
||||
const ModelObjectPtrs model_objects = get_pool()->model_objects_info()->model_objects();
|
||||
if (model_objects.empty())
|
||||
return;
|
||||
|
||||
// which mesh should be cut?
|
||||
std::vector<const TriangleMesh*> meshes;
|
||||
|
||||
if (meshes.empty())
|
||||
for (auto mo : model_objects) {
|
||||
for (const ModelVolume* mv : mo->volumes)
|
||||
meshes.push_back(&mv->mesh());
|
||||
}
|
||||
|
||||
if (meshes != m_old_meshes) {
|
||||
m_clippers.clear();
|
||||
for (const TriangleMesh* mesh : meshes) {
|
||||
m_clippers.emplace_back(new MeshClipper);
|
||||
m_clippers.back()->set_mesh(*mesh);
|
||||
}
|
||||
m_old_meshes = meshes;
|
||||
|
||||
m_active_inst_bb_radius = get_pool()->get_canvas()->volumes_bounding_box().radius();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ModelObjectsClipper::on_release()
|
||||
{
|
||||
m_clippers.clear();
|
||||
m_old_meshes.clear();
|
||||
m_clp.reset();
|
||||
m_clp_ratio = 0.;
|
||||
|
||||
}
|
||||
|
||||
void ModelObjectsClipper::render_cut() const
|
||||
{
|
||||
if (m_clp_ratio == 0.)
|
||||
return;
|
||||
const ModelObjectPtrs model_objects = get_pool()->model_objects_info()->model_objects();
|
||||
|
||||
size_t clipper_id = 0;
|
||||
for (const ModelObject* mo : model_objects) {
|
||||
Geometry::Transformation assemble_objects_trafo = mo->instances[0]->get_assemble_transformation();
|
||||
auto offset_to_assembly = mo->instances[0]->get_offset_to_assembly();
|
||||
for (const ModelVolume* mv : mo->volumes) {
|
||||
Geometry::Transformation vol_trafo = mv->get_transformation();
|
||||
Geometry::Transformation trafo = assemble_objects_trafo * vol_trafo;
|
||||
trafo.set_offset(trafo.get_offset() + vol_trafo.get_offset() * (GLVolume::explosion_ratio - 1.0) + offset_to_assembly * (GLVolume::explosion_ratio - 1.0));
|
||||
|
||||
auto& clipper = m_clippers[clipper_id];
|
||||
clipper->set_plane(*m_clp);
|
||||
clipper->set_transformation(trafo);
|
||||
glsafe(::glPushMatrix());
|
||||
// BBS
|
||||
glsafe(::glColor3f(0.25f, 0.25f, 0.25f));
|
||||
clipper->render_cut();
|
||||
glsafe(::glPopMatrix());
|
||||
|
||||
++clipper_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ModelObjectsClipper::set_position(double pos, bool keep_normal)
|
||||
{
|
||||
Vec3d camera_dir = wxGetApp().plater()->get_camera().get_dir_forward();
|
||||
Vec3d normal = -camera_dir;
|
||||
const Vec3d& center = get_pool()->get_canvas()->volumes_bounding_box().center();
|
||||
float dist = normal.dot(center);
|
||||
|
||||
if (pos < 0.)
|
||||
pos = m_clp_ratio;
|
||||
|
||||
m_clp_ratio = pos;
|
||||
m_clp.reset(new ClippingPlane(normal, (dist - (-m_active_inst_bb_radius * GLVolume::explosion_ratio) - m_clp_ratio * 2 * m_active_inst_bb_radius * GLVolume::explosion_ratio)));
|
||||
get_pool()->get_canvas()->set_as_dirty();
|
||||
}
|
||||
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue