Raycaster can now handle multiple volumes
This is necessary for future FDM supports gizmo. SLA objects only have one volume, so it wasn't needed until now.
This commit is contained in:
parent
bf734c8f68
commit
d9e5721cb7
2 changed files with 33 additions and 12 deletions
|
@ -198,21 +198,41 @@ void Raycaster::on_update()
|
||||||
if (! mo)
|
if (! mo)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const TriangleMesh* mesh = &mo->volumes.front()->mesh();
|
std::vector<const TriangleMesh*> meshes;
|
||||||
const HollowedMesh* hollowed_mesh_tracker = get_pool()->hollowed_mesh();
|
const std::vector<ModelVolume*>& mvs = mo->volumes;
|
||||||
if (hollowed_mesh_tracker && hollowed_mesh_tracker->get_hollowed_mesh())
|
if (mvs.size() == 1) {
|
||||||
mesh = hollowed_mesh_tracker->get_hollowed_mesh();
|
assert(mvs.front()->is_model_part());
|
||||||
|
const HollowedMesh* hollowed_mesh_tracker = get_pool()->hollowed_mesh();
|
||||||
|
if (hollowed_mesh_tracker && hollowed_mesh_tracker->get_hollowed_mesh())
|
||||||
|
meshes.push_back(hollowed_mesh_tracker->get_hollowed_mesh());
|
||||||
|
}
|
||||||
|
if (meshes.empty()) {
|
||||||
|
for (const ModelVolume* mv : mvs) {
|
||||||
|
if (mv->is_model_part())
|
||||||
|
meshes.push_back(&mv->mesh());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mesh != m_old_mesh) {
|
if (meshes != m_old_meshes) {
|
||||||
m_raycaster.reset(new MeshRaycaster(*mesh));
|
m_raycasters.clear();
|
||||||
m_old_mesh = mesh;
|
for (const TriangleMesh* mesh : meshes)
|
||||||
|
m_raycasters.emplace_back(new MeshRaycaster(*mesh));
|
||||||
|
m_old_meshes = meshes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Raycaster::on_release()
|
void Raycaster::on_release()
|
||||||
{
|
{
|
||||||
m_raycaster.reset();
|
m_raycasters.clear();
|
||||||
m_old_mesh = nullptr;
|
m_old_meshes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<const MeshRaycaster*> Raycaster::raycasters() const
|
||||||
|
{
|
||||||
|
std::vector<const MeshRaycaster*> mrcs;
|
||||||
|
for (const auto& raycaster_unique_ptr : m_raycasters)
|
||||||
|
mrcs.push_back(raycaster_unique_ptr.get());
|
||||||
|
return mrcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -188,15 +188,16 @@ public:
|
||||||
CommonGizmosDataID get_dependencies() const override { return CommonGizmosDataID::SelectionInfo; }
|
CommonGizmosDataID get_dependencies() const override { return CommonGizmosDataID::SelectionInfo; }
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
|
|
||||||
const MeshRaycaster* raycaster() const { return m_raycaster.get(); }
|
const MeshRaycaster* raycaster() const { assert(m_raycasters.size() == 1); return m_raycasters.front().get(); }
|
||||||
|
std::vector<const MeshRaycaster*> raycasters() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void on_update() override;
|
void on_update() override;
|
||||||
void on_release() override;
|
void on_release() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<MeshRaycaster> m_raycaster;
|
std::vector<std::unique_ptr<MeshRaycaster>> m_raycasters;
|
||||||
const TriangleMesh* m_old_mesh = nullptr;
|
std::vector<const TriangleMesh*> m_old_meshes;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue