mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-13 01:37:53 -06:00
FIX:fix transparent 3D display
Change-Id: I6b7a09842d68c0417ae66640463b540500290848 (cherry picked from commit fce7e678802d3087728eafa93992999cc745bd0a)
This commit is contained in:
parent
6e34ecd749
commit
9392e3a9f1
6 changed files with 97 additions and 38 deletions
|
@ -71,29 +71,46 @@ void glAssertRecentCallImpl(const char* file_name, unsigned int line, const char
|
|||
// BBS
|
||||
std::vector<std::array<float, 4>> get_extruders_colors()
|
||||
{
|
||||
unsigned char rgb_color[3] = {};
|
||||
unsigned char rgba_color[4] = {};
|
||||
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||
std::vector<std::array<float, 4>> colors_out(colors.size());
|
||||
for (const std::string &color : colors) {
|
||||
Slic3r::GUI::BitmapCache::parse_color(color, rgb_color);
|
||||
Slic3r::GUI::BitmapCache::parse_color4(color, rgba_color);
|
||||
size_t color_idx = &color - &colors.front();
|
||||
colors_out[color_idx] = { float(rgb_color[0]) / 255.f, float(rgb_color[1]) / 255.f, float(rgb_color[2]) / 255.f, 1.f };
|
||||
colors_out[color_idx] = {
|
||||
float(rgba_color[0]) / 255.f,
|
||||
float(rgba_color[1]) / 255.f,
|
||||
float(rgba_color[2]) / 255.f,
|
||||
float(rgba_color[3]) / 255.f,
|
||||
};
|
||||
}
|
||||
|
||||
return colors_out;
|
||||
}
|
||||
|
||||
std::array<float, 4> adjust_color_for_rendering(const std::array<float, 4>& colors)
|
||||
{
|
||||
if ((colors[0] < 0.1) && (colors[1] < 0.1) && (colors[2] < 0.1))
|
||||
float FullyTransparentMaterialThreshold = 0.1f;
|
||||
float FullTransparentModdifiedToFixAlpha = 0.3f;
|
||||
std::array<float, 4> adjust_color_for_rendering(const std::array<float, 4> &colors, int whichView)
|
||||
{
|
||||
if (whichView == (int) Slic3r::GUI::GLCanvas3D::ECanvasType::CanvasView3D ||
|
||||
whichView == (int) Slic3r::GUI::GLCanvas3D::ECanvasType::CanvasAssembleView) {
|
||||
if (colors[3] < FullyTransparentMaterialThreshold) { // completely transparent
|
||||
std::array<float, 4> new_color;
|
||||
new_color[0] = 0.1;
|
||||
new_color[1] = 0.1;
|
||||
new_color[2] = 0.1;
|
||||
new_color[3] = colors[3];
|
||||
new_color[0] = 1;
|
||||
new_color[1] = 1;
|
||||
new_color[2] = 1;
|
||||
new_color[3] = FullTransparentModdifiedToFixAlpha;
|
||||
return new_color;
|
||||
}
|
||||
} else {
|
||||
if (colors[3] < FullyTransparentMaterialThreshold) { // completely transparent
|
||||
std::array<float, 4> new_color;
|
||||
new_color[0] = 1;
|
||||
new_color[1] = 1;
|
||||
new_color[2] = 1;
|
||||
new_color[3] = 0.05f;
|
||||
return new_color;
|
||||
}
|
||||
}
|
||||
|
||||
return colors;
|
||||
}
|
||||
|
@ -514,8 +531,13 @@ void GLVolume::set_render_color()
|
|||
}
|
||||
}
|
||||
|
||||
if (force_transparent)
|
||||
if (force_transparent) {
|
||||
if (color[3] < FullyTransparentMaterialThreshold) {
|
||||
render_color[3] = FullTransparentModdifiedToFixAlpha;
|
||||
} else {
|
||||
render_color[3] = color[3];
|
||||
}
|
||||
}
|
||||
|
||||
//BBS set unprintable color
|
||||
if (!printable) {
|
||||
|
@ -1023,6 +1045,15 @@ void GLWipeTowerVolume::render(bool with_outline) const
|
|||
glFrontFace(GL_CCW);
|
||||
}
|
||||
|
||||
bool GLWipeTowerVolume::IsTransparent() {
|
||||
for (size_t i = 0; i < m_colors.size(); i++) {
|
||||
if (m_colors[i][3] < 1.0f) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<int> GLVolumeCollection::load_object(
|
||||
const ModelObject *model_object,
|
||||
int obj_idx,
|
||||
|
@ -1211,6 +1242,10 @@ GLVolumeWithIdAndZList volumes_to_render(const GLVolumePtrs& volumes, GLVolumeCo
|
|||
for (unsigned int i = 0; i < (unsigned int)volumes.size(); ++i) {
|
||||
GLVolume* volume = volumes[i];
|
||||
bool is_transparent = (volume->render_color[3] < 1.0f);
|
||||
auto tempGlwipeTowerVolume = dynamic_cast<GLWipeTowerVolume *>(volume);
|
||||
if (tempGlwipeTowerVolume) {
|
||||
is_transparent = tempGlwipeTowerVolume->IsTransparent();
|
||||
}
|
||||
if (((type == GLVolumeCollection::ERenderType::Opaque && !is_transparent) ||
|
||||
(type == GLVolumeCollection::ERenderType::Transparent && is_transparent) ||
|
||||
type == GLVolumeCollection::ERenderType::All) &&
|
||||
|
|
|
@ -31,7 +31,9 @@
|
|||
#define glcheck()
|
||||
#endif // HAS_GLSAFE
|
||||
extern std::vector<std::array<float, 4>> get_extruders_colors();
|
||||
extern std::array<float, 4> adjust_color_for_rendering(const std::array<float, 4>& colors);
|
||||
extern float FullyTransparentMaterialThreshold;
|
||||
extern float FullTransparentModdifiedToFixAlpha;
|
||||
extern std::array<float, 4> adjust_color_for_rendering(const std::array<float, 4> &colors, int whichView=0);
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
@ -558,6 +560,7 @@ public:
|
|||
virtual void render(bool with_outline = false) const;
|
||||
|
||||
std::vector<GLIndexedVertexArray> iva_per_colors;
|
||||
bool IsTransparent();
|
||||
|
||||
private:
|
||||
std::vector<std::array<float, 4>> m_colors;
|
||||
|
|
|
@ -1152,6 +1152,9 @@ void GCodeViewer::refresh(const GCodeProcessorResult& gcode_result, const std::v
|
|||
for (auto item : m_tools.m_tool_visibles) item = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < m_tools.m_tool_colors.size(); i++) {
|
||||
m_tools.m_tool_colors[i] = adjust_color_for_rendering(m_tools.m_tool_colors[i], GLCanvas3D::ECanvasType::CanvasPreview);
|
||||
}
|
||||
// ensure there are enough colors defined
|
||||
while (m_tools.m_tool_colors.size() < std::max(size_t(1), gcode_result.extruders_count)) {
|
||||
m_tools.m_tool_colors.push_back(decode_color("#FF8000"));
|
||||
|
@ -3263,7 +3266,7 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
|
|||
color = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
else {
|
||||
color = m_tools.m_tool_colors[path.cp_color_id];
|
||||
color = adjust_color_for_rendering(color);
|
||||
color = adjust_color_for_rendering(color, GLCanvas3D::ECanvasType::CanvasPreview);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -3873,6 +3876,10 @@ void GCodeViewer::render_toolpaths()
|
|||
](std::vector<RenderPath>::reverse_iterator it_path, std::vector<RenderPath>::reverse_iterator it_end, GLShaderProgram& shader, int uniform_color) {
|
||||
for (auto it = it_path; it != it_end && it_path->ibuffer_id == it->ibuffer_id; ++it) {
|
||||
const RenderPath& path = *it;
|
||||
if (path.color[3] < 1.0) {
|
||||
glsafe(::glEnable(GL_BLEND));
|
||||
glsafe(::glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
}
|
||||
// Some OpenGL drivers crash on empty glMultiDrawElements, see GH #7415.
|
||||
assert(! path.sizes.empty());
|
||||
assert(! path.offsets.empty());
|
||||
|
@ -3881,6 +3888,9 @@ void GCodeViewer::render_toolpaths()
|
|||
#if ENABLE_GCODE_VIEWER_STATISTICS
|
||||
++m_statistics.gl_multi_triangles_calls_count;
|
||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||
if (path.color[3] < 1.0) {
|
||||
glsafe(::glDisable(GL_BLEND));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -4159,6 +4169,10 @@ void GCodeViewer::render_all_plates_stats(const std::vector<const GCodeProcessor
|
|||
std::vector<float> filament_densities = gcode_result_list.front()->filament_densities;
|
||||
std::vector<Color> filament_colors = decode_colors(wxGetApp().plater()->get_extruder_colors_from_plater_config(gcode_result_list.back()));
|
||||
|
||||
for (int i = 0; i < filament_colors.size(); i++) {
|
||||
filament_colors[i] = adjust_color_for_rendering(filament_colors[i], GLCanvas3D::ECanvasType::CanvasPreview);
|
||||
}
|
||||
|
||||
bool imperial_units = wxGetApp().app_config->get("use_inches") == "1";
|
||||
float window_padding = 4.0f * m_scale;
|
||||
const float icon_size = ImGui::GetTextLineHeight() * 0.7;
|
||||
|
@ -4409,21 +4423,21 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||
default:
|
||||
case EItemType::Rect: {
|
||||
draw_list->AddRectFilled({ pos.x + 1.0f * m_scale, pos.y + 3.0f * m_scale }, { pos.x + icon_size - 1.0f * m_scale, pos.y + icon_size + 1.0f * m_scale },
|
||||
ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }));
|
||||
ImGui::GetColorU32({color[0], color[1], color[2], color[3]}));
|
||||
break;
|
||||
}
|
||||
case EItemType::Circle: {
|
||||
ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size + 5.0f));
|
||||
draw_list->AddCircleFilled(center, 0.5f * icon_size, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
||||
draw_list->AddCircleFilled(center, 0.5f * icon_size, ImGui::GetColorU32({color[0], color[1], color[2], color[3]}), 16);
|
||||
break;
|
||||
}
|
||||
case EItemType::Hexagon: {
|
||||
ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size + 5.0f));
|
||||
draw_list->AddNgonFilled(center, 0.5f * icon_size, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 6);
|
||||
draw_list->AddNgonFilled(center, 0.5f * icon_size, ImGui::GetColorU32({color[0], color[1], color[2], color[3]}), 6);
|
||||
break;
|
||||
}
|
||||
case EItemType::Line: {
|
||||
draw_list->AddLine({ pos.x + 1, pos.y + icon_size + 2 }, { pos.x + icon_size - 1, pos.y + 4 }, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 3.0f);
|
||||
draw_list->AddLine({pos.x + 1, pos.y + icon_size + 2}, {pos.x + icon_size - 1, pos.y + 4}, ImGui::GetColorU32({color[0], color[1], color[2], color[3]}), 3.0f);
|
||||
break;
|
||||
case EItemType::None:
|
||||
break;
|
||||
|
|
|
@ -734,7 +734,13 @@ public:
|
|||
|
||||
//BBS
|
||||
ConflictResultOpt m_conflict_result;
|
||||
|
||||
bool GetGcodeGenOk()
|
||||
{
|
||||
if (m_roles.empty())
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
std::vector<int> m_plater_extruder;
|
||||
bool m_gl_data_initialized{ false };
|
||||
|
|
|
@ -1888,32 +1888,34 @@ void GLCanvas3D::render(bool only_init)
|
|||
_render_selection();
|
||||
if (!no_partplate)
|
||||
_render_bed(!camera.is_looking_downward(), show_axes);
|
||||
//BBS: add outline logic
|
||||
_render_objects(GLVolumeCollection::ERenderType::Transparent, !m_gizmos.is_running());
|
||||
if (!no_partplate)
|
||||
if (!no_partplate) //BBS: add outline logic
|
||||
_render_platelist(!camera.is_looking_downward(), only_current, only_body, hover_id);
|
||||
_render_objects(GLVolumeCollection::ERenderType::Transparent, !m_gizmos.is_running());
|
||||
}
|
||||
/* preview render */
|
||||
else if (m_canvas_type == ECanvasType::CanvasPreview && m_render_preview) {
|
||||
//BBS: add outline logic
|
||||
_render_objects(GLVolumeCollection::ERenderType::Opaque, !m_gizmos.is_running());
|
||||
//BBS: GUI refactor: add canvas size as parameters
|
||||
_render_gcode(cnv_size.get_width(), cnv_size.get_height());
|
||||
_render_sla_slices();
|
||||
_render_selection();
|
||||
_render_bed(!camera.is_looking_downward(), show_axes);
|
||||
_render_platelist(!camera.is_looking_downward(), only_current, true, hover_id);
|
||||
// BBS: add outline logic
|
||||
if (m_gcode_viewer.GetGcodeGenOk()==false) {
|
||||
_render_objects(GLVolumeCollection::ERenderType::Transparent, !m_gizmos.is_running());
|
||||
}
|
||||
// BBS: GUI refactor: add canvas size as parameters
|
||||
_render_gcode(cnv_size.get_width(), cnv_size.get_height());
|
||||
}
|
||||
/* assemble render*/
|
||||
else if (m_canvas_type == ECanvasType::CanvasAssembleView) {
|
||||
//BBS: add outline logic
|
||||
_render_objects(GLVolumeCollection::ERenderType::Opaque, !m_gizmos.is_running());
|
||||
//_render_bed(!camera.is_looking_downward(), show_axes);
|
||||
//BBS: add outline logic
|
||||
_render_objects(GLVolumeCollection::ERenderType::Transparent, !m_gizmos.is_running());
|
||||
_render_plane();
|
||||
//BBS: add outline logic insteadof selection under assemble view
|
||||
//_render_selection();
|
||||
// BBS: add outline logic
|
||||
_render_objects(GLVolumeCollection::ERenderType::Transparent, !m_gizmos.is_running());
|
||||
}
|
||||
|
||||
_render_sequential_clearance();
|
||||
|
|
|
@ -3702,9 +3702,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||
if (!silence) wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().make_preferred().string());
|
||||
// XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames...
|
||||
}
|
||||
|
||||
// automatic selection of added objects
|
||||
if (!obj_idxs.empty() && view3D != nullptr && !load_config) {
|
||||
if (!obj_idxs.empty() && view3D != nullptr && load_config) {
|
||||
// update printable state for new volumes on canvas3D
|
||||
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_objects(obj_idxs);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue