mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-15 11:51:33 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4662bc67bb | ||
|
|
edcf865191 | ||
|
|
e30b9fe93e | ||
|
|
b7bff92ede | ||
|
|
d48012e18b | ||
|
|
5d73410281 |
@@ -18,7 +18,7 @@
|
||||
<script src="../js/plugin-config-ui.js"></script>
|
||||
<script src="./index.js"></script>
|
||||
<script src="./plugin-sort.js"></script>
|
||||
<script src="../../js/fuzzy-search.js"></script>
|
||||
<script src="../js/fuzzy-search.js"></script>
|
||||
<script src="./plugin-search.js"></script>
|
||||
</head>
|
||||
<body onLoad="OnInit()">
|
||||
|
||||
@@ -10,6 +10,11 @@ function OnInit()
|
||||
// Orca: fallback timeout in case the C++ -> JS signal fails (e.g., WebKit issues).
|
||||
// Jump to the target page after 3 minutes so slow computers don't get stuck on a partially loaded page.
|
||||
setTimeout("JumpToTarget()",180*1000);
|
||||
|
||||
var tSend={};
|
||||
tSend['sequence_id']=Math.round(new Date() / 1000);
|
||||
tSend['command']="userguide_loading_page_ready";
|
||||
SendWXMessage(JSON.stringify(tSend));
|
||||
}
|
||||
|
||||
function HandleStudio( pVal )
|
||||
|
||||
@@ -156,16 +156,12 @@ function SetCloudMode( bOn )
|
||||
|
||||
m_CloudMode=bOn;
|
||||
$("body").toggleClass("cloud-mode", bOn);
|
||||
|
||||
if( bOn )
|
||||
{
|
||||
$(".BtnItem").removeClass("BtnItemSelected");
|
||||
$(".BtnShortcut").addClass("BtnItemSelected");
|
||||
}
|
||||
}
|
||||
|
||||
function GotoCloud()
|
||||
{
|
||||
$(".BtnItem").removeClass("BtnItemSelected");
|
||||
$(".BtnShortcut").addClass("BtnItemSelected");
|
||||
SetCloudMode(true);
|
||||
SendSimpleCommand("homepage_open_cloud");
|
||||
}
|
||||
|
||||
@@ -91,12 +91,16 @@ bool DecodedHeightTexture::texel_tap(const Vec2f &uv, bool tile_enabled, Texture
|
||||
const float fy = v * float(height);
|
||||
const int x0 = std::clamp(int(std::floor(fx)), 0, width - 1);
|
||||
const int y0 = std::clamp(int(std::floor(fy)), 0, height - 1);
|
||||
// Neighbour for bilinear filtering: wrap for tiling methods, clamp at the edge otherwise (a
|
||||
// repeating neighbour would incorrectly blend against the opposite edge of the image).
|
||||
// Neighbour for bilinear filtering. Repeat wraps, because its next tile really does start at the
|
||||
// opposite edge. The other two clamp: an untiled placement has nothing past its border, and a
|
||||
// mirrored tile folds back on itself there, so the texel past the edge is the edge again. Wrapping
|
||||
// a mirrored seam blends the two opposite edges of the image together, which is both a visible
|
||||
// line and a disagreement with the preview - the GPU path binds GL_MIRRORED_REPEAT, which folds.
|
||||
const bool wrap_neighbour = tile_enabled && tile_method != TextureTileMethod::MirroredRepeat;
|
||||
tap.x0 = x0;
|
||||
tap.y0 = y0;
|
||||
tap.x1 = tile_enabled ? (x0 + 1) % width : std::min(x0 + 1, width - 1);
|
||||
tap.y1 = tile_enabled ? (y0 + 1) % height : std::min(y0 + 1, height - 1);
|
||||
tap.x1 = wrap_neighbour ? (x0 + 1) % width : std::min(x0 + 1, width - 1);
|
||||
tap.y1 = wrap_neighbour ? (y0 + 1) % height : std::min(y0 + 1, height - 1);
|
||||
tap.tx = fx - std::floor(fx);
|
||||
tap.ty = fy - std::floor(fy);
|
||||
return true;
|
||||
@@ -692,7 +696,68 @@ TextureDetail analyze_texture_detail(const TextureDisplacementLayer &layer)
|
||||
for (int i = 0; i < 8; ++i)
|
||||
top += bins[size_t(i)];
|
||||
out.flat_share = float(double(top) / double(npx));
|
||||
out.flat_colors = out.flat_share >= 0.85f;
|
||||
|
||||
// How much of the principal colour axis carries pixels. Sampled rather than exhaustive: the
|
||||
// axis is a bulk property, and a stride keeps this a few milliseconds on a large image.
|
||||
{
|
||||
constexpr size_t MAX_SAMPLES = size_t(1) << 16;
|
||||
const size_t stride = std::max<size_t>(1, npx / MAX_SAMPLES);
|
||||
std::vector<Vec3f> pts;
|
||||
pts.reserve(npx / stride + 1);
|
||||
for (size_t i = 0; i < npx; i += stride)
|
||||
pts.push_back(tex.has_color() ?
|
||||
Vec3f(float(tex.rgb[i * 3]), float(tex.rgb[i * 3 + 1]), float(tex.rgb[i * 3 + 2])) :
|
||||
Vec3f::Constant(float(tex.pixels[i])));
|
||||
if (pts.size() >= 16) {
|
||||
Vec3f mean = Vec3f::Zero();
|
||||
for (const Vec3f &p : pts)
|
||||
mean += p;
|
||||
mean /= float(pts.size());
|
||||
// Power iteration on the covariance: the axis, without forming the matrix.
|
||||
Vec3f axis(1.f, 0.3f, 0.2f);
|
||||
for (int it = 0; it < 24; ++it) {
|
||||
Vec3f next = Vec3f::Zero();
|
||||
for (const Vec3f &p : pts) {
|
||||
const Vec3f d = p - mean;
|
||||
next += d.dot(axis) * d;
|
||||
}
|
||||
const float n = next.norm();
|
||||
if (n < 1e-6f)
|
||||
break;
|
||||
axis = next / n;
|
||||
}
|
||||
std::vector<float> proj(pts.size());
|
||||
for (size_t i = 0; i < pts.size(); ++i)
|
||||
proj[i] = (pts[i] - mean).dot(axis);
|
||||
std::sort(proj.begin(), proj.end());
|
||||
// Trimmed, so a handful of stray pixels cannot stretch the range and make a flat
|
||||
// image look like it spans one.
|
||||
const float lo = proj[size_t(0.01 * double(proj.size()))];
|
||||
const float hi = proj[std::min(proj.size() - 1, size_t(0.99 * double(proj.size())))];
|
||||
const float span = hi - lo;
|
||||
if (span > 1e-3f) {
|
||||
constexpr int BUCKETS = 32;
|
||||
std::array<size_t, BUCKETS> hist{};
|
||||
for (const float s : proj)
|
||||
if (s >= lo && s <= hi)
|
||||
++hist[size_t(std::min(BUCKETS - 1, int((s - lo) / span * BUCKETS)))];
|
||||
// A bucket counts as carrying pixels at a fifth of a percent of them, which is
|
||||
// above the noise a dithered image leaves between its colours.
|
||||
const size_t floor_count = size_t(0.002 * double(proj.size()));
|
||||
int filled = 0;
|
||||
for (const size_t c : hist)
|
||||
filled += c >= floor_count;
|
||||
out.axis_coverage = float(filled) / float(BUCKETS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Both signals, because either alone misreads a common case: the histogram calls a
|
||||
// two-colour gradient flat (measured 0.90 on a green-to-red ramp, and 0.96 on a painted
|
||||
// model texture), while coverage alone would call a noisy two-colour logo a gradient. An
|
||||
// image whose axis could not be measured keeps coverage at 0, so the flat-share test decides
|
||||
// alone - which is what an image of a single colour needs.
|
||||
out.flat_colors = out.flat_share >= 0.85f && out.axis_coverage < 0.25f;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(g_texture_detail_cache.mutex);
|
||||
auto &entries = g_texture_detail_cache.entries;
|
||||
|
||||
@@ -504,6 +504,15 @@ struct TextureDetail
|
||||
// verdict: a "flat-colour" image (tiles, logos, camouflage) whose colours should each print in a
|
||||
// single filament, versus a photograph or gradient where interleaved filament mixes pay off.
|
||||
float flat_share = 0.f;
|
||||
// Share of the image's principal colour axis that actually carries pixels, in 32 steps. A ramp
|
||||
// covers it end to end; a few flat colours sit in spikes with gaps between them. The histogram
|
||||
// above cannot tell those apart - a two-colour gradient occupies as few bins as the two colours
|
||||
// on their own - so both are needed before an image counts as flat.
|
||||
//
|
||||
// Zero when there was nothing to measure: an image of one colour, or too few pixels to fit an
|
||||
// axis through. That is the right default, because it leaves the flat-share test deciding on its
|
||||
// own, exactly as it did before this signal existed.
|
||||
float axis_coverage = 0.f;
|
||||
bool flat_colors = false;
|
||||
};
|
||||
TextureDetail analyze_texture_detail(const TextureDisplacementLayer &layer);
|
||||
|
||||
@@ -687,8 +687,6 @@ set(SLIC3R_GUI_SOURCES
|
||||
plugin/host/PluginHostUi.hpp
|
||||
plugin/host/PluginPages.cpp
|
||||
plugin/host/PluginPages.hpp
|
||||
plugin/host/PluginResourceTextures.cpp
|
||||
plugin/host/PluginResourceTextures.hpp
|
||||
plugin/CloudPluginService.cpp
|
||||
plugin/CloudPluginService.hpp
|
||||
plugin/PluginFsUtils.cpp
|
||||
@@ -712,9 +710,6 @@ set(SLIC3R_GUI_SOURCES
|
||||
plugin/pluginTypes/pages/PagesPluginCapability.hpp
|
||||
plugin/pluginTypes/pages/PagesPluginCapability.cpp
|
||||
plugin/pluginTypes/pages/PagesPluginCapabilityTrampoline.hpp
|
||||
plugin/pluginTypes/resourceTexture/ResourceTexturePluginCapability.hpp
|
||||
plugin/pluginTypes/resourceTexture/ResourceTexturePluginCapability.cpp
|
||||
plugin/pluginTypes/resourceTexture/ResourceTexturePluginCapabilityTrampoline.hpp
|
||||
plugin/pluginTypes/script/ScriptPluginCapability.hpp
|
||||
plugin/pluginTypes/script/ScriptPluginCapability.cpp
|
||||
plugin/pluginTypes/script/ScriptPluginCapabilityTrampoline.hpp
|
||||
|
||||
@@ -252,11 +252,9 @@
|
||||
#include "slic3r/GUI/ParamsDialog.hpp"
|
||||
#include "slic3r/GUI/ParamsPanel.hpp"
|
||||
#include "slic3r/GUI/PartPlate.hpp"
|
||||
#include "slic3r/GUI/TextureLibrary.hpp"
|
||||
#include "slic3r/GUI/Widgets/Button.hpp"
|
||||
#include "slic3r/GUI/wxExtensions.hpp"
|
||||
#include "slic3r/plugin/host/PluginPages.hpp"
|
||||
#include "slic3r/plugin/host/PluginResourceTextures.hpp"
|
||||
#include <wx/defs.h>
|
||||
#include "slic3r/GUI/Widgets/WebView.hpp"
|
||||
#include <cwchar>
|
||||
@@ -335,23 +333,6 @@ static std::shared_ptr<OrcaCloudServiceAgent> get_orca_cloud_agent(NetworkAgent*
|
||||
return agent ? std::dynamic_pointer_cast<OrcaCloudServiceAgent>(agent->get_cloud_agent()) : nullptr;
|
||||
}
|
||||
|
||||
// Full {web} page URL for a same-site OrcaCloud path, or empty when it cannot be built. An already
|
||||
// open cloud pane is navigated straight to it, without re-running the session handoff.
|
||||
static wxString cloud_page_url(NetworkAgent* agent, const std::string& path)
|
||||
{
|
||||
if (path.empty())
|
||||
return {};
|
||||
auto orca = get_orca_cloud_agent(agent);
|
||||
if (!orca)
|
||||
return {};
|
||||
std::string base = orca->get_cloud_base_url();
|
||||
while (!base.empty() && base.back() == '/')
|
||||
base.pop_back();
|
||||
if (base.empty())
|
||||
return {};
|
||||
return from_u8(base + path);
|
||||
}
|
||||
|
||||
void start_ping_test()
|
||||
{
|
||||
return;
|
||||
@@ -3082,37 +3063,6 @@ void GUI_App::init_plugin_gui_wiring()
|
||||
refresh_plugins_dialog();
|
||||
switch_printer_agent_after_unload(capability.plugin_key);
|
||||
});
|
||||
plugin_mgr.subscribe_on_load_callback([](const std::string& plugin_key) {
|
||||
if (wxTheApp == nullptr || wxGetApp().is_closing())
|
||||
return;
|
||||
PluginResourceTextures::instance().on_plugin_register(plugin_key);
|
||||
Slic3r::GUI::bump_texture_library_generation();
|
||||
});
|
||||
plugin_mgr.subscribe_on_unload_callback([](const std::string& plugin_key) {
|
||||
if (wxTheApp == nullptr || wxGetApp().is_closing())
|
||||
return;
|
||||
PluginResourceTextures::instance().on_plugin_deregister(plugin_key);
|
||||
Slic3r::GUI::bump_texture_library_generation();
|
||||
});
|
||||
plugin_mgr.subscribe_on_capability_load_callback([](const PluginCapabilityId& capability) {
|
||||
if (capability.type != PluginCapabilityType::ResourceTexture)
|
||||
return;
|
||||
if (wxTheApp == nullptr || wxGetApp().is_closing())
|
||||
return;
|
||||
PluginResourceTextures::instance().on_cap_register(capability);
|
||||
Slic3r::GUI::bump_texture_library_generation();
|
||||
});
|
||||
plugin_mgr.subscribe_on_capability_unload_callback([](const PluginCapabilityId& capability) {
|
||||
if (capability.type != PluginCapabilityType::ResourceTexture)
|
||||
return;
|
||||
if (wxTheApp == nullptr || wxGetApp().is_closing())
|
||||
return;
|
||||
PluginResourceTextures::instance().on_cap_deregister(capability);
|
||||
Slic3r::GUI::bump_texture_library_generation();
|
||||
});
|
||||
// Packs already loaded before this wiring, or in tests where no callback fires.
|
||||
PluginResourceTextures::instance().initial_sweep();
|
||||
Slic3r::GUI::bump_texture_library_generation();
|
||||
}
|
||||
|
||||
bool GUI_App::on_init_inner()
|
||||
@@ -5484,7 +5434,12 @@ std::string GUI_App::handle_web_request(std::string cmd)
|
||||
this->request_open_project({});
|
||||
}
|
||||
else if (command_str.compare("homepage_open_cloud") == 0) {
|
||||
this->open_orca_cloud();
|
||||
// Deferred: set_cloud_mode() may create a second native webview, which must
|
||||
// not run inside this webview's script-message callback.
|
||||
CallAfter([this]() {
|
||||
if (WebViewPanel* home = WebViewPanel::if_built())
|
||||
home->set_cloud_mode(true, cloud_webview_handoff());
|
||||
});
|
||||
}
|
||||
else if (command_str.compare("homepage_close_cloud") == 0) {
|
||||
CallAfter([]() {
|
||||
@@ -5633,22 +5588,6 @@ std::string GUI_App::handle_web_request(std::string cmd)
|
||||
return "";
|
||||
}
|
||||
|
||||
void GUI_App::open_orca_cloud(const std::string& next)
|
||||
{
|
||||
// Remembered so a login while the pane is open re-seeds the same page rather than the default.
|
||||
m_cloud_open_path = next;
|
||||
// Deferred: set_cloud_mode() may create the second native webview, so this must not run inside
|
||||
// the caller's frame (a webview script-message callback or an ImGui frame).
|
||||
CallAfter([this]() {
|
||||
if (mainframe != nullptr)
|
||||
mainframe->select_tab(TAB_ID_HOME);
|
||||
// The Home page is built lazily, so the tab switch may not have created it yet: ensure() builds
|
||||
// it if needed, matching what showing the tab does, rather than dropping the open request.
|
||||
if (WebViewPanel* home = WebViewPanel::ensure())
|
||||
home->set_cloud_mode(true, cloud_webview_handoff(m_cloud_open_path), cloud_page_url(m_agent, m_cloud_open_path));
|
||||
});
|
||||
}
|
||||
|
||||
void GUI_App::handle_script_message(std::string msg, const std::string& provider)
|
||||
{
|
||||
try {
|
||||
@@ -5926,7 +5865,7 @@ void GUI_App::on_update_machine_list(wxCommandEvent &evt)
|
||||
}*/
|
||||
}
|
||||
|
||||
wxString GUI_App::cloud_webview_handoff(const std::string& next)
|
||||
wxString GUI_App::cloud_webview_handoff()
|
||||
{
|
||||
// The cloud pane loads the Start URL, not a token: the page checks the webview's own session
|
||||
// and asks for a handoff itself (guide §4). Signed out, user_id is omitted and the page will
|
||||
@@ -5934,7 +5873,7 @@ wxString GUI_App::cloud_webview_handoff(const std::string& next)
|
||||
auto orca = get_orca_cloud_agent(m_agent);
|
||||
if (!orca)
|
||||
return {};
|
||||
return from_u8(orca->build_web_session_start_url(next));
|
||||
return from_u8(orca->build_web_session_start_url());
|
||||
}
|
||||
|
||||
void GUI_App::request_cloud_web_session(const std::string& state)
|
||||
@@ -6077,7 +6016,7 @@ void GUI_App::on_user_login_handle(wxCommandEvent &evt)
|
||||
m_cloud_handoff_state.clear();
|
||||
if (WebViewPanel* home = WebViewPanel::if_built())
|
||||
if (home->cloud_mode_active())
|
||||
home->set_cloud_mode(true, cloud_webview_handoff(m_cloud_open_path));
|
||||
home->set_cloud_mode(true, cloud_webview_handoff());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -365,8 +365,6 @@ private:
|
||||
// and a generation counter so a superseded mint/login result is dropped (guide §5, "only the
|
||||
// newest request counts").
|
||||
std::string m_cloud_handoff_state;
|
||||
// The OrcaCloud path the open requests target, remembered so a login re-seed keeps the same page.
|
||||
std::string m_cloud_open_path;
|
||||
uint64_t m_cloud_handoff_gen { 0 };
|
||||
bool m_show_error_msgdlg{false};
|
||||
wxString m_info_dialog_content;
|
||||
@@ -468,9 +466,6 @@ public:
|
||||
#if wxUSE_WEBVIEW_EDGE
|
||||
void init_webview_runtime();
|
||||
#endif
|
||||
// Switches to the Home tab and opens the OrcaCloud pane beside the homepage on `next`, a
|
||||
// same-site OrcaCloud path (empty = the page's default). Work is deferred internally.
|
||||
void open_orca_cloud(const std::string& next = std::string());
|
||||
static unsigned get_colour_approx_luma(const wxColour& colour);
|
||||
static bool dark_mode();
|
||||
const wxColour get_label_default_clr_system();
|
||||
@@ -577,7 +572,7 @@ public:
|
||||
// called from the pane when the page asks for a session; it opens the desktop login dialog if
|
||||
// signed out, otherwise mints a one-time token on a worker thread and loads the Complete URL
|
||||
// in the same webview.
|
||||
wxString cloud_webview_handoff(const std::string& next = std::string());
|
||||
wxString cloud_webview_handoff();
|
||||
void request_cloud_web_session(const std::string& state);
|
||||
void mint_cloud_web_session(const std::string& state, uint64_t gen);
|
||||
void on_cloud_web_session_minted(const std::string& state, uint64_t gen, const std::string& token_hash);
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "slic3r/Utils/UndoRedo.hpp"
|
||||
#include "GLGizmoUtils.hpp"
|
||||
|
||||
#include <cctype>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
@@ -73,7 +72,6 @@
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <numeric>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
@@ -99,48 +97,6 @@ namespace {
|
||||
// bigger jump than the whole useful region.
|
||||
constexpr float ImGuiLogSlider = float(ImGuiSliderFlags_Logarithmic);
|
||||
|
||||
// The scrollbar of the panel's scrolling areas (the panel body and the texture library). ImGui's stock
|
||||
// scrollbar is a wide, square-cornered slab in a tinted track - against the flat panel it reads as a raw
|
||||
// widget bolted onto the edge - so it is slimmed to a rounded thumb over an invisible track. The child
|
||||
// background goes transparent with it, so the area reads as part of the panel.
|
||||
void push_slim_scrollbar_style(float width, bool dark)
|
||||
{
|
||||
const ImVec4 grab = dark ? ImVec4(1.f, 1.f, 1.f, 0.26f) : ImVec4(0.f, 0.f, 0.f, 0.26f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, width);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarRounding, 0.5f * width);
|
||||
ImGui::PushStyleColor(ImGuiCol_ScrollbarBg, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrab, grab);
|
||||
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabHovered, ImVec4(grab.x, grab.y, grab.z, 0.45f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabActive, ImVec4(grab.x, grab.y, grab.z, 0.65f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||
}
|
||||
|
||||
void pop_slim_scrollbar_style()
|
||||
{
|
||||
ImGui::PopStyleColor(5);
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
|
||||
// Cuts a UTF-8 string down to `max_w` pixels, ending it in "..." when it had to be cut.
|
||||
std::string ellipsize(std::string s, float max_w, float font_size = 0.f)
|
||||
{
|
||||
const auto text_width = [&](const std::string &text) {
|
||||
return font_size > 0.f
|
||||
? ImGui::GetFont()->CalcTextSizeA(font_size, std::numeric_limits<float>::max(), 0.f, text.c_str()).x
|
||||
: ImGui::CalcTextSize(text.c_str()).x;
|
||||
};
|
||||
if (text_width(s) <= max_w)
|
||||
return s;
|
||||
while (!s.empty() && text_width(s + "...") > max_w) {
|
||||
unsigned char c;
|
||||
do { // a whole code point at a time
|
||||
c = static_cast<unsigned char>(s.back());
|
||||
s.pop_back();
|
||||
} while (!s.empty() && (c & 0xC0) == 0x80);
|
||||
}
|
||||
return s + "...";
|
||||
}
|
||||
|
||||
// Uploads decoded 8-bit grayscale height data as an RGBA GPU texture for display in the panel.
|
||||
// Shared by the per-layer thumbnail and the picker's library entries, which differ only in where
|
||||
// their pixels came from.
|
||||
@@ -330,10 +286,22 @@ constexpr float PREFER_PURE_DE = 2.f;
|
||||
// the quantizer's lookup cube.
|
||||
constexpr size_t MIX_TARGET_SAMPLES = size_t(1) << 20;
|
||||
constexpr size_t MIX_TARGET_BINS = 256;
|
||||
// rank_mixes() stops once the best remaining mix would improve the match by less than this, in
|
||||
// CIEDE2000 averaged over every pixel of the colouring layers (see mix_targets()): a mix that only
|
||||
// touches a few stray pixels is not worth a filament slot.
|
||||
constexpr float MIN_MIX_GAIN = 0.05f;
|
||||
// The longest interleave cycle a mix may use, as the denominator of its ratio. The slicer alternates
|
||||
// a mix layer by layer, so the cycle is how many layers one repeat spans; past this it stops reading
|
||||
// as a colour and starts reading as bands of its two filaments. It also sets how many mixes exist at
|
||||
// all - the coprime ratios per pair of filaments - so it is what decides how finely a gradient can be
|
||||
// stepped. Ten gives 33 ratios per pair against the 11 of six: measured on four filaments, a
|
||||
// green-to-red gradient goes from 11 usable mixes to 16, and the shipped Colour Bricks from 6 to 10.
|
||||
constexpr int MIX_MAX_DENOMINATOR = 10;
|
||||
|
||||
// rank_mixes() stops once the best remaining mix would improve the match by less than this FRACTION
|
||||
// of what the best mix bought: a mix that only touches a few stray pixels is not worth a filament
|
||||
// slot. Relative rather than a fixed amount of CIEDE2000, because the gains decay smoothly and a
|
||||
// fixed cut lands wherever that curve happens to cross it - on a red-to-green gradient with five
|
||||
// filaments the old 0.05 kept a mix worth 0.052 and refused one worth 0.042, and it stopped at the
|
||||
// same count whether the user allowed 8 mixes or 28, and whether four filaments were loaded or six.
|
||||
// As a fraction it scales with the texture, so both the setting and the loaded filaments matter.
|
||||
constexpr double MIN_MIX_GAIN_FRACTION = 0.001;
|
||||
|
||||
// The project's mixed filament slots, one string each, as the palette cache compares them: anything
|
||||
// that changes which of them a mix can reuse changes this.
|
||||
@@ -2963,9 +2931,8 @@ void GLGizmoTextureDisplacement::run_uv_command(int cmd, float value)
|
||||
}
|
||||
else if (cmd == int(Command::PickTexture)) {
|
||||
// The same texture library the layer card opens; the panel renders it this frame.
|
||||
m_picker_slot = m_active_layer_slot;
|
||||
m_picker_open_request = true;
|
||||
m_picker_reveal_selected = true;
|
||||
m_picker_slot = m_active_layer_slot;
|
||||
m_picker_open_request = true;
|
||||
} else if (cmd == int(Command::Unwrap)) {
|
||||
// The solve runs only on this - painting, the seam angle and seam marking never trigger it.
|
||||
m_uv_unwrap_pending = true;
|
||||
@@ -4147,7 +4114,7 @@ void GLGizmoTextureDisplacement::set_layer_texture(TextureDisplacementLayer &lay
|
||||
// the PNG the first time the layer is previewed or baked.
|
||||
layer.image_data = tex->image_data;
|
||||
// The user's own textures are listed most recently used first.
|
||||
if (entry.source == TextureSource::User)
|
||||
if (entry.is_user)
|
||||
touch_user_texture(entry.path);
|
||||
|
||||
rebuild_preview();
|
||||
@@ -4174,40 +4141,6 @@ void GLGizmoTextureDisplacement::import_custom_texture(TextureDisplacementLayer
|
||||
set_layer_texture(layer, *entry);
|
||||
}
|
||||
|
||||
void GLGizmoTextureDisplacement::ease_wheel_scroll(float &target, float &applied)
|
||||
{
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
const float scroll_now = ImGui::GetScrollY();
|
||||
const float scroll_max = ImGui::GetScrollMaxY();
|
||||
|
||||
// Anything that moved the scroll without us - dragging the grab, a keyboard/gamepad nav step, the
|
||||
// content shrinking under a clamped offset, a SetScroll*() call - has to re-seed the target, or the
|
||||
// easing below would immediately drag the view back to where it last animated to.
|
||||
if (applied < 0.f || std::abs(scroll_now - applied) > 0.5f)
|
||||
target = scroll_now;
|
||||
|
||||
if (io.MouseWheel != 0.f && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))
|
||||
target -= io.MouseWheel * ImGui::GetFontSize() * 4.f;
|
||||
// Whole pixels: ImGui floors whatever SetScrollY() is given, so a fractional target could never be
|
||||
// reached and the "still gliding" test below would stay true forever, repainting the canvas for good.
|
||||
target = std::floor(std::clamp(target, 0.f, scroll_max));
|
||||
|
||||
const float delta = target - scroll_now;
|
||||
if (std::abs(delta) >= 1.f) {
|
||||
// Exponential ease, formulated against the frame time so the glide takes the same wall time
|
||||
// whether the canvas is running at 30 or 144 fps. The last sub-pixel step would be floored
|
||||
// away, so land on the target outright once the remainder is that small.
|
||||
const float t = 1.f - std::exp(-20.f * std::clamp(io.DeltaTime, 1.f / 240.f, 1.f / 15.f));
|
||||
const float step = (std::abs(delta * t) < 1.f) ? delta : delta * t;
|
||||
const float next = std::floor(scroll_now + step);
|
||||
ImGui::SetScrollY(next);
|
||||
applied = next;
|
||||
m_parent.set_as_dirty(); // nothing else would redraw mid-glide once the mouse stops
|
||||
} else {
|
||||
applied = scroll_now;
|
||||
}
|
||||
}
|
||||
|
||||
void GLGizmoTextureDisplacement::render_texture_library_popup(const ImVec2 &panel_min, const ImVec2 &panel_max)
|
||||
{
|
||||
ModelVolume *mv = texture_volume();
|
||||
@@ -4224,55 +4157,17 @@ void GLGizmoTextureDisplacement::render_texture_library_popup(const ImVec2 &pane
|
||||
ImGui::OpenPopup(popup_id);
|
||||
}
|
||||
|
||||
const float tile = std::round(m_imgui->scaled(3.2f));
|
||||
const float spacing = std::round(m_imgui->scaled(0.4f));
|
||||
const float grid_w = 4.f * tile + 3.f * spacing;
|
||||
const float gap = m_imgui->scaled(0.5f);
|
||||
const float scrollbar_w = m_imgui->scaled(0.5f);
|
||||
const float ring_w = std::max(2.f, std::round(m_imgui->scaled(0.1f))); // the current texture's ring
|
||||
const float frame_h = ImGui::GetFrameHeight();
|
||||
const ImVec4 orca = ImGuiWrapper::COL_ORCA;
|
||||
const ImGuiStyle &style = ImGui::GetStyle();
|
||||
|
||||
// A fixed size rather than a fit-to-content one. The width is the four-column grid, a gutter and the
|
||||
// slim scrollbar beside it, plus the window padding, so the columns always fit and no horizontal
|
||||
// scrollbar is needed; it derives from scaled values, so it tracks the DPI like the rest.
|
||||
const float fixed_w = grid_w + spacing + scrollbar_w + 2.f * style.WindowPadding.x;
|
||||
|
||||
// BeginPopup() ORs in ImGuiWindowFlags_AlwaysAutoResize (deps_src/imgui/imgui.cpp:8371) and no flag
|
||||
// turns it back off. A SetNextWindowSize() overrides it for each axis it sets (imgui.cpp:5983-5996),
|
||||
// so an explicit size is the only way to fix the popup's size; the grid child below then scrolls.
|
||||
//
|
||||
// Top-aligned with the panel, which keeps it clear of the gizmo toolbar above a docked panel, and as
|
||||
// tall as the panel or 70% of the window, whichever is taller, while keeping a gap inside the window.
|
||||
// The height follows the window and the panel, never the content, so it does not jump as packs load or
|
||||
// sections collapse.
|
||||
const ImGuiViewport *viewport = ImGui::GetMainViewport();
|
||||
const float vp_top = viewport->Pos.y + gap;
|
||||
const float vp_bottom = viewport->Pos.y + viewport->Size.y - gap;
|
||||
const float height = std::max(std::min(std::max(0.70f * viewport->Size.y, panel_max.y - panel_min.y), vp_bottom - vp_top),
|
||||
2.f * frame_h);
|
||||
const float popup_y = std::max(vp_top, std::min(panel_min.y, vp_bottom - height));
|
||||
const float tile = std::round(m_imgui->scaled(3.2f));
|
||||
const float spacing = std::round(m_imgui->scaled(0.4f));
|
||||
const float grid_w = 4.f * tile + 3.f * spacing;
|
||||
const float gap = m_imgui->scaled(0.5f);
|
||||
// Beside the panel rather than over it, so the layer being retextured stays in view: to its left when
|
||||
// there is room (the docked panel sits against the right edge of the canvas), otherwise to its right.
|
||||
const float width = viewport->Size.x > 0.f ? std::min(fixed_w, viewport->Size.x) : fixed_w;
|
||||
const bool left = panel_min.x - gap - width >= 0.f;
|
||||
const float popup_x = left ? panel_min.x - gap - width : panel_max.x + gap;
|
||||
// Cond_Always, not Appearing: a viewport resize while the popup is open must move and resize it too.
|
||||
ImGui::SetNextWindowPos(ImVec2(popup_x, popup_y), ImGuiCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(width, height), ImGuiCond_Always);
|
||||
// Drawn as the panel's own sheet: its opaque background and rounding, no border. A popup is filled with
|
||||
// PopupBg, which the panel's toolbar style leaves at ImGui's translucent near-black - a dark window
|
||||
// beside a light panel, with whatever it covers showing through. Only Begin reads these, so they are
|
||||
// popped at once and the tooltips shown from inside keep their own look.
|
||||
ImGui::PushStyleColor(ImGuiCol_PopupBg, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_PopupRounding, style.WindowRounding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_PopupBorderSize, 0.f);
|
||||
// The window itself never scrolls; the grid child below does.
|
||||
const bool open = ImGui::BeginPopup(popup_id, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor();
|
||||
if (!open)
|
||||
const float popup_w = grid_w + 2.f * ImGui::GetStyle().WindowPadding.x;
|
||||
const bool left = panel_min.x - gap - popup_w >= 0.f;
|
||||
ImGui::SetNextWindowPos(ImVec2(left ? panel_min.x - gap : panel_max.x + gap, panel_min.y + m_imgui->scaled(4.f)),
|
||||
ImGuiCond_Appearing, ImVec2(left ? 1.f : 0.f, 0.f));
|
||||
if (!ImGui::BeginPopup(popup_id))
|
||||
return;
|
||||
if (layer == nullptr) {
|
||||
ImGui::CloseCurrentPopup();
|
||||
@@ -4288,49 +4183,16 @@ void GLGizmoTextureDisplacement::render_texture_library_popup(const ImVec2 &pane
|
||||
m_tooltip_anchor_max = ImVec2(m_tooltip_anchor_min.x + ImGui::GetWindowSize().x,
|
||||
m_tooltip_anchor_min.y + ImGui::GetWindowSize().y);
|
||||
|
||||
// The header stays put while the grid scrolls under it: the title says what the popup is for, and the
|
||||
// close button is there for anyone who does not know that a click outside closes it.
|
||||
bool close_clicked = false;
|
||||
{
|
||||
ImDrawList *hdl = ImGui::GetWindowDrawList();
|
||||
const ImVec2 row = ImGui::GetCursorScreenPos();
|
||||
ImGui::SetCursorScreenPos(ImVec2(row.x, row.y + 0.5f * (frame_h - ImGui::GetTextLineHeight())));
|
||||
m_imgui->bold_text(_u8L("Choose a texture"));
|
||||
const ImVec2 btn(ImGui::GetWindowPos().x + ImGui::GetWindowContentRegionMax().x - frame_h, row.y);
|
||||
ImGui::SetCursorScreenPos(btn);
|
||||
close_clicked = ImGui::InvisibleButton("##close", ImVec2(frame_h, frame_h));
|
||||
const bool hot = ImGui::IsItemHovered();
|
||||
const ImVec2 c(btn.x + 0.5f * frame_h, btn.y + 0.5f * frame_h);
|
||||
const float k = std::round(0.18f * frame_h);
|
||||
const float line_w = std::max(1.f, std::round(m_imgui->scaled(0.08f)));
|
||||
const ImU32 x_col = ImGui::GetColorU32(ImGuiCol_Text, hot ? 1.f : 0.6f);
|
||||
if (hot)
|
||||
hdl->AddCircleFilled(c, 0.5f * frame_h, ImGui::GetColorU32(ImGuiCol_Text, 0.08f));
|
||||
hdl->AddLine(ImVec2(c.x - k, c.y - k), ImVec2(c.x + k, c.y + k), x_col, line_w);
|
||||
hdl->AddLine(ImVec2(c.x - k, c.y + k), ImVec2(c.x + k, c.y - k), x_col, line_w);
|
||||
ImGui::SetCursorScreenPos(ImVec2(row.x, row.y + frame_h + style.ItemSpacing.y));
|
||||
ImGui::Separator();
|
||||
}
|
||||
m_imgui->push_bold_font();
|
||||
m_imgui->text(_L("Choose a texture"));
|
||||
m_imgui->pop_bold_font();
|
||||
|
||||
const std::vector<TextureLibraryEntry> &library = texture_library();
|
||||
// A reinstalled pack can drop new bytes at a path already cached on this gizmo, and get_library_texture()
|
||||
// caches a failure as well as a success, so a moved generation makes every cached entry suspect.
|
||||
if (const uint64_t generation = texture_library_generation(); generation != m_library_generation) {
|
||||
m_library_textures.clear();
|
||||
m_library_generation = generation;
|
||||
}
|
||||
|
||||
// The grid scrolls as the panel body does: the same slim scrollbar, and the wheel eased by
|
||||
// ease_wheel_scroll() instead of ImGui's five-line jumps (hence NoScrollWithMouse).
|
||||
push_slim_scrollbar_style(scrollbar_w, wxGetApp().dark_mode());
|
||||
ImGui::BeginChild("##texture_grid", ImVec2(0.f, 0.f), false, ImGuiWindowFlags_NoScrollWithMouse);
|
||||
ease_wheel_scroll(m_picker_scroll_target, m_picker_scroll_applied);
|
||||
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList(); // the child's, so tiles clip to the grid
|
||||
std::optional<TextureLibraryEntry> chosen;
|
||||
std::optional<TextureLibraryEntry> to_remove;
|
||||
bool import_clicked = false;
|
||||
bool download_clicked = false;
|
||||
ImDrawList *dl = ImGui::GetWindowDrawList();
|
||||
const ImU32 selected_col = ImGui::GetColorU32(ImGuiWrapper::COL_ORCA);
|
||||
std::optional<TextureLibraryEntry> chosen;
|
||||
std::optional<TextureLibraryEntry> to_remove;
|
||||
bool import_clicked = false;
|
||||
|
||||
// Tiles are placed on the four-column grid explicitly rather than flowed with SameLine(): a user tile
|
||||
// overlays a remove button on its corner, and that button would otherwise be "the previous item" the
|
||||
@@ -4346,15 +4208,16 @@ void GLGizmoTextureDisplacement::render_texture_library_popup(const ImVec2 &pane
|
||||
ImGui::Dummy(ImVec2(grid_w, float(rows) * tile + float(rows - 1) * spacing));
|
||||
}
|
||||
};
|
||||
// One section's tiles, in the order the section holds them (shipped alphabetically, pack textures by
|
||||
// name, the user's own most recently used first - the order texture_library() produced); a user tile
|
||||
// carries a remove button on hover. Returns how many it drew.
|
||||
const auto grid = [&](const ImVec2 &origin, const std::vector<const TextureLibraryEntry *> &entries, bool removable) {
|
||||
// One group's tiles: shipped textures alphabetically, or the user's own most recently used first (the
|
||||
// order texture_library() keeps), those with a remove button on hover. Returns how many it drew.
|
||||
const auto grid = [&](const ImVec2 &origin, bool user) {
|
||||
int n = 0;
|
||||
for (const TextureLibraryEntry *entry : entries) {
|
||||
for (const TextureLibraryEntry &entry : library) {
|
||||
if (entry.is_user != user)
|
||||
continue;
|
||||
ImGui::SetCursorScreenPos(tile_pos(origin, n++));
|
||||
ImGui::PushID(entry->path.c_str());
|
||||
const LibraryTexture *tex = get_library_texture(entry->path);
|
||||
ImGui::PushID(entry.path.c_str());
|
||||
const LibraryTexture *tex = get_library_texture(entry.path);
|
||||
GLTexture *thumb = tex != nullptr ? tex->thumbnail.get() : nullptr;
|
||||
bool clicked = false;
|
||||
if (thumb != nullptr) {
|
||||
@@ -4372,27 +4235,15 @@ void GLGizmoTextureDisplacement::render_texture_library_popup(const ImVec2 &pane
|
||||
} else {
|
||||
clicked = ImGui::Button("?", ImVec2(tile, tile));
|
||||
}
|
||||
if (removable)
|
||||
if (user)
|
||||
ImGui::SetItemAllowOverlap(); // the remove button drawn over its corner takes its own clicks
|
||||
const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
|
||||
const bool current = entry->path == layer->path;
|
||||
const bool hovered = ImGui::IsItemHovered();
|
||||
// The layer's current texture carries an accent ring, and the tile under the pointer a thinner,
|
||||
// fainter one. Both are drawn inside the tile, where the grid's clip rect never cuts them.
|
||||
if (current || hovered) {
|
||||
const float w = current ? ring_w : std::round(0.5f * ring_w);
|
||||
dl->AddRect(ImVec2(a.x + 0.5f * w, a.y + 0.5f * w), ImVec2(b.x - 0.5f * w, b.y - 0.5f * w),
|
||||
ImGui::GetColorU32(current ? orca : ImVec4(orca.x, orca.y, orca.z, 0.6f)), 0.f, 0, w);
|
||||
}
|
||||
// Centred, as far as the scroll range allows, so the textures around it are in view too.
|
||||
if (current && m_picker_reveal_selected)
|
||||
ImGui::SetScrollFromPosY(0.5f * (a.y + b.y) - ImGui::GetWindowPos().y, 0.5f);
|
||||
if (hovered)
|
||||
panel_tooltip(entry->name);
|
||||
const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
|
||||
if (entry.path == layer->path)
|
||||
dl->AddRect(ImVec2(a.x - 1.f, a.y - 1.f), ImVec2(b.x + 1.f, b.y + 1.f), selected_col, 0.f, 0, 2.f);
|
||||
if (ImGui::IsItemHovered())
|
||||
panel_tooltip(entry.name);
|
||||
|
||||
// Clipped by the grid's clip rect, so a tile scrolled out of the grid or under its scrollbar
|
||||
// does not offer its remove button. IsMouseHoveringRect() clips by default.
|
||||
if (removable && ImGui::IsMouseHoveringRect(a, b)) {
|
||||
if (user && ImGui::IsMouseHoveringRect(a, b)) {
|
||||
const float r = std::round(tile * 0.17f);
|
||||
const ImVec2 c(b.x - r - 2.f, a.y + r + 2.f);
|
||||
ImGui::SetCursorScreenPos(ImVec2(c.x - r, c.y - r));
|
||||
@@ -4405,162 +4256,27 @@ void GLGizmoTextureDisplacement::render_texture_library_popup(const ImVec2 &pane
|
||||
if (hot)
|
||||
panel_tooltip(_u8L("Remove from My textures"));
|
||||
if (remove_clicked)
|
||||
to_remove = *entry;
|
||||
to_remove = entry;
|
||||
}
|
||||
ImGui::PopID();
|
||||
if (clicked)
|
||||
chosen = *entry;
|
||||
chosen = entry;
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
||||
// Every section collapses; the state is remembered for the app run. Pack keys use pack_name, a
|
||||
// capability name unique per type across loaded packages and stable across reinstalls. This function-local
|
||||
// static survives popup closes, never touches app_config, and resets on restart.
|
||||
static std::map<std::string, bool> s_section_collapsed; // true = collapsed; absent = expanded
|
||||
|
||||
const auto split_pack_title = [](const std::string &title) -> std::pair<std::string, std::string> {
|
||||
size_t split = std::string::npos;
|
||||
for (size_t i = 0; i + 3 < title.size(); ++i)
|
||||
if (title[i] == ' ' && (title[i + 1] == 'b' || title[i + 1] == 'B') &&
|
||||
(title[i + 2] == 'y' || title[i + 2] == 'Y') && title[i + 3] == ' ')
|
||||
split = i;
|
||||
if (split == std::string::npos)
|
||||
return { title, {} };
|
||||
|
||||
std::string name = title.substr(0, split);
|
||||
while (!name.empty() && std::isspace(static_cast<unsigned char>(name.back())))
|
||||
name.pop_back();
|
||||
std::string attribution = title.substr(split);
|
||||
size_t first = 0;
|
||||
while (first < attribution.size() && std::isspace(static_cast<unsigned char>(attribution[first])))
|
||||
++first;
|
||||
attribution.erase(0, first);
|
||||
if (name.empty() || attribution.empty())
|
||||
return { title, {} };
|
||||
return { name, attribution };
|
||||
};
|
||||
|
||||
// A section heading, one row as wide as the grid: a click anywhere on it collapses or expands the
|
||||
// section. Child headings indent their contents while keeping their counts right-aligned. Attribution
|
||||
// lines use a smaller disabled style; the grid follows closer than the next heading does.
|
||||
// Returns true when the section is open, so the caller knows whether to draw its contents.
|
||||
const auto section_header = [&](const std::string &key, const std::string &title, size_t count, float indent,
|
||||
const std::string &attribution, const std::string &full_title) {
|
||||
bool &collapsed = s_section_collapsed[key]; // default-inserts false -> expanded
|
||||
const ImVec2 row = ImGui::GetCursorScreenPos();
|
||||
const bool two_lines = !attribution.empty();
|
||||
const float line_h = ImGui::GetTextLineHeight();
|
||||
const float small_font_size = ImGui::GetFontSize() * 0.8f;
|
||||
const float small_line_h = line_h * 0.8f;
|
||||
const float row_h = two_lines ? std::max(frame_h, line_h + small_line_h + spacing) : frame_h;
|
||||
const ImVec2 row_max(row.x + grid_w, row.y + row_h);
|
||||
if (ImGui::InvisibleButton(key.c_str(), ImVec2(grid_w, row_h)))
|
||||
collapsed = !collapsed;
|
||||
const bool hovered = ImGui::IsItemHovered();
|
||||
if (hovered)
|
||||
dl->AddRectFilled(row, row_max, ImGui::GetColorU32(ImGuiCol_Text, 0.05f), style.FrameRounding);
|
||||
|
||||
const float inset = std::round(0.25f * frame_h);
|
||||
const float arrow = std::round(ImGui::GetFontSize() * 0.55f);
|
||||
const float cx = row.x + inset + indent + 0.5f * arrow;
|
||||
const float cy = row.y + 0.5f * row_h;
|
||||
const float hs = 0.3f * arrow;
|
||||
const ImU32 accent = ImGui::GetColorU32(orca);
|
||||
if (collapsed)
|
||||
dl->AddTriangleFilled(ImVec2(cx - 0.5f * hs, cy - hs), ImVec2(cx + 0.5f * hs, cy), ImVec2(cx - 0.5f * hs, cy + hs), accent);
|
||||
else
|
||||
dl->AddTriangleFilled(ImVec2(cx - hs, cy - 0.5f * hs), ImVec2(cx + hs, cy - 0.5f * hs), ImVec2(cx, cy + 0.5f * hs), accent);
|
||||
|
||||
const std::string n = std::to_string(count);
|
||||
const float n_w = ImGui::CalcTextSize(n.c_str()).x;
|
||||
const float tx = row.x + inset + indent + arrow + spacing;
|
||||
const float max_text_w = std::max(0.f, row_max.x - inset - n_w - spacing - tx);
|
||||
const std::string shown = ellipsize(title, max_text_w);
|
||||
const std::string shown_attribution = two_lines ? ellipsize(attribution, max_text_w, small_font_size) : std::string{};
|
||||
const float title_y = two_lines ? row.y + 0.5f * (row_h - line_h - small_line_h)
|
||||
: row.y + 0.5f * (frame_h - line_h);
|
||||
const float count_y = row.y + 0.5f * (row_h - line_h);
|
||||
dl->AddText(ImVec2(tx, title_y), ImGui::GetColorU32(ImGuiCol_Text), shown.c_str());
|
||||
if (two_lines)
|
||||
dl->AddText(ImGui::GetFont(), small_font_size, ImVec2(tx, title_y + line_h),
|
||||
ImGui::GetColorU32(ImGuiCol_TextDisabled), shown_attribution.c_str());
|
||||
dl->AddText(ImVec2(row_max.x - inset - n_w, count_y), ImGui::GetColorU32(ImGuiCol_TextDisabled), n.c_str());
|
||||
if (hovered && (shown != title || shown_attribution != attribution))
|
||||
panel_tooltip(full_title); // a long plugin-supplied name, cut by the fixed width
|
||||
ImGui::SetCursorScreenPos(ImVec2(row.x, row_max.y + spacing));
|
||||
return !collapsed;
|
||||
};
|
||||
|
||||
// Built-in is first, plugin packs are grouped under Texture libraries, and My
|
||||
// textures stays last so its import tile and help line describe that group. Pack names identify both
|
||||
// their child section and state.
|
||||
struct Section
|
||||
ImGui::TextDisabled("%s", _u8L("Built-in").c_str());
|
||||
{
|
||||
std::string key;
|
||||
std::string title;
|
||||
std::vector<const TextureLibraryEntry *> entries;
|
||||
};
|
||||
std::vector<Section> sections;
|
||||
std::map<std::string, size_t> pack_section; // pack_name -> index in `sections`
|
||||
sections.push_back({ "builtin:", _u8L("Built-in"), {} });
|
||||
for (const TextureLibraryEntry &entry : library) {
|
||||
if (entry.source == TextureSource::Shipped) {
|
||||
sections.front().entries.push_back(&entry); // the section exists even when the library is empty
|
||||
continue;
|
||||
}
|
||||
if (entry.source == TextureSource::User)
|
||||
continue; // added below, so My textures stays last
|
||||
if (entry.source != TextureSource::Plugin)
|
||||
continue;
|
||||
const auto [it, inserted] = pack_section.emplace(entry.pack_name, sections.size());
|
||||
if (inserted)
|
||||
sections.push_back({ "pack:" + entry.pack_name, entry.pack_name, {} });
|
||||
sections[it->second].entries.push_back(&entry);
|
||||
}
|
||||
sections.push_back({ "user:", _u8L("My textures"), {} });
|
||||
for (const TextureLibraryEntry &entry : library)
|
||||
if (entry.source == TextureSource::User)
|
||||
sections.back().entries.push_back(&entry);
|
||||
|
||||
const float child_indent = std::round(m_imgui->scaled(0.8f));
|
||||
const Section &built_in = sections.front();
|
||||
if (section_header(built_in.key, built_in.title, built_in.entries.size(), 0.f, {}, built_in.title)) {
|
||||
const ImVec2 origin = ImGui::GetCursorScreenPos();
|
||||
const int count = grid(origin, built_in.entries, false);
|
||||
const int count = grid(origin, false);
|
||||
end_grid(origin, count);
|
||||
if (count == 0)
|
||||
ImGui::TextDisabled("%s", _u8L("No textures found.").c_str());
|
||||
}
|
||||
|
||||
size_t subscribed_count = 0;
|
||||
for (size_t i = 1; i + 1 < sections.size(); ++i)
|
||||
subscribed_count += sections[i].entries.size();
|
||||
|
||||
const std::string subscribed_title = _u8L("Texture libraries");
|
||||
if (section_header("subscribed:", subscribed_title, subscribed_count, 0.f, {}, subscribed_title)) {
|
||||
for (size_t i = 1; i + 1 < sections.size(); ++i) {
|
||||
const Section &pack = sections[i];
|
||||
const auto [name, attribution] = split_pack_title(pack.title);
|
||||
if (!section_header(pack.key, name, pack.entries.size(), child_indent, attribution, pack.title))
|
||||
continue;
|
||||
const ImVec2 origin = ImGui::GetCursorScreenPos();
|
||||
const int count = grid(origin, pack.entries, false);
|
||||
end_grid(origin, count);
|
||||
}
|
||||
|
||||
ImGui::Dummy(ImVec2(0.f, spacing));
|
||||
const std::string download_label = _u8L("Explore more texture libraries");
|
||||
if (ImGui::Button(download_label.c_str(), ImVec2(grid_w, frame_h)))
|
||||
download_clicked = true;
|
||||
if (ImGui::IsItemHovered())
|
||||
panel_tooltip(_u8L("Opens OrcaCloud in the Home page to browse for plugins."));
|
||||
}
|
||||
|
||||
const Section &user = sections.back();
|
||||
if (section_header(user.key, user.title, user.entries.size(), 0.f, {}, user.title)) {
|
||||
ImGui::TextDisabled("%s", _u8L("My textures").c_str());
|
||||
{
|
||||
const ImVec2 origin = ImGui::GetCursorScreenPos();
|
||||
const int count = grid(origin, user.entries, true);
|
||||
const int count = grid(origin, true);
|
||||
ImGui::SetCursorScreenPos(tile_pos(origin, count));
|
||||
if (ImGui::Button("+##import_texture", ImVec2(tile, tile)))
|
||||
import_clicked = true;
|
||||
@@ -4569,25 +4285,17 @@ void GLGizmoTextureDisplacement::render_texture_library_popup(const ImVec2 &pane
|
||||
"bakes from and saved to your personal texture folder, kept separate from the "
|
||||
"textures shipped with OrcaSlicer."));
|
||||
end_grid(origin, count + 1);
|
||||
// Belongs to this section: it describes the import tile and the remove-on-hover tiles, both of
|
||||
// which live here, so it is hidden with them rather than left describing controls off-screen.
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + grid_w);
|
||||
ImGui::TextDisabled("%s", _u8L("PNG, JPG or BMP - converted to a height map on import. Hover one of yours to remove it.").c_str());
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
// Done whether or not the current texture was drawn: one in a collapsed section stays where it is.
|
||||
m_picker_reveal_selected = false;
|
||||
ImGui::EndChild();
|
||||
pop_slim_scrollbar_style();
|
||||
|
||||
if (chosen || import_clicked || close_clicked || download_clicked)
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + grid_w);
|
||||
ImGui::TextDisabled("%s", _u8L("PNG, JPG or BMP - converted to a height map on import. Hover one of yours to remove it.").c_str());
|
||||
ImGui::PopTextWrapPos();
|
||||
|
||||
if (chosen || import_clicked)
|
||||
ImGui::CloseCurrentPopup();
|
||||
m_tooltip_anchor_min = prev_anchor_min;
|
||||
m_tooltip_anchor_max = prev_anchor_max;
|
||||
ImGui::EndPopup();
|
||||
// The OrcaCloud plugin hub filtered to resource textures; the pane's session handoff redirects here.
|
||||
if (download_clicked)
|
||||
wxGetApp().open_orca_cloud("/app/plugins/plugin-hub?types=resource-textures");
|
||||
|
||||
// Only once the loop over the library is done: importing, picking (which reorders the recently used)
|
||||
// and removing all change the library the loop was iterating.
|
||||
@@ -5655,7 +5363,7 @@ std::vector<GLGizmoTextureDisplacement::PaletteEntry> GLGizmoTextureDisplacement
|
||||
std::vector<PaletteEntry> candidates;
|
||||
for (int i = 0; i < n; ++i)
|
||||
for (int j = i + 1; j < n; ++j)
|
||||
for (int den = 2; den <= 6; ++den)
|
||||
for (int den = 2; den <= MIX_MAX_DENOMINATOR; ++den)
|
||||
for (int num = 1; num < den; ++num) {
|
||||
if (std::gcd(num, den) != 1)
|
||||
continue; // 2/4 is 1/2, already there
|
||||
@@ -5694,6 +5402,8 @@ std::vector<GLGizmoTextureDisplacement::PaletteEntry> GLGizmoTextureDisplacement
|
||||
std::vector<float> current = pure_d;
|
||||
std::vector<char> taken(nc, 0);
|
||||
std::vector<PaletteEntry> out;
|
||||
// Set from the first mix taken, so the floor is read off this texture rather than assumed.
|
||||
double floor_gain = 0.;
|
||||
const auto counts = [&](size_t c, size_t t) {
|
||||
const float d = dist[c * nt + t];
|
||||
return d < current[t] && d <= pure_d[t] - PREFER_PURE_DE;
|
||||
@@ -5713,8 +5423,11 @@ std::vector<GLGizmoTextureDisplacement::PaletteEntry> GLGizmoTextureDisplacement
|
||||
best = c;
|
||||
}
|
||||
}
|
||||
if (best == nc || best_gain < double(MIN_MIX_GAIN))
|
||||
// Nothing left that helps, or the remaining mixes are noise beside the first one.
|
||||
if (best == nc || best_gain <= 0. || best_gain < floor_gain)
|
||||
break;
|
||||
if (out.empty())
|
||||
floor_gain = best_gain * MIN_MIX_GAIN_FRACTION;
|
||||
taken[best] = 1;
|
||||
out.push_back(candidates[best]);
|
||||
for (size_t t = 0; t < nt; ++t)
|
||||
@@ -6890,6 +6603,19 @@ void GLGizmoTextureDisplacement::on_render_input_window(float x, float y, float
|
||||
m_imgui->text(text);
|
||||
m_imgui->pop_bold_font();
|
||||
};
|
||||
// Cuts a UTF-8 string down to `max_w` pixels, ending it in "..." when it had to be cut.
|
||||
const auto ellipsize = [](std::string s, float max_w) {
|
||||
if (ImGui::CalcTextSize(s.c_str()).x <= max_w)
|
||||
return s;
|
||||
while (!s.empty() && ImGui::CalcTextSize((s + "...").c_str()).x > max_w) {
|
||||
unsigned char c;
|
||||
do { // a whole code point at a time
|
||||
c = static_cast<unsigned char>(s.back());
|
||||
s.pop_back();
|
||||
} while (!s.empty() && (c & 0xC0) == 0x80);
|
||||
}
|
||||
return s + "...";
|
||||
};
|
||||
// Label column + a slider filling the rest of the row, value printed inside the track.
|
||||
// `right_inset` keeps a layer card's inner padding.
|
||||
const auto slider_label = [&](const wxString &label) {
|
||||
@@ -7082,11 +6808,52 @@ void GLGizmoTextureDisplacement::on_render_input_window(float x, float y, float
|
||||
style.WindowPadding.y - style.ItemSpacing.y);
|
||||
const float body_h = m_panel_body_h > 0.f ? std::min(m_panel_body_h + 1.f, max_body_h) : max_body_h;
|
||||
|
||||
push_slim_scrollbar_style(m_imgui->scaled(0.5f), dark);
|
||||
// NoScrollWithMouse: ease_wheel_scroll() eases the scroll instead of teleporting five text lines per
|
||||
// notch, which on blocks this tall lost the reader's place.
|
||||
// ImGui's stock scrollbar is a wide, square-cornered slab in a tinted track - against this flat panel
|
||||
// it reads as a raw widget bolted onto the edge. Slim it to a rounded thumb over an invisible track.
|
||||
const float scrollbar_w = m_imgui->scaled(0.5f);
|
||||
const ImVec4 grab = dark ? ImVec4(1.f, 1.f, 1.f, 0.26f) : ImVec4(0.f, 0.f, 0.f, 0.26f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, scrollbar_w);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarRounding, 0.5f * scrollbar_w);
|
||||
ImGui::PushStyleColor(ImGuiCol_ScrollbarBg, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrab, grab);
|
||||
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabHovered, ImVec4(grab.x, grab.y, grab.z, 0.45f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ScrollbarGrabActive, ImVec4(grab.x, grab.y, grab.z, 0.65f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.f, 0.f, 0.f, 0.f));
|
||||
// NoScrollWithMouse: the wheel is handled below so the scroll can be eased instead of teleporting
|
||||
// five text lines per notch, which on blocks this tall lost the reader's place.
|
||||
ImGui::BeginChild("##td_body", ImVec2(panel_w, body_h), false, ImGuiWindowFlags_NoScrollWithMouse);
|
||||
ease_wheel_scroll(m_panel_scroll_target, m_panel_scroll_applied);
|
||||
{
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
const float scroll_now = ImGui::GetScrollY();
|
||||
const float scroll_max = ImGui::GetScrollMaxY();
|
||||
|
||||
// Anything that moved the scroll without us - dragging the grab, a keyboard/gamepad nav step, the
|
||||
// content shrinking under a clamped offset - has to re-seed the target, or the easing below would
|
||||
// immediately drag the view back to where it last animated to.
|
||||
if (m_panel_scroll_applied < 0.f || std::abs(scroll_now - m_panel_scroll_applied) > 0.5f)
|
||||
m_panel_scroll_target = scroll_now;
|
||||
|
||||
if (io.MouseWheel != 0.f && ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))
|
||||
m_panel_scroll_target -= io.MouseWheel * ImGui::GetFontSize() * 4.f;
|
||||
// Whole pixels: ImGui floors whatever SetScrollY() is given, so a fractional target could never be
|
||||
// reached and the "still gliding" test below would stay true forever, repainting the canvas for good.
|
||||
m_panel_scroll_target = std::floor(std::clamp(m_panel_scroll_target, 0.f, scroll_max));
|
||||
|
||||
const float delta = m_panel_scroll_target - scroll_now;
|
||||
if (std::abs(delta) >= 1.f) {
|
||||
// Exponential ease, formulated against the frame time so the glide takes the same wall time
|
||||
// whether the canvas is running at 30 or 144 fps. The last sub-pixel step would be floored
|
||||
// away, so land on the target outright once the remainder is that small.
|
||||
const float t = 1.f - std::exp(-20.f * std::clamp(io.DeltaTime, 1.f / 240.f, 1.f / 15.f));
|
||||
const float step = (std::abs(delta * t) < 1.f) ? delta : delta * t;
|
||||
const float next = std::floor(scroll_now + step);
|
||||
ImGui::SetScrollY(next);
|
||||
m_panel_scroll_applied = next;
|
||||
m_parent.set_as_dirty(); // nothing else would redraw mid-glide once the mouse stops
|
||||
} else {
|
||||
m_panel_scroll_applied = scroll_now;
|
||||
}
|
||||
}
|
||||
|
||||
// Everything that changes the layer list is deferred until the list is no longer being drawn:
|
||||
// removing or reordering shifts mv->texture_displacement_layers under the pointers the loop holds,
|
||||
@@ -7331,9 +7098,8 @@ void GLGizmoTextureDisplacement::on_render_input_window(float x, float y, float
|
||||
|
||||
// Opens the texture library for a layer, making it the active one too (after the loop).
|
||||
const auto open_picker = [&](int slot) {
|
||||
m_picker_slot = slot;
|
||||
m_picker_open_request = true;
|
||||
m_picker_reveal_selected = true;
|
||||
m_picker_slot = slot;
|
||||
m_picker_open_request = true;
|
||||
};
|
||||
// The six-dot drag icon, drawn into `list` over [x, x + w] x [y, y + h].
|
||||
const auto draw_drag_icon = [&](ImDrawList *list, float x, float y, float w, float h, ImU32 tint) {
|
||||
@@ -7609,8 +7375,9 @@ void GLGizmoTextureDisplacement::on_render_input_window(float x, float y, float
|
||||
// physical filaments.
|
||||
const int max_mixes = std::max(1, int(EnforcerBlockerType::ExtruderMax) - int(m_palette_filaments.size()));
|
||||
if (int_row("##color_mix_count", _L("Mixed colors"), &opts.color_mix_count, 1, max_mixes, "%d", card_pad,
|
||||
_L("The most mixed filaments a bake may add. They are picked from the "
|
||||
"texture's colors, and only the ones the bake actually uses are created."),
|
||||
_L("The most mixed filaments a bake may add - a ceiling, not a count. They "
|
||||
"are picked from the texture's colors, so a texture the filaments already "
|
||||
"cover gets fewer, and only the ones the bake actually uses are created."),
|
||||
{ { "mixed_colors_few.png", _L("Few") }, { "mixed_colors_many.png", _L("Many") } }))
|
||||
m_preview_params_dirty = true;
|
||||
// After the slider, so a change shows in the same frame.
|
||||
@@ -7621,6 +7388,27 @@ void GLGizmoTextureDisplacement::on_render_input_window(float x, float y, float
|
||||
// TRN %1% is the number of printable colors, %2% is "from N filaments".
|
||||
ImGui::TextDisabled("%s", Slic3r::format(into_u8(_L_PLURAL("%1% printable color %2%", "%1% printable colors %2%", n_colors)),
|
||||
n_colors, from_filaments).c_str());
|
||||
// Two reasons the palette can hold fewer mixes than the setting asks for, and both
|
||||
// used to be silent, leaving the user raising a number that changed nothing. A
|
||||
// flat-color image is matched against the filaments alone, so it gets none at all;
|
||||
// otherwise the ranking stops once another mix would no longer noticeably improve
|
||||
// the match.
|
||||
const int n_mixes = std::max(0, n_colors - n_filaments);
|
||||
if (n_mixes < opts.color_mix_count) {
|
||||
const bool flat = std::any_of(mv->texture_displacement_layers.begin(),
|
||||
mv->texture_displacement_layers.end(),
|
||||
[](const TextureDisplacementLayer &l) {
|
||||
return l.color_enabled && !l.empty() &&
|
||||
height_texture_has_color(l) &&
|
||||
analyze_texture_detail(l).flat_colors;
|
||||
});
|
||||
ImGui::PushTextWrapPos(content_rx - card_pad);
|
||||
ImGui::TextDisabled("%s", flat ?
|
||||
_u8L("Flat-color image: each color prints in one filament, so no mixes are used.").c_str() :
|
||||
Slic3r::format(_u8L("This texture uses %1% of them - more mixes would not "
|
||||
"change the result."), n_mixes).c_str());
|
||||
ImGui::PopTextWrapPos();
|
||||
}
|
||||
}
|
||||
if (int_row("##color_despeckle", _L("Denoise"), &opts.color_despeckle, 0, 6, "%d", card_pad,
|
||||
_L("Cleans up single stray triangles of the wrong color, which detail finer "
|
||||
@@ -8328,7 +8116,8 @@ void GLGizmoTextureDisplacement::on_render_input_window(float x, float y, float
|
||||
// height of everything above, whether or not it is scrolled.
|
||||
m_panel_body_h = ImGui::GetCursorPosY() - style.ItemSpacing.y;
|
||||
ImGui::EndChild();
|
||||
pop_slim_scrollbar_style();
|
||||
ImGui::PopStyleColor(5);
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
// The layer-list changes deferred from the loop above.
|
||||
if (slot_to_remove >= 0)
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
// actually pick it. Stops early once another mix would make no noticeable difference, so a texture
|
||||
// the filaments already cover gets few mixes or none.
|
||||
//
|
||||
// Ratios are the short-cycle ones (k/d for d up to 6): the slicer interleaves a mix layer by layer,
|
||||
// Ratios are k/d for d up to MIX_MAX_DENOMINATOR: the slicer interleaves a mix layer by layer,
|
||||
// and a long cycle prints as visible bands rather than as a colour. A mix's `rgb` is the colour its
|
||||
// mixed filament slot will show (blend_color_multi(), as the sidebar computes it), so the match, the
|
||||
// preview and the slot all agree on what the mix looks like.
|
||||
@@ -428,10 +428,6 @@ private:
|
||||
void render_texture_library_popup(const ImVec2 &panel_min, const ImVec2 &panel_max);
|
||||
int m_picker_slot = -1;
|
||||
bool m_picker_open_request = false;
|
||||
// Set when the popup opens, so the next layout scrolls the layer's current texture into view.
|
||||
bool m_picker_reveal_selected = false;
|
||||
float m_picker_scroll_target = 0.f; // see ease_wheel_scroll()
|
||||
float m_picker_scroll_applied = -1.f;
|
||||
void set_layer_texture(TextureDisplacementLayer &layer, const TextureLibraryEntry &entry);
|
||||
void import_custom_texture(TextureDisplacementLayer &layer);
|
||||
|
||||
@@ -1066,8 +1062,6 @@ private:
|
||||
|
||||
// Library textures the picker has shown at least once, keyed by file path (see LibraryTexture).
|
||||
std::map<std::string, LibraryTexture> m_library_textures;
|
||||
// Generation of the library the above were cached against; a change clears them.
|
||||
uint64_t m_library_generation = 0;
|
||||
|
||||
// Everything the *unwrap* depends on. update_uv_editor() runs from rebuild_preview(), i.e. on
|
||||
// every stroke end and every slider release - but depth/tiling/rotation/offset/blend change
|
||||
@@ -1109,15 +1103,12 @@ private:
|
||||
// The config key behind m_undocked.
|
||||
static constexpr const char *UNDOCKED_CONFIG_KEY = "texture_displacement_panel_undocked";
|
||||
|
||||
// Smooth scrolling for a child window, called inside it: the panel body (everything between the header
|
||||
// and the pinned Bake footer) and the texture library's grid. ImGui jumps a fixed number of lines per
|
||||
// wheel notch, which on tall layer cards reads as a hard jolt rather than a scroll. The child sets
|
||||
// ImGuiWindowFlags_NoScrollWithMouse, and the wheel moves `target` instead; the real scroll is eased
|
||||
// toward it over the following frames. `applied` is what the easing wrote last frame, <0 until the
|
||||
// first one.
|
||||
void ease_wheel_scroll(float &target, float &applied);
|
||||
// Smooth scrolling for the panel body (everything between the header and the pinned Bake footer).
|
||||
// ImGui jumps a fixed number of lines per wheel notch, which on tall layer cards reads as a hard
|
||||
// jolt rather than a scroll. The wheel is intercepted (ImGuiWindowFlags_NoScrollWithMouse) and
|
||||
// moves a *target* offset instead; the real scroll is eased toward it over the following frames.
|
||||
float m_panel_scroll_target = 0.f;
|
||||
float m_panel_scroll_applied = -1.f;
|
||||
float m_panel_scroll_applied = -1.f; // what the easing wrote last frame; <0 until the first one
|
||||
// Last frame's body content height and footer height. The body is a child window that has to be
|
||||
// given its height before its content is laid out, so it is sized from the previous frame: as tall
|
||||
// as its content, capped so the footer still fits above the bottom of the canvas.
|
||||
|
||||
@@ -505,12 +505,10 @@ bool ImGuiWrapper::update_mouse_data(wxMouseEvent& evt)
|
||||
io.MouseDown[0] = evt.LeftIsDown();
|
||||
io.MouseDown[1] = evt.RightIsDown();
|
||||
io.MouseDown[2] = evt.MiddleIsDown();
|
||||
// Only a vertical wheel event with a direction is a wheel step. A macOS trackpad reports sideways motion
|
||||
// as separate horizontal events, and its wheel events often carry a rotation of 0: wx truncates the
|
||||
// sub-pixel deltas to whole ones and passes on events with no delta at all. Read as vertical steps,
|
||||
// either kind scrolls against the gesture, and scrolling up bounces back and forth.
|
||||
if (evt.GetWheelAxis() == wxMOUSE_WHEEL_VERTICAL && evt.GetWheelRotation() != 0)
|
||||
float wheel_delta = static_cast<float>(evt.GetWheelDelta());
|
||||
if (wheel_delta != 0.0f) {
|
||||
io.MouseWheel = evt.GetWheelRotation() > 0 ? 1.f : -1.f;
|
||||
}
|
||||
unsigned buttons = (evt.LeftIsDown() ? 1 : 0) | (evt.RightIsDown() ? 2 : 0) | (evt.MiddleIsDown() ? 4 : 0);
|
||||
m_mouse_buttons = buttons;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "TextureLibrary.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <cstddef>
|
||||
#include <boost/filesystem/directory.hpp>
|
||||
@@ -22,7 +21,6 @@
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#include <vector>
|
||||
#include <wx/app.h>
|
||||
#include <wx/gdicmn.h>
|
||||
#include <utility>
|
||||
#include <wx/image.h>
|
||||
@@ -38,9 +36,6 @@
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
#include "slic3r/GUI/I18N.hpp"
|
||||
|
||||
#include "slic3r/plugin/PluginFsUtils.hpp"
|
||||
#include "slic3r/plugin/host/PluginResourceTextures.hpp"
|
||||
|
||||
namespace Slic3r::GUI {
|
||||
|
||||
namespace {
|
||||
@@ -55,7 +50,7 @@ bool is_image_file(const boost::filesystem::path &path)
|
||||
return ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".bmp";
|
||||
}
|
||||
|
||||
void scan_dir(const boost::filesystem::path &dir, TextureSource source, std::vector<TextureLibraryEntry> &out)
|
||||
void scan_dir(const boost::filesystem::path &dir, bool is_user, std::vector<TextureLibraryEntry> &out)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
if (!boost::filesystem::is_directory(dir, ec))
|
||||
@@ -65,43 +60,12 @@ void scan_dir(const boost::filesystem::path &dir, TextureSource source, std::vec
|
||||
for (boost::filesystem::directory_iterator it(dir, ec), end; it != end && !ec; it.increment(ec)) {
|
||||
if (!boost::filesystem::is_regular_file(it->path(), ec) || !is_image_file(it->path()))
|
||||
continue;
|
||||
out.push_back({ it->path().stem().string(), it->path().string(), source });
|
||||
out.push_back({ it->path().stem().string(), it->path().string(), is_user });
|
||||
}
|
||||
std::sort(out.begin() + first, out.end(),
|
||||
[](const TextureLibraryEntry &a, const TextureLibraryEntry &b) { return a.name < b.name; });
|
||||
}
|
||||
|
||||
// Appends every loaded pack's textures, ordered by the pack's display name and then by file name. Each
|
||||
// entry carries the contributing pack's display name, which the picker uses to group a pack's textures
|
||||
// into one section; a pack name is unique among loaded packs of this capability type, so the name both
|
||||
// groups the section and keeps its entries contiguous. A pack whose directory fails validation is
|
||||
// skipped, so one bad pack never hides the others.
|
||||
void scan_plugin_textures(std::vector<TextureLibraryEntry> &out)
|
||||
{
|
||||
std::vector<TextureLibraryEntry> found;
|
||||
for (const ResourceTextureEntry &pack : PluginResourceTextures::instance().entries()) {
|
||||
std::string error;
|
||||
const std::vector<std::string> files =
|
||||
collect_resource_texture_files(pack.texture_dir, pack.plugin_root, error);
|
||||
if (!error.empty()) {
|
||||
BOOST_LOG_TRIVIAL(warning) << "Texture pack '" << pack.display_name << "' was skipped: " << error;
|
||||
continue;
|
||||
}
|
||||
for (const std::string &file : files) {
|
||||
const boost::filesystem::path path(file);
|
||||
found.push_back({ path.stem().string(), file, TextureSource::Plugin, pack.display_name });
|
||||
}
|
||||
}
|
||||
|
||||
std::stable_sort(found.begin(), found.end(), [](const TextureLibraryEntry &a, const TextureLibraryEntry &b) {
|
||||
if (a.pack_name != b.pack_name)
|
||||
return a.pack_name < b.pack_name;
|
||||
return a.name < b.name;
|
||||
});
|
||||
for (TextureLibraryEntry &entry : found)
|
||||
out.push_back(std::move(entry));
|
||||
}
|
||||
|
||||
// True if the image carries any colour at all, i.e. some pixel's channels are not all equal. A
|
||||
// photo saved as RGB but actually grey should still be stored as a grayscale PNG - it is a third of
|
||||
// the bytes, and the colour feature keys off has_color(), so storing a grey image as RGB would offer
|
||||
@@ -244,11 +208,6 @@ bool is_supported_height_map(const std::vector<unsigned char> &bytes)
|
||||
|
||||
std::vector<TextureLibraryEntry> g_library;
|
||||
bool g_library_scanned = false;
|
||||
// The generation g_library was last built from, so texture_library() can rescan after a pack change.
|
||||
uint64_t g_library_scan_generation = 0;
|
||||
|
||||
// Bumped by plugin callbacks, read by the GUI frame. Atomic so a read never races a write.
|
||||
std::atomic<uint64_t> g_library_generation{ 0 };
|
||||
|
||||
// Writes `bytes` into the user's own texture folder as `stem`.png, uniquified so an existing texture -
|
||||
// shipped-name collision, or a second edit of the same source - is never overwritten. Returns the new
|
||||
@@ -296,8 +255,6 @@ const size_t RECENT_MAX = 200;
|
||||
std::vector<std::string> recent_texture_names()
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
if (wxTheApp == nullptr) // headless or shutting down: there is no app config to read
|
||||
return names;
|
||||
if (wxGetApp().app_config == nullptr)
|
||||
return names;
|
||||
const std::string value = wxGetApp().app_config->get(RECENT_SECTION, RECENT_KEY);
|
||||
@@ -312,8 +269,6 @@ std::vector<std::string> recent_texture_names()
|
||||
|
||||
void store_recent_texture_names(std::vector<std::string> names)
|
||||
{
|
||||
if (wxTheApp == nullptr) // headless or shutting down: there is no app config to write
|
||||
return;
|
||||
if (wxGetApp().app_config == nullptr)
|
||||
return;
|
||||
if (names.size() > RECENT_MAX)
|
||||
@@ -324,9 +279,8 @@ void store_recent_texture_names(std::vector<std::string> names)
|
||||
wxGetApp().app_config->set(RECENT_SECTION, RECENT_KEY, value);
|
||||
}
|
||||
|
||||
// Reorders the user's entries by recent use. Stable, so textures never used keep the name order
|
||||
// scan_dir() gave them, after every used one. Only the user's own range is touched: shipped and pack
|
||||
// entries must keep the order their scans produced.
|
||||
// Reorders the user's entries (the tail of `library`) by recent use. Stable, so textures never used keep
|
||||
// the name order scan_dir() gave them, after every used one.
|
||||
void sort_user_textures(std::vector<TextureLibraryEntry> &library)
|
||||
{
|
||||
const std::vector<std::string> names = recent_texture_names();
|
||||
@@ -337,11 +291,8 @@ void sort_user_textures(std::vector<TextureLibraryEntry> &library)
|
||||
const auto it = rank.find(boost::filesystem::path(e.path).filename().string());
|
||||
return it == rank.end() ? std::numeric_limits<int>::max() : it->second;
|
||||
};
|
||||
const auto first_user = std::find_if(library.begin(), library.end(),
|
||||
[](const TextureLibraryEntry &e) { return e.source == TextureSource::User; });
|
||||
const auto user_end = std::find_if(first_user, library.end(),
|
||||
[](const TextureLibraryEntry &e) { return e.source != TextureSource::User; });
|
||||
std::stable_sort(first_user, user_end,
|
||||
const auto first_user = std::find_if(library.begin(), library.end(), [](const TextureLibraryEntry &e) { return e.is_user; });
|
||||
std::stable_sort(first_user, library.end(),
|
||||
[&rank_of](const TextureLibraryEntry &a, const TextureLibraryEntry &b) { return rank_of(a) < rank_of(b); });
|
||||
}
|
||||
|
||||
@@ -360,16 +311,6 @@ bool in_user_texture_dir(const std::string &path)
|
||||
|
||||
} // namespace
|
||||
|
||||
uint64_t texture_library_generation()
|
||||
{
|
||||
return g_library_generation.load();
|
||||
}
|
||||
|
||||
void bump_texture_library_generation()
|
||||
{
|
||||
g_library_generation.fetch_add(1);
|
||||
}
|
||||
|
||||
std::string user_texture_dir()
|
||||
{
|
||||
const boost::filesystem::path dir = boost::filesystem::path(Slic3r::data_dir()) / "textures" / "displacement";
|
||||
@@ -384,20 +325,17 @@ std::string user_texture_dir()
|
||||
|
||||
const std::vector<TextureLibraryEntry> &texture_library(bool force_rescan)
|
||||
{
|
||||
const uint64_t generation = texture_library_generation();
|
||||
if (g_library_scanned && !force_rescan && generation == g_library_scan_generation)
|
||||
if (g_library_scanned && !force_rescan)
|
||||
return g_library;
|
||||
|
||||
g_library.clear();
|
||||
scan_dir(boost::filesystem::path(Slic3r::resources_dir()) / "textures" / "displacement", TextureSource::Shipped, g_library);
|
||||
scan_dir(boost::filesystem::path(Slic3r::resources_dir()) / "textures" / "displacement", false, g_library);
|
||||
const std::string user_dir = user_texture_dir();
|
||||
if (!user_dir.empty())
|
||||
scan_dir(boost::filesystem::path(user_dir), TextureSource::User, g_library);
|
||||
scan_dir(boost::filesystem::path(user_dir), true, g_library);
|
||||
sort_user_textures(g_library);
|
||||
scan_plugin_textures(g_library);
|
||||
|
||||
g_library_scan_generation = generation;
|
||||
g_library_scanned = true;
|
||||
g_library_scanned = true;
|
||||
return g_library;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef slic3r_TextureLibrary_hpp_
|
||||
#define slic3r_TextureLibrary_hpp_
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -11,45 +10,26 @@
|
||||
|
||||
namespace Slic3r::GUI {
|
||||
|
||||
// Where a library texture came from. The picker lists each source under its own heading.
|
||||
enum class TextureSource { Shipped, User, Plugin };
|
||||
|
||||
// One selectable height-map texture in the texture-displacement gizmo's texture picker. A texture that
|
||||
// came from a plugin pack also carries the provenance the picker groups its sections by.
|
||||
// One selectable height-map texture in the texture-displacement gizmo's texture picker.
|
||||
struct TextureLibraryEntry
|
||||
{
|
||||
std::string name; // display name (the file's stem, e.g. "Wood Grain")
|
||||
std::string path; // absolute path on disk
|
||||
TextureSource source; // which of the three sources it came from
|
||||
|
||||
std::string pack_name; // contributing pack's display name; empty for Shipped and User
|
||||
std::string name; // display name (the file's stem, e.g. "Wood Grain")
|
||||
std::string path; // absolute path on disk
|
||||
bool is_user; // imported by the user, as opposed to shipped with OrcaSlicer
|
||||
};
|
||||
|
||||
// Every available height-map texture, in the order the picker lists them: the ones shipped in
|
||||
// resources/textures/displacement first, by name; then the user's own from <data_dir>/textures/displacement,
|
||||
// most recently used first (see touch_user_texture()) and the rest by name; then the loaded texture
|
||||
// packs, ordered by pack display name and then by file name.
|
||||
// Every available height-map texture: the ones shipped in resources/textures/displacement first, sorted
|
||||
// by name, then the user's own from <data_dir>/textures/displacement - most recently used first (see
|
||||
// touch_user_texture()), then any never used, by name.
|
||||
//
|
||||
// The shipped and user textures live in separate directories deliberately: an app update replaces the
|
||||
// resources tree wholesale, so anything the user imported has to sit somewhere that update can never
|
||||
// overwrite or delete. Pack textures are read-only like the shipped ones. Every texture carries its
|
||||
// `source`; a pack texture also carries `pack_name`, and the picker groups pack textures into one
|
||||
// collapsible section per pack name. A pack's name is unique among loaded packs of this capability type -
|
||||
// the loader refuses a collision with "Capability collision for type ... and name ...", see
|
||||
// PluginManager::check_registry_locked (PluginManager.cpp:211-225) - so the name on its own identifies a
|
||||
// section and keeps that pack's entries contiguous.
|
||||
// The two live in separate directories deliberately: an app update replaces the resources tree
|
||||
// wholesale, so anything the user imported has to sit somewhere that update can never overwrite or
|
||||
// delete. `is_user` is what the picker uses to show them under separate headings.
|
||||
//
|
||||
// Scanned once and cached. Pass force_rescan after an import, or to pick up a file the user dropped
|
||||
// into either folder by hand while the app was running. A rescan also happens on its own when the pack
|
||||
// registry changes, which is what texture_library_generation() tracks.
|
||||
// into either folder by hand while the app was running.
|
||||
const std::vector<TextureLibraryEntry> &texture_library(bool force_rescan = false);
|
||||
|
||||
// Monotonic counter, bumped whenever the set of loaded texture packs changes. The GUI reads it to
|
||||
// decide whether texture_library() must rescan, and plugin callbacks bump it. Safe to read from any
|
||||
// thread at any time.
|
||||
uint64_t texture_library_generation();
|
||||
void bump_texture_library_generation();
|
||||
|
||||
// Moves one of the user's own textures to the front of the recently-used order texture_library() lists
|
||||
// them in, and stores that order in the app config so it survives a restart. No-op for anything that is
|
||||
// not in user_texture_dir().
|
||||
|
||||
@@ -451,6 +451,16 @@ void GuideFrame::on_profile_loaded()
|
||||
SaveProfileData();
|
||||
const std::string strAll = m_ProfileJson.dump(-1, ' ', false, json::error_handler_t::ignore);
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", finished, json contents:\n" << strAll;
|
||||
m_profile_ready = true;
|
||||
notify_profile_loaded();
|
||||
}
|
||||
|
||||
// The data is often ready before the loading page has run its scripts, and a
|
||||
// call into a page without HandleStudio is lost, so the message waits for both.
|
||||
void GuideFrame::notify_profile_loaded()
|
||||
{
|
||||
if (!m_profile_ready || !m_page_ready)
|
||||
return;
|
||||
json res;
|
||||
res["command"] = "userguide_profile_load_finish";
|
||||
res["sequence_id"] = "10001";
|
||||
@@ -546,7 +556,11 @@ void GuideFrame::OnScriptMessage(wxWebViewEvent &evt)
|
||||
wxString strCmd = j["command"];
|
||||
BOOST_LOG_TRIVIAL(trace) << "GuideFrame::OnScriptMessage;Command:" << strCmd;
|
||||
|
||||
if (strCmd == "close_page") {
|
||||
if (strCmd == "userguide_loading_page_ready") {
|
||||
m_page_ready = true;
|
||||
notify_profile_loaded();
|
||||
}
|
||||
else if (strCmd == "close_page") {
|
||||
this->EndModal(wxID_CANCEL);
|
||||
}
|
||||
if (strCmd == "user_clause") {
|
||||
|
||||
@@ -102,6 +102,7 @@ public:
|
||||
int LoadProfileFamily(std::string strVendor, std::string strFilePath);
|
||||
void init_guide_paths();
|
||||
void on_profile_loaded();
|
||||
void notify_profile_loaded();
|
||||
bool BuildProfileJson(const PresetBundle& bundle, bool require_all_resource_vendors);
|
||||
bool BuildProfileDataFromPresetBundle();
|
||||
bool BuildProfileDataFromVendors();
|
||||
@@ -142,6 +143,10 @@ private:
|
||||
|
||||
//First Load
|
||||
bool bFirstComplete{false};
|
||||
// The loading page gets userguide_profile_load_finish once both are true;
|
||||
// every instance of it reports in, so the flag is never reset.
|
||||
bool m_profile_ready{false};
|
||||
bool m_page_ready{false};
|
||||
// Set once in the destructor. Read through `this` by the loading thread
|
||||
// (joined before `this` dies) and captured as the shared_ptr by CallAfter
|
||||
// lambdas so they don't touch `this` after the object is freed.
|
||||
|
||||
@@ -537,7 +537,7 @@ void WebViewPanel::cloud_signed_out(const wxString& signout_url)
|
||||
}
|
||||
}
|
||||
|
||||
void WebViewPanel::set_cloud_mode(bool on, const wxString& url, const wxString& page_url)
|
||||
void WebViewPanel::set_cloud_mode(bool on, const wxString& url)
|
||||
{
|
||||
if (on) {
|
||||
// load_cloud_url records the origin from whatever it loads, including the plain cloud
|
||||
@@ -546,10 +546,6 @@ void WebViewPanel::set_cloud_mode(bool on, const wxString& url, const wxString&
|
||||
create_cloud_browser();
|
||||
m_cloud_seed_url = url;
|
||||
schedule_cloud_load(url.empty() ? wxString(kCloudUrl) : url);
|
||||
} else if (!page_url.empty()) {
|
||||
// The pane already holds a session, so an explicit page loads straight in; the handoff is
|
||||
// only needed to establish one, not to reach an ordinary page.
|
||||
load_cloud_url(page_url);
|
||||
} else if (!url.empty() && url != m_cloud_seed_url) {
|
||||
// Re-seed only when the Start URL actually changed — a login, an account switch or a
|
||||
// sign-out changes it; an ordinary re-open does not (guide §8). Reloading an unchanged
|
||||
@@ -560,10 +556,6 @@ void WebViewPanel::set_cloud_mode(bool on, const wxString& url, const wxString&
|
||||
load_cloud_after_signout(url);
|
||||
}
|
||||
m_cloud_browser->Show();
|
||||
// The homepage shell owns the nav highlight and the cloud-mode layout class. A native open
|
||||
// (not the page's own GotoCloud) must ask it to switch; the page's SetCloudMode no-ops if it
|
||||
// already did. OnDocumentLoaded re-applies this when the homepage was still loading.
|
||||
RunScript("SetCloudMode(true)");
|
||||
} else if (m_cloud_browser) {
|
||||
// Closing keeps the pane alive with its session, so re-opening does not have to sign in
|
||||
// again (guide §10). Nothing is cleared here.
|
||||
|
||||
@@ -118,10 +118,7 @@ public:
|
||||
// Shows/hides the native OrcaCloud pane beside this homepage nav column. `url` is the
|
||||
// cloud Start URL ({web}/auth/handoff?next=…&user_id=…), which the page uses to decide
|
||||
// whether it already has a session; empty falls back to the plain cloud page.
|
||||
// `page_url` is a full {web} page URL: an already-open pane is navigated straight there,
|
||||
// without re-running the handoff, which is what an explicit "open this page" wants. Empty
|
||||
// keeps whatever page the pane holds.
|
||||
void set_cloud_mode(bool on, const wxString& url = wxString(), const wxString& page_url = wxString());
|
||||
void set_cloud_mode(bool on, const wxString& url = wxString());
|
||||
|
||||
// True while the OrcaCloud pane exists and is visible.
|
||||
bool cloud_mode_active() const { return m_cloud_browser && m_cloud_browser->IsShown(); }
|
||||
|
||||
@@ -529,7 +529,6 @@ std::string PluginConfig::capability_type_label(PluginCapabilityType type)
|
||||
case PluginCapabilityType::Visualization: return _u8L("Visualization");
|
||||
case PluginCapabilityType::Script: return _u8L("Script");
|
||||
case PluginCapabilityType::SlicingPipeline: return _u8L("Slicing Pipeline");
|
||||
case PluginCapabilityType::ResourceTexture: return _u8L("Resource Texture");
|
||||
default: return _u8L("Unknown");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <boost/filesystem/directory.hpp>
|
||||
#include <boost/filesystem/file_status.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
|
||||
#include "PluginAuditManager.hpp"
|
||||
@@ -1256,76 +1255,4 @@ boost::filesystem::path find_installed_plugin_entry(const boost::filesystem::pat
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::string> collect_resource_texture_files(const std::string& dir,
|
||||
const std::string& plugin_root,
|
||||
std::string& error)
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
// Picker sanity bound, not a security control: the popup draws every entry in its grid.
|
||||
constexpr size_t kMaxResourceTextureFiles = 64;
|
||||
|
||||
std::vector<std::string> files;
|
||||
error.clear();
|
||||
|
||||
if (dir.empty()) {
|
||||
error = _u8L("Resource texture directory is not set");
|
||||
return files;
|
||||
}
|
||||
if (plugin_root.empty()) {
|
||||
error = _u8L("Plugin folder could not be determined.");
|
||||
return files;
|
||||
}
|
||||
|
||||
boost::system::error_code ec;
|
||||
const fs::path resolved_dir = fs::weakly_canonical(fs::path(dir), ec);
|
||||
if (ec) {
|
||||
error = _u8L("Resource texture directory could not be resolved");
|
||||
return files;
|
||||
}
|
||||
|
||||
if (!fs::is_directory(resolved_dir, ec) || ec) {
|
||||
error = _u8L("Resource texture path is not a directory");
|
||||
return files;
|
||||
}
|
||||
|
||||
const fs::path resolved_root = fs::weakly_canonical(fs::path(plugin_root), ec);
|
||||
if (ec) {
|
||||
error = _u8L("Plugin folder could not be resolved");
|
||||
return files;
|
||||
}
|
||||
|
||||
if (!is_inside_allowed_root(resolved_dir, resolved_root)) {
|
||||
error = _u8L("Resource texture directory is outside the plugin folder");
|
||||
return files;
|
||||
}
|
||||
|
||||
for (fs::directory_iterator it(resolved_dir, ec), end; it != end && !ec; it.increment(ec)) {
|
||||
const fs::path& path = it->path();
|
||||
|
||||
if (!fs::is_regular_file(path, ec) || ec)
|
||||
continue;
|
||||
|
||||
std::string ext = path.extension().string();
|
||||
boost::algorithm::to_lower(ext);
|
||||
if (ext != ".png" && ext != ".jpg" && ext != ".jpeg" && ext != ".bmp")
|
||||
continue;
|
||||
|
||||
// Re-check per file: a symlink inside the pack must not resolve outside it.
|
||||
if (!is_inside_allowed_root(path, resolved_root))
|
||||
continue;
|
||||
|
||||
files.push_back(path.string());
|
||||
if (files.size() >= kMaxResourceTextureFiles)
|
||||
break;
|
||||
}
|
||||
|
||||
if (ec) {
|
||||
error = _u8L("Resource texture directory could not be read");
|
||||
return {};
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
@@ -176,12 +176,6 @@ bool read_wheel_plugin_metadata(const boost::filesystem::path& whl_path, PluginD
|
||||
// Returns the path to the entry file, or an empty path with error set if zero or multiple candidates.
|
||||
boost::filesystem::path find_installed_plugin_entry(const boost::filesystem::path& plugin_dir, std::string& error);
|
||||
|
||||
// Validated non-recursive .png/.jpg/.jpeg/.bmp files directly inside `dir`, every one contained in
|
||||
// `plugin_root`. Empty with `error` set on failure.
|
||||
std::vector<std::string> collect_resource_texture_files(const std::string& dir,
|
||||
const std::string& plugin_root,
|
||||
std::string& error);
|
||||
|
||||
// Canonical writer: emits the .install_state.json schema for the given state.
|
||||
bool write_install_state(const boost::filesystem::path& plugin_dir, const PluginInstallState& state);
|
||||
// Builds a PluginInstallState from the descriptor and delegates to the canonical writer.
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include "PluginFsUtils.hpp"
|
||||
#include "PythonInterpreter.hpp"
|
||||
#include "PythonPluginBridge.hpp"
|
||||
#include "pluginTypes/resourceTexture/ResourceTexturePluginCapability.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "slic3r/GUI/I18N.hpp"
|
||||
#include "slic3r/GUI/format.hpp"
|
||||
@@ -388,37 +387,6 @@ bool load(const PluginDescriptor& descriptor,
|
||||
instance->set_config_ui_available(false);
|
||||
}
|
||||
|
||||
// ResourceTexture capabilities resolve their texture directory here, under the
|
||||
// GIL this block already holds, and cache the validated result. A resolution
|
||||
// fault only costs this capability its textures, so it is caught locally like
|
||||
// has_config_ui() above rather than failing the load.
|
||||
if (auto* resource_texture = dynamic_cast<ResourceTexturePluginCapability*>(instance.get())) {
|
||||
try {
|
||||
const std::string texture_dir = resource_texture->get_texture_dir();
|
||||
if (texture_dir.empty()) {
|
||||
resource_texture->set_texture_dir({});
|
||||
} else {
|
||||
std::string texture_error;
|
||||
collect_resource_texture_files(texture_dir, descriptor.plugin_root, texture_error);
|
||||
if (texture_error.empty()) {
|
||||
resource_texture->set_texture_dir(texture_dir);
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< "Plugin capability '" << found.name << "' of plugin '" << descriptor.plugin_key
|
||||
<< "': texture directory rejected (" << texture_error
|
||||
<< "); the capability will provide no textures";
|
||||
resource_texture->set_texture_dir({});
|
||||
}
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
BOOST_LOG_TRIVIAL(warning)
|
||||
<< "Plugin capability '" << found.name << "' of plugin '" << descriptor.plugin_key
|
||||
<< "': get_texture_dir() failed (" << ex.what()
|
||||
<< "); the capability will provide no textures";
|
||||
resource_texture->set_texture_dir({});
|
||||
}
|
||||
}
|
||||
|
||||
capabilities.push_back(std::move(instance));
|
||||
}
|
||||
} catch (const std::exception& ex) {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "PyPluginTrampoline.hpp"
|
||||
#include "pluginTypes/printerAgent/PrinterAgentPluginCapability.hpp"
|
||||
#include "pluginTypes/pages/PagesPluginCapability.hpp"
|
||||
#include "pluginTypes/resourceTexture/ResourceTexturePluginCapability.hpp"
|
||||
#include "pluginTypes/script/ScriptPluginCapability.hpp"
|
||||
#include "pluginTypes/slicingPipeline/SlicingPipelinePluginCapability.hpp"
|
||||
#include <pybind11/pytypes.h>
|
||||
@@ -375,7 +374,6 @@ void bind_python_api(pybind11::module_& m)
|
||||
.value("Visualization", PluginCapabilityType::Visualization)
|
||||
.value("Script", PluginCapabilityType::Script)
|
||||
.value("SlicingPipeline", PluginCapabilityType::SlicingPipeline)
|
||||
.value("ResourceTexture", PluginCapabilityType::ResourceTexture)
|
||||
.value("Unknown", PluginCapabilityType::Unknown)
|
||||
.export_values();
|
||||
|
||||
@@ -529,7 +527,6 @@ void bind_python_api(pybind11::module_& m)
|
||||
PagesPluginCapability::RegisterBindings(m);
|
||||
ScriptPluginCapability::RegisterBindings(m);
|
||||
SlicingPipelinePluginCapability::RegisterBindings(m);
|
||||
ResourceTexturePluginCapability::RegisterBindings(m);
|
||||
PluginHost::RegisterBindings(m);
|
||||
BOOST_LOG_TRIVIAL(debug) << "Registered ScriptPluginCapability Python bindings";
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
enum class PluginCapabilityType { PrinterConnection = 0, Pages, Analysis, Importer, Exporter, Visualization, Script, SlicingPipeline, ResourceTexture, Unknown };
|
||||
enum class PluginCapabilityType { PrinterConnection = 0, Pages, Analysis, Importer, Exporter, Visualization, Script, SlicingPipeline, Unknown };
|
||||
|
||||
struct PluginCapabilityId
|
||||
{
|
||||
@@ -48,7 +48,6 @@ inline std::string plugin_capability_type_to_string(PluginCapabilityType type)
|
||||
case PluginCapabilityType::Visualization: return "visualization";
|
||||
case PluginCapabilityType::Script: return "script";
|
||||
case PluginCapabilityType::SlicingPipeline: return "slicing-pipeline";
|
||||
case PluginCapabilityType::ResourceTexture: return "resource-texture";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
@@ -64,7 +63,6 @@ inline std::string plugin_capability_type_display_name(PluginCapabilityType type
|
||||
case PluginCapabilityType::Visualization: return "Visualization";
|
||||
case PluginCapabilityType::Script: return "Script";
|
||||
case PluginCapabilityType::SlicingPipeline: return "Slicing Pipeline";
|
||||
case PluginCapabilityType::ResourceTexture: return "Resource Texture";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
@@ -94,8 +92,6 @@ inline PluginCapabilityType plugin_capability_type_from_string(std::string_view
|
||||
return PluginCapabilityType::Script;
|
||||
if (lowered == "slicing-pipeline")
|
||||
return PluginCapabilityType::SlicingPipeline;
|
||||
if (lowered == "resource-texture")
|
||||
return PluginCapabilityType::ResourceTexture;
|
||||
return PluginCapabilityType::Unknown;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
#include "PluginResourceTextures.hpp"
|
||||
|
||||
#include "slic3r/plugin/PluginDescriptor.hpp"
|
||||
#include "slic3r/plugin/PluginManager.hpp"
|
||||
#include "slic3r/plugin/pluginTypes/resourceTexture/ResourceTexturePluginCapability.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <slic3r/plugin/PythonPluginInterface.hpp>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
PluginResourceTextures &PluginResourceTextures::instance()
|
||||
{
|
||||
static PluginResourceTextures registry;
|
||||
return registry;
|
||||
}
|
||||
|
||||
std::optional<ResourceTextureEntry> PluginResourceTextures::build_entry(const PluginCapabilityId &id) const
|
||||
{
|
||||
// Query by id and re-check state; the manager copies the shared_ptr and releases its lock.
|
||||
auto capability = PluginManager::instance().get_plugin_capability(id, /*only_enabled=*/false);
|
||||
if (!capability || !capability->is_enabled() || capability->type() != PluginCapabilityType::ResourceTexture)
|
||||
return std::nullopt;
|
||||
|
||||
auto texture_capability = std::dynamic_pointer_cast<ResourceTexturePluginCapability>(capability);
|
||||
if (!texture_capability)
|
||||
return std::nullopt;
|
||||
|
||||
// An empty directory means resolution failed at load, so the pack contributes nothing.
|
||||
const std::string &texture_dir = texture_capability->texture_dir();
|
||||
if (texture_dir.empty())
|
||||
return std::nullopt;
|
||||
|
||||
PluginDescriptor descriptor;
|
||||
if (!PluginManager::instance().try_get_plugin_descriptor_for_capability(capability->name(),
|
||||
PluginCapabilityType::ResourceTexture,
|
||||
descriptor))
|
||||
return std::nullopt;
|
||||
|
||||
ResourceTextureEntry entry;
|
||||
entry.id = capability->identity();
|
||||
entry.plugin_key = entry.id.plugin_key;
|
||||
entry.display_name = capability->name();
|
||||
entry.texture_dir = texture_dir;
|
||||
entry.plugin_root = descriptor.plugin_root;
|
||||
return entry;
|
||||
}
|
||||
|
||||
void PluginResourceTextures::on_plugin_register(const std::string &plugin_key)
|
||||
{
|
||||
for (const auto &capability : PluginManager::instance().get_plugin_capabilities(plugin_key, PluginCapabilityType::ResourceTexture)) {
|
||||
if (capability)
|
||||
on_cap_register(capability->identity());
|
||||
}
|
||||
}
|
||||
|
||||
void PluginResourceTextures::on_plugin_deregister(const std::string &plugin_key)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
for (auto it = m_entries.begin(); it != m_entries.end();) {
|
||||
if (it->first.plugin_key == plugin_key)
|
||||
it = m_entries.erase(it);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void PluginResourceTextures::on_cap_register(const PluginCapabilityId &id)
|
||||
{
|
||||
std::optional<ResourceTextureEntry> entry = build_entry(id);
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (entry)
|
||||
m_entries[entry->id] = std::move(*entry);
|
||||
}
|
||||
|
||||
void PluginResourceTextures::on_cap_deregister(const PluginCapabilityId &id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_entries.erase(id);
|
||||
}
|
||||
|
||||
void PluginResourceTextures::initial_sweep()
|
||||
{
|
||||
std::map<PluginCapabilityId, ResourceTextureEntry> entries;
|
||||
for (const auto &capability : PluginManager::instance().get_plugin_capabilities("", PluginCapabilityType::ResourceTexture)) {
|
||||
if (!capability)
|
||||
continue;
|
||||
std::optional<ResourceTextureEntry> entry = build_entry(capability->identity());
|
||||
if (entry)
|
||||
entries[entry->id] = std::move(*entry);
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
m_entries = std::move(entries);
|
||||
}
|
||||
|
||||
std::vector<ResourceTextureEntry> PluginResourceTextures::entries() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
std::vector<ResourceTextureEntry> result;
|
||||
result.reserve(m_entries.size());
|
||||
for (const auto &entry : m_entries)
|
||||
result.push_back(entry.second);
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -1,50 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <slic3r/plugin/PythonPluginInterface.hpp>
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
// One ResourceTexture capability contributing a texture directory to the texture picker.
|
||||
struct ResourceTextureEntry
|
||||
{
|
||||
PluginCapabilityId id;
|
||||
std::string plugin_key;
|
||||
std::string display_name;
|
||||
std::string texture_dir;
|
||||
std::string plugin_root; // so a scan can re-check containment
|
||||
};
|
||||
|
||||
// Tracks every loaded and enabled ResourceTexture capability by id. Holds strings only: a
|
||||
// shared_ptr here would keep a Python object alive past Py_Finalize.
|
||||
class PluginResourceTextures
|
||||
{
|
||||
public:
|
||||
static PluginResourceTextures &instance();
|
||||
|
||||
PluginResourceTextures(const PluginResourceTextures &) = delete;
|
||||
PluginResourceTextures &operator=(const PluginResourceTextures &) = delete;
|
||||
|
||||
void on_plugin_register(const std::string &plugin_key);
|
||||
void on_plugin_deregister(const std::string &plugin_key);
|
||||
void on_cap_register(const PluginCapabilityId &id);
|
||||
void on_cap_deregister(const PluginCapabilityId &id);
|
||||
void initial_sweep();
|
||||
|
||||
std::vector<ResourceTextureEntry> entries() const;
|
||||
|
||||
private:
|
||||
PluginResourceTextures() = default;
|
||||
|
||||
std::optional<ResourceTextureEntry> build_entry(const PluginCapabilityId &id) const;
|
||||
|
||||
mutable std::mutex m_mutex;
|
||||
std::map<PluginCapabilityId, ResourceTextureEntry> m_entries;
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "ResourceTexturePluginCapability.hpp"
|
||||
#include "ResourceTexturePluginCapabilityTrampoline.hpp"
|
||||
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/pytypes.h>
|
||||
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <slic3r/plugin/PythonPluginInterface.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
void ResourceTexturePluginCapability::RegisterBindings(pybind11::module_& module)
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(debug) << "Registering orca.resource_texture bindings";
|
||||
|
||||
auto resource_texture = module.def_submodule("resource_texture", "Plugin resource texture API");
|
||||
|
||||
py::class_<ResourceTexturePluginCapability, PluginCapabilityInterface,
|
||||
PyResourceTexturePluginCapabilityTrampoline,
|
||||
std::shared_ptr<ResourceTexturePluginCapability>>(resource_texture,
|
||||
"ResourceTexturePluginCapabilityBase")
|
||||
.def(py::init<>())
|
||||
.def("get_type", &ResourceTexturePluginCapability::get_type)
|
||||
.def("get_texture_dir", &ResourceTexturePluginCapability::get_texture_dir);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../PythonPluginInterface.hpp"
|
||||
#include "pybind11/pybind11.h"
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
namespace Slic3r {
|
||||
class ResourceTexturePluginCapability : public PluginCapabilityInterface
|
||||
{
|
||||
public:
|
||||
static void RegisterBindings(pybind11::module_& module);
|
||||
|
||||
PluginCapabilityType get_type() const override { return PluginCapabilityType::ResourceTexture; }
|
||||
|
||||
// Python contract: the directory the host scans for textures. Resolved once at materialization
|
||||
// under the GIL; never called from the GUI. Overridden in Python through the trampoline.
|
||||
virtual std::string get_texture_dir() const = 0;
|
||||
|
||||
// C++-only read of the validated directory cached by the loader; empty if resolution failed.
|
||||
const std::string& texture_dir() const { return m_texture_dir; }
|
||||
void set_texture_dir(std::string dir) { m_texture_dir = std::move(dir); }
|
||||
|
||||
private:
|
||||
std::string m_texture_dir;
|
||||
};
|
||||
} // namespace Slic3r
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "ResourceTexturePluginCapability.hpp"
|
||||
#include "../../PyPluginTrampoline.hpp"
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/pytypes.h>
|
||||
|
||||
#include <string>
|
||||
#include "slic3r/plugin/PythonPluginInterface.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class PyResourceTexturePluginCapabilityTrampoline :
|
||||
public PyPluginCommonTrampoline<ResourceTexturePluginCapability>
|
||||
{
|
||||
public:
|
||||
using PyPluginCommonTrampoline<ResourceTexturePluginCapability>::PyPluginCommonTrampoline;
|
||||
|
||||
std::string get_texture_dir() const override
|
||||
{
|
||||
ORCA_PY_OVERRIDE_AUDITED(
|
||||
[] {},
|
||||
PYBIND11_OVERRIDE_PURE,
|
||||
std::string,
|
||||
ResourceTexturePluginCapability,
|
||||
get_texture_dir);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -94,6 +94,33 @@ static std::shared_ptr<std::vector<unsigned char>> make_flat_rgb_png(uint8_t r,
|
||||
return std::make_shared<std::vector<unsigned char>>(std::move(bytes));
|
||||
}
|
||||
|
||||
// An RGB image built by a caller-supplied function of the pixel position, written through the same
|
||||
// temp-file round trip the flat helpers above use.
|
||||
static std::shared_ptr<std::vector<unsigned char>> make_rgb_png(
|
||||
size_t w, size_t h, const std::function<std::array<uint8_t, 3>(size_t, size_t)> &at)
|
||||
{
|
||||
std::vector<uint8_t> rgb;
|
||||
rgb.reserve(w * h * 3);
|
||||
for (size_t y = 0; y < h; ++y)
|
||||
for (size_t x = 0; x < w; ++x) {
|
||||
const std::array<uint8_t, 3> c = at(x, y);
|
||||
rgb.insert(rgb.end(), { c[0], c[1], c[2] });
|
||||
}
|
||||
const boost::filesystem::path tmp_path = boost::filesystem::temp_directory_path()
|
||||
/ boost::filesystem::unique_path("texdisp_test_%%%%%%%%.png");
|
||||
REQUIRE(Slic3r::png::write_rgb_to_file(tmp_path.string(), w, h, rgb));
|
||||
|
||||
std::vector<unsigned char> bytes;
|
||||
{
|
||||
std::ifstream ifs(tmp_path.string(), std::ios::binary);
|
||||
bytes.assign(std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>());
|
||||
}
|
||||
boost::system::error_code ec;
|
||||
boost::filesystem::remove(tmp_path, ec);
|
||||
REQUIRE_FALSE(bytes.empty());
|
||||
return std::make_shared<std::vector<unsigned char>>(std::move(bytes));
|
||||
}
|
||||
|
||||
// A hard-edged black/white checkerboard, the worst case for a height map: every texel boundary is a
|
||||
// step, which is precisely the relief the post-process smoothing exists to round off.
|
||||
static std::shared_ptr<std::vector<unsigned char>> make_checkerboard_png(size_t w = 16, size_t h = 16)
|
||||
@@ -2626,6 +2653,61 @@ TEST_CASE("TextureDisplacement: a texture of flat colours is told apart from a c
|
||||
CHECK(d.flat_share < 0.85f);
|
||||
}
|
||||
|
||||
TEST_CASE("A mirrored tile folds at its seam instead of wrapping to the far edge", "[TextureDisplacement]")
|
||||
{
|
||||
// Mirrored repeat exists so a tile edge lines up with itself, which means the texel past the edge
|
||||
// is the edge again. Wrapping the bilinear neighbour instead blends the image's two opposite edges
|
||||
// together: on a ramp from black to white it turned the white edge into near-black at every seam,
|
||||
// a visible line and a disagreement with the preview, where the GPU binds GL_MIRRORED_REPEAT.
|
||||
TextureDisplacementLayer layer;
|
||||
layer.image_data = make_rgb_png(8, 8, [](size_t x, size_t) {
|
||||
const uint8_t v = uint8_t(x * 36); // 0 at the left edge, 252 at the right
|
||||
return std::array<uint8_t, 3>{ v, v, v };
|
||||
});
|
||||
const DecodedHeightTexture tex = decode_height_texture(layer);
|
||||
REQUIRE(tex.width == 8);
|
||||
const float bright = 252.f / 255.f;
|
||||
|
||||
// Either side of a seam the fold puts the bright edge, not a blend with the dark one.
|
||||
for (const float u : { 0.999f, 1.001f, 2.999f, 3.001f }) {
|
||||
INFO("u = " << u);
|
||||
CHECK_THAT(tex.sample(Vec2f(u, 0.5f), true, TextureTileMethod::MirroredRepeat),
|
||||
WithinAbs(bright, 0.02f));
|
||||
}
|
||||
|
||||
// Plain repeat is the opposite case and must keep wrapping: its next tile really does start at the
|
||||
// far edge, so just inside the seam the neighbour is the dark one.
|
||||
CHECK(tex.sample(Vec2f(0.999f, 0.5f), true, TextureTileMethod::Repeat) < 0.1f);
|
||||
}
|
||||
|
||||
TEST_CASE("A two-colour ramp is not mistaken for an image of flat colours", "[TextureDisplacement]")
|
||||
{
|
||||
// The histogram alone cannot tell these two apart: a ramp between two colours visits as few
|
||||
// coarse bins as the two colours on their own, and both score far above the flat-share
|
||||
// threshold. What separates them is that the ramp fills its colour axis and the pair does not.
|
||||
const std::array<uint8_t, 3> a{ 0x4f, 0xc3, 0x08 };
|
||||
const std::array<uint8_t, 3> b{ 0xd4, 0x2f, 0x25 };
|
||||
|
||||
TextureDisplacementLayer ramp;
|
||||
ramp.image_data = make_rgb_png(96, 96, [&](size_t, size_t y) {
|
||||
const float t = float(y) / 95.f;
|
||||
return std::array<uint8_t, 3>{ uint8_t(std::lround(a[0] + (b[0] - a[0]) * t)),
|
||||
uint8_t(std::lround(a[1] + (b[1] - a[1]) * t)),
|
||||
uint8_t(std::lround(a[2] + (b[2] - a[2]) * t)) };
|
||||
});
|
||||
const TextureDetail ramp_detail = analyze_texture_detail(ramp);
|
||||
CHECK(ramp_detail.flat_share >= 0.85f); // the old signal, on its own, calls this flat
|
||||
CHECK(ramp_detail.axis_coverage > 0.8f); // but its colours run the length of the axis
|
||||
CHECK_FALSE(ramp_detail.flat_colors); // so mixes stay available
|
||||
|
||||
// The same two colours as areas rather than a ramp: nothing in between, so no mix would serve it.
|
||||
TextureDisplacementLayer two_tone;
|
||||
two_tone.image_data = make_rgb_png(96, 96, [&](size_t, size_t y) { return y < 48 ? a : b; });
|
||||
const TextureDetail two_tone_detail = analyze_texture_detail(two_tone);
|
||||
CHECK(two_tone_detail.axis_coverage < 0.25f);
|
||||
CHECK(two_tone_detail.flat_colors);
|
||||
}
|
||||
|
||||
TEST_CASE("Each layer's texture is sampled only on its own painted area", "[TextureDisplacement]")
|
||||
{
|
||||
// Two layers with different textures and depths, one painted on the cube's top, one on its -X side.
|
||||
|
||||
@@ -30,7 +30,6 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_printer_agent.cpp
|
||||
test_plugin_install.cpp
|
||||
test_plugin_lifecycle.cpp
|
||||
test_plugin_resource_texture.cpp
|
||||
test_plugin_printer_agent.cpp
|
||||
test_printhost.cpp
|
||||
test_slicing_pipeline_bindings.cpp
|
||||
@@ -43,7 +42,6 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_texture_color_palette.cpp
|
||||
test_texture_island_view.cpp
|
||||
test_file_url.cpp
|
||||
test_imgui_wrapper.cpp
|
||||
test_user_manager.cpp
|
||||
../fff_print/test_helpers.cpp
|
||||
)
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
// How ImGuiWrapper turns wx mouse events into ImGui input. ImGuiWrapper lives in libslic3r_gui; this is
|
||||
// the suite that links it. Same Windows include prologue as test_texture_color_palette.cpp (wx pulls in
|
||||
// <windows.h>; keep WIN32_LEAN_AND_MEAN / NOMINMAX ahead of it).
|
||||
#ifdef WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
#include <catch2/matchers/catch_matchers.hpp>
|
||||
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <wx/event.h>
|
||||
|
||||
#include "slic3r/GUI/ImGuiWrapper.hpp"
|
||||
|
||||
using Catch::Matchers::WithinAbs;
|
||||
using Slic3r::GUI::ImGuiWrapper;
|
||||
|
||||
namespace {
|
||||
|
||||
// ImGui's wheel after one wheel event, as wx on macOS builds it: a delta of 10 and the rotation in whole
|
||||
// points of trackpad travel.
|
||||
float wheel_after(int rotation, wxMouseWheelAxis axis)
|
||||
{
|
||||
ImGuiWrapper imgui;
|
||||
imgui.set_display_size(800.f, 600.f); // update_mouse_data() ignores input until the display has a size
|
||||
|
||||
wxMouseEvent evt(wxEVT_MOUSEWHEEL);
|
||||
evt.m_wheelRotation = rotation;
|
||||
evt.m_wheelDelta = 10;
|
||||
evt.m_wheelAxis = axis;
|
||||
imgui.update_mouse_data(evt);
|
||||
return ImGui::GetIO().MouseWheel;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("a vertical wheel event steps ImGui's wheel in its own direction", "[ImGuiWrapper]")
|
||||
{
|
||||
const int rotation = GENERATE(1, 7, 120, -1, -7, -120);
|
||||
CHECK_THAT(wheel_after(rotation, wxMOUSE_WHEEL_VERTICAL), WithinAbs(rotation > 0 ? 1.0 : -1.0, 0.0));
|
||||
}
|
||||
|
||||
// Both kinds arrive from a macOS trackpad while scrolling; see ImGuiWrapper::update_mouse_data().
|
||||
TEST_CASE("a wheel event with no rotation or on the horizontal axis does not step ImGui's wheel", "[ImGuiWrapper][Regression]")
|
||||
{
|
||||
const auto [rotation, axis] = GENERATE(table<int, wxMouseWheelAxis>({
|
||||
{ 0, wxMOUSE_WHEEL_VERTICAL },
|
||||
{ 5, wxMOUSE_WHEEL_HORIZONTAL },
|
||||
{ -5, wxMOUSE_WHEEL_HORIZONTAL },
|
||||
}));
|
||||
CHECK_THAT(wheel_after(rotation, axis), WithinAbs(0.0, 0.0));
|
||||
}
|
||||
@@ -1,941 +0,0 @@
|
||||
// ResourceTexture plugin type: directory validation, the host registry's lifecycle, the texture
|
||||
// listing's plugin section, hostile get_texture_dir() overrides, decode parity and the .3mf round
|
||||
// trip without the pack installed.
|
||||
//
|
||||
// The GUI wiring lives in GUI_App::init_plugin_gui_wiring; the test binary has no app, so the same
|
||||
// registry callbacks are installed here. As in test_plugin_lifecycle.cpp, each Catch2 test case runs
|
||||
// in its own process (catch_discover_tests), so the PluginManager and interpreter come up at most once
|
||||
// per test.
|
||||
//
|
||||
// Same Windows include prologue as test_texture_color_palette.cpp: wx pulls in <windows.h>, so keep
|
||||
// WIN32_LEAN_AND_MEAN / NOMINMAX ahead of the Catch2 headers.
|
||||
#include "test_utils.hpp"
|
||||
#include <slic3r/plugin/PluginDescriptor.hpp>
|
||||
#ifdef WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <catch2/catch_all.hpp>
|
||||
#include <catch2/catch_message.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <initializer_list>
|
||||
#include <ios>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <wx/image.h>
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "libslic3r/Format/bbs_3mf.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/PNGReadWrite.hpp"
|
||||
#include "libslic3r/Preset.hpp"
|
||||
#include "libslic3r/PrintConfig.hpp"
|
||||
#include "libslic3r/Semver.hpp"
|
||||
#include "libslic3r/TextureDisplacement.hpp"
|
||||
#include "libslic3r/TriangleMesh.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "libslic3r/Zipper.hpp"
|
||||
|
||||
#include "slic3r/GUI/TextureLibrary.hpp"
|
||||
#include "slic3r/plugin/PluginFsUtils.hpp"
|
||||
#include "slic3r/plugin/PluginManager.hpp"
|
||||
#include "slic3r/plugin/PythonInterpreter.hpp"
|
||||
#include "slic3r/plugin/PythonPluginInterface.hpp"
|
||||
#include "slic3r/plugin/host/PluginResourceTextures.hpp"
|
||||
|
||||
#include "plugin_test_utils.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
namespace {
|
||||
|
||||
// Brings the plugin system up, and tears it down explicitly at the end of the test, as
|
||||
// test_plugin_lifecycle.cpp does. Declare this FIRST in a test so it is destroyed last.
|
||||
struct ScopedPluginManager
|
||||
{
|
||||
// Before initialize(): the interpreter creates {data_dir}/python/packages and {data_dir}/log.
|
||||
ScopedDataDir python_data_dir{"texture-python"};
|
||||
bool initialized = false;
|
||||
|
||||
ScopedPluginManager() { initialized = PluginManager::instance().initialize(); }
|
||||
~ScopedPluginManager()
|
||||
{
|
||||
PluginManager::instance().shutdown();
|
||||
PythonInterpreter::instance().shutdown();
|
||||
}
|
||||
};
|
||||
|
||||
// The app installs these in GUI_App::init_plugin_gui_wiring. Without an app the callbacks run inline
|
||||
// on the load worker, which is what lets the tests observe the registry right after the wait.
|
||||
void install_resource_texture_wiring()
|
||||
{
|
||||
static bool installed = false;
|
||||
if (installed)
|
||||
return;
|
||||
installed = true;
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
manager.subscribe_on_load_callback([](const std::string& plugin_key) {
|
||||
PluginResourceTextures::instance().on_plugin_register(plugin_key);
|
||||
GUI::bump_texture_library_generation();
|
||||
});
|
||||
manager.subscribe_on_unload_callback([](const std::string& plugin_key) {
|
||||
PluginResourceTextures::instance().on_plugin_deregister(plugin_key);
|
||||
GUI::bump_texture_library_generation();
|
||||
});
|
||||
manager.subscribe_on_capability_load_callback([](const PluginCapabilityId& capability) {
|
||||
if (capability.type != PluginCapabilityType::ResourceTexture)
|
||||
return;
|
||||
PluginResourceTextures::instance().on_cap_register(capability);
|
||||
GUI::bump_texture_library_generation();
|
||||
});
|
||||
manager.subscribe_on_capability_unload_callback([](const PluginCapabilityId& capability) {
|
||||
if (capability.type != PluginCapabilityType::ResourceTexture)
|
||||
return;
|
||||
PluginResourceTextures::instance().on_cap_deregister(capability);
|
||||
GUI::bump_texture_library_generation();
|
||||
});
|
||||
}
|
||||
|
||||
// A minimal resource-texture plugin. `display_name` is the PEP723 package name and, unless
|
||||
// `capability_name` is given, the capability's get_name() too; pass `capability_name` to keep the
|
||||
// package name and the capability name independent.
|
||||
std::string make_resource_texture_source(const std::string& display_name,
|
||||
const std::string& get_texture_dir_body,
|
||||
const std::string& capability_name = "")
|
||||
{
|
||||
const std::string cap_name = capability_name.empty() ? display_name : capability_name;
|
||||
return std::string{}
|
||||
+ "# /// script\n"
|
||||
+ "# requires-python = \">=3.12\"\n"
|
||||
+ "# dependencies = []\n"
|
||||
+ "#\n"
|
||||
+ "# [tool.orcaslicer.plugin]\n"
|
||||
+ "# name = \"" + display_name + "\"\n"
|
||||
+ "# description = \"Resource texture pack fixture.\"\n"
|
||||
+ "# author = \"tests\"\n"
|
||||
+ "# version = \"1.0.0\"\n"
|
||||
+ "# type = \"resource-texture\"\n"
|
||||
+ "# ///\n"
|
||||
+ "import os\n"
|
||||
+ "import orca\n"
|
||||
+ "\n\n"
|
||||
+ "class PackTextures(orca.resource_texture.ResourceTexturePluginCapabilityBase):\n"
|
||||
+ " def get_name(self):\n"
|
||||
+ " return \"" + cap_name + "\"\n"
|
||||
+ "\n"
|
||||
+ " def get_texture_dir(self):\n"
|
||||
+ " " + get_texture_dir_body + "\n"
|
||||
+ "\n\n"
|
||||
+ "@orca.plugin\n"
|
||||
+ "class TexturePack(orca.base):\n"
|
||||
+ " def register_capabilities(self):\n"
|
||||
+ " orca.register_capability(PackTextures)\n";
|
||||
}
|
||||
|
||||
std::string default_texture_dir_body()
|
||||
{
|
||||
return "return os.path.join(os.path.dirname(__file__), \"textures\")";
|
||||
}
|
||||
|
||||
// Writes {data_dir}/orca_plugins/<stem>/<stem>.py and returns the plugin directory.
|
||||
fs::path write_plugin(const ScopedDataDir& data_dir_guard, const std::string& stem, const std::string& source)
|
||||
{
|
||||
const fs::path plugin_dir = data_dir_guard.plugins_dir() / stem;
|
||||
fs::create_directories(plugin_dir);
|
||||
|
||||
std::ofstream out((plugin_dir / (stem + ".py")).string(), std::ios::binary);
|
||||
out << source;
|
||||
out.close();
|
||||
|
||||
return plugin_dir;
|
||||
}
|
||||
|
||||
bool load_and_wait(PluginManager& manager, const std::string& plugin_key, std::string& error)
|
||||
{
|
||||
manager.load_plugin(plugin_key, /*skip_deps=*/true);
|
||||
return manager.wait_for_plugin_load(plugin_key, std::chrono::seconds(120), error);
|
||||
}
|
||||
|
||||
// The Plugin-sourced slice of the texture listing, which is exactly what the picker's third heading
|
||||
// draws. Pass force to call texture_library(true); without it the listing is reused unless a pack
|
||||
// callback moved the generation.
|
||||
std::vector<GUI::TextureLibraryEntry> plugin_textures(bool force)
|
||||
{
|
||||
std::vector<GUI::TextureLibraryEntry> found;
|
||||
for (const GUI::TextureLibraryEntry& entry : GUI::texture_library(force))
|
||||
if (entry.source == GUI::TextureSource::Plugin)
|
||||
found.push_back(entry);
|
||||
return found;
|
||||
}
|
||||
|
||||
void write_text_file(const fs::path& path, const std::string& content = "x")
|
||||
{
|
||||
fs::create_directories(path.parent_path());
|
||||
std::ofstream out(path.string(), std::ios::binary);
|
||||
out << content;
|
||||
}
|
||||
|
||||
std::vector<unsigned char> read_file_bytes(const fs::path& path)
|
||||
{
|
||||
std::ifstream ifs(path.string(), std::ios::binary);
|
||||
return std::vector<unsigned char>(std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>());
|
||||
}
|
||||
|
||||
void write_bytes(const fs::path& path, const std::vector<unsigned char>& bytes)
|
||||
{
|
||||
fs::create_directories(path.parent_path());
|
||||
std::ofstream out(path.string(), std::ios::binary);
|
||||
out.write(reinterpret_cast<const char*>(bytes.data()), std::streamsize(bytes.size()));
|
||||
}
|
||||
|
||||
void write_gray_png(const fs::path& path, uint8_t value, size_t w = 4, size_t h = 4)
|
||||
{
|
||||
fs::create_directories(path.parent_path());
|
||||
const std::vector<uint8_t> pixels(w * h, value);
|
||||
REQUIRE(Slic3r::png::write_gray_to_file(path.string(), w, h, pixels));
|
||||
}
|
||||
|
||||
// A 24-bit gray BMP (R == G == B), synthesised without an image toolkit. Rows are bottom-up and
|
||||
// padded to four bytes; the image is uniform, so the orientation does not matter.
|
||||
std::vector<unsigned char> make_gray_bmp(int width, int height, uint8_t value)
|
||||
{
|
||||
const int row_bytes = ((width * 3 + 3) / 4) * 4;
|
||||
const uint32_t pixel_bytes = uint32_t(row_bytes) * uint32_t(height);
|
||||
const uint32_t file_size = 14 + 40 + pixel_bytes;
|
||||
|
||||
std::vector<unsigned char> bmp(file_size, 0);
|
||||
const auto put16 = [&bmp](size_t at, uint16_t v) {
|
||||
bmp[at] = uint8_t(v);
|
||||
bmp[at + 1] = uint8_t(v >> 8);
|
||||
};
|
||||
const auto put32 = [&bmp](size_t at, uint32_t v) {
|
||||
bmp[at] = uint8_t(v);
|
||||
bmp[at + 1] = uint8_t(v >> 8);
|
||||
bmp[at + 2] = uint8_t(v >> 16);
|
||||
bmp[at + 3] = uint8_t(v >> 24);
|
||||
};
|
||||
|
||||
bmp[0] = 'B';
|
||||
bmp[1] = 'M';
|
||||
put32(2, file_size);
|
||||
put32(10, 54); // pixel data offset
|
||||
put32(14, 40); // BITMAPINFOHEADER size
|
||||
put32(18, uint32_t(width));
|
||||
put32(22, uint32_t(height));
|
||||
put16(26, 1); // planes
|
||||
put16(28, 24); // bits per pixel
|
||||
put32(34, pixel_bytes);
|
||||
|
||||
for (int y = 0; y < height; ++y) {
|
||||
unsigned char* row = bmp.data() + 54 + size_t(y) * size_t(row_bytes);
|
||||
for (int x = 0; x < width; ++x) {
|
||||
row[x * 3] = value;
|
||||
row[x * 3 + 1] = value;
|
||||
row[x * 3 + 2] = value;
|
||||
}
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
|
||||
// The app calls wxInitAllImageHandlers() during startup and, before that, wxEntryStart() runs the
|
||||
// wxImageModule, which registers the standard handlers. wxInitAllImageHandlers() adds PNG, JPEG and
|
||||
// the rest but NOT the BMP handler, so a test binary without a wxApp must add the standard set too or
|
||||
// a .bmp texture cannot be loaded here at all.
|
||||
void ensure_wx_image_handlers()
|
||||
{
|
||||
static bool initialized = false;
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = true;
|
||||
wxImage::InitStandardHandlers();
|
||||
wxInitAllImageHandlers();
|
||||
}
|
||||
|
||||
// Stores `model` as a one-plate project, mirroring tests/libslic3r/test_3mf.cpp.
|
||||
void store_project(Model& model, const std::string& path)
|
||||
{
|
||||
ScopedTemporaryDir backup_dir("orca_tex_pack_src");
|
||||
model.set_backup_path(backup_dir.string());
|
||||
|
||||
DynamicPrintConfig cfg;
|
||||
PlateData plate;
|
||||
plate.plate_index = 0;
|
||||
StoreParams sp;
|
||||
sp.path = path.c_str();
|
||||
sp.model = &model;
|
||||
sp.config = &cfg;
|
||||
sp.strategy = SaveStrategy::Zip64 | SaveStrategy::Silence;
|
||||
sp.plate_data_list.push_back(&plate);
|
||||
REQUIRE(store_bbs_3mf(sp));
|
||||
}
|
||||
|
||||
bool load_project(const std::string& path, Model& model, const ScopedTemporaryDir& backup_dir)
|
||||
{
|
||||
model.set_backup_path(backup_dir.string());
|
||||
DynamicPrintConfig config;
|
||||
ConfigSubstitutionContext ctxt{ ForwardCompatibilitySubstitutionRule::Enable };
|
||||
PlateDataPtrs plates;
|
||||
std::vector<Preset*> project_presets;
|
||||
bool is_bbl_3mf = false;
|
||||
bool is_orca_3mf = false;
|
||||
Semver file_version;
|
||||
const bool loaded = load_bbs_3mf(path.c_str(), &config, &ctxt, &model, &plates, &project_presets,
|
||||
&is_bbl_3mf, &is_orca_3mf, &file_version, nullptr,
|
||||
LoadStrategy::LoadModel | LoadStrategy::LoadConfig);
|
||||
release_PlateData_list(plates);
|
||||
return loaded;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// ── Validation (collect_resource_texture_files, no Python) ──────────────────────────────────────
|
||||
|
||||
TEST_CASE("A texture file directly inside the plugin folder is listed", "[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir root("tex-root");
|
||||
write_text_file(root.path() / "textures" / "grain.png");
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files =
|
||||
collect_resource_texture_files((root.path() / "textures").string(), root.string(), error);
|
||||
|
||||
CHECK(error.empty());
|
||||
REQUIRE(files.size() == 1);
|
||||
CHECK(fs::path(files.front()).filename() == "grain.png");
|
||||
}
|
||||
|
||||
TEST_CASE("A directory reached with a parent-directory escape is refused", "[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir parent("tex-escape");
|
||||
const fs::path root = parent.path() / "pack";
|
||||
const fs::path outside = parent.path() / "outside";
|
||||
fs::create_directories(root);
|
||||
write_text_file(outside / "leak.png");
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files =
|
||||
collect_resource_texture_files((root / ".." / "outside").string(), root.string(), error);
|
||||
|
||||
CHECK(files.empty());
|
||||
CHECK_FALSE(error.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("An absolute directory outside the plugin folder is refused", "[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir root("tex-abs-root");
|
||||
ScopedTemporaryDir elsewhere("tex-abs-elsewhere");
|
||||
write_text_file(elsewhere.path() / "leak.png");
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files = collect_resource_texture_files(elsewhere.string(), root.string(), error);
|
||||
|
||||
CHECK(files.empty());
|
||||
CHECK_FALSE(error.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("A symlink pointing outside the plugin folder is skipped, not reported as an error", "[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir root("tex-symlink-root");
|
||||
ScopedTemporaryDir target("tex-symlink-target");
|
||||
write_text_file(target.path() / "secret.png");
|
||||
|
||||
const fs::path link = root.path() / "textures" / "link.png";
|
||||
fs::create_directories(link.parent_path());
|
||||
boost::system::error_code ec;
|
||||
fs::create_symlink(target.path() / "secret.png", link, ec);
|
||||
if (ec)
|
||||
SKIP("symlinks unavailable on this filesystem: " + ec.message());
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files =
|
||||
collect_resource_texture_files(link.parent_path().string(), root.string(), error);
|
||||
|
||||
// The directory itself is legitimate; the escaping link is dropped, not an error.
|
||||
CHECK(error.empty());
|
||||
CHECK(files.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Files in a subdirectory of the texture directory are not listed", "[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir root("tex-recursive");
|
||||
write_text_file(root.path() / "top.png");
|
||||
write_text_file(root.path() / "nested" / "deep.png");
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files = collect_resource_texture_files(root.string(), root.string(), error);
|
||||
|
||||
CHECK(error.empty());
|
||||
REQUIRE(files.size() == 1);
|
||||
CHECK(fs::path(files.front()).filename() == "top.png");
|
||||
}
|
||||
|
||||
TEST_CASE("An entry that is not a regular file is skipped", "[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir root("tex-nonregular");
|
||||
write_text_file(root.path() / "real.png");
|
||||
fs::create_directories(root.path() / "fake.png"); // a directory named like an image
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files = collect_resource_texture_files(root.string(), root.string(), error);
|
||||
|
||||
CHECK(error.empty());
|
||||
REQUIRE(files.size() == 1);
|
||||
CHECK(fs::path(files.front()).filename() == "real.png");
|
||||
}
|
||||
|
||||
TEST_CASE("Image extensions are matched case-insensitively and other extensions are ignored",
|
||||
"[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir root("tex-extensions");
|
||||
for (const char* name : { "a.png", "b.PNG", "c.jpg", "d.JPG", "e.jpeg", "f.JPEG", "g.bmp", "h.BMP" })
|
||||
write_text_file(root.path() / name);
|
||||
for (const char* name : { "i.txt", "j.gif", "k.pngx", "l.pn", "m.png.bak" })
|
||||
write_text_file(root.path() / name);
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files = collect_resource_texture_files(root.string(), root.string(), error);
|
||||
|
||||
CHECK(error.empty());
|
||||
CHECK(files.size() == 8);
|
||||
|
||||
std::vector<std::string> names;
|
||||
for (const std::string& file : files)
|
||||
names.push_back(fs::path(file).filename().string());
|
||||
for (const char* accepted : { "a.png", "b.PNG", "c.jpg", "d.JPG", "e.jpeg", "f.JPEG", "g.bmp", "h.BMP" })
|
||||
CHECK(std::find(names.begin(), names.end(), accepted) != names.end());
|
||||
for (const char* rejected : { "i.txt", "j.gif", "k.pngx", "l.pn", "m.png.bak" })
|
||||
CHECK(std::find(names.begin(), names.end(), rejected) == names.end());
|
||||
}
|
||||
|
||||
TEST_CASE("The listing stops at 64 image files", "[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir root("tex-cap");
|
||||
for (int i = 0; i < 70; ++i)
|
||||
write_text_file(root.path() / ("file" + std::to_string(i) + ".png"));
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files = collect_resource_texture_files(root.string(), root.string(), error);
|
||||
|
||||
CHECK(error.empty());
|
||||
CHECK(files.size() == 64);
|
||||
}
|
||||
|
||||
TEST_CASE("A missing texture directory yields no files and an error", "[PluginResourceTexture]")
|
||||
{
|
||||
ScopedTemporaryDir root("tex-missing");
|
||||
|
||||
std::string error;
|
||||
const std::vector<std::string> files =
|
||||
collect_resource_texture_files((root.path() / "textures").string(), root.string(), error);
|
||||
|
||||
CHECK(files.empty());
|
||||
CHECK_FALSE(error.empty());
|
||||
}
|
||||
|
||||
// ── Lifecycle through the real listing ──────────────────────────────────────────────────────────
|
||||
|
||||
TEST_CASE("A resource-texture pack's images appear in the listing and clear on disable and unload",
|
||||
"[PluginResourceTexture][PluginLifecycle][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("texture-listing");
|
||||
|
||||
const std::string plugin_key = "Texture_Pack";
|
||||
const fs::path plugin_dir =
|
||||
write_plugin(data_dir_guard, plugin_key, make_resource_texture_source("Texture Pack", default_texture_dir_body()));
|
||||
|
||||
const fs::path textures = plugin_dir / "textures";
|
||||
write_gray_png(textures / "alpha.png", 0x20);
|
||||
write_gray_png(textures / "beta.png", 0x80);
|
||||
write_text_file(textures / "gamma.jpg"); // the listing only checks the extension; decode is covered below
|
||||
write_text_file(textures / "notes.txt");
|
||||
|
||||
// A user-owned texture, so the listing has a non-pack entry whose provenance must be empty.
|
||||
write_gray_png(fs::path(GUI::user_texture_dir()) / "user_made.png", 0x40);
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
install_resource_texture_wiring();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE(load_and_wait(manager, plugin_key, error));
|
||||
INFO("load error: " << error);
|
||||
CHECK(error.empty());
|
||||
|
||||
CHECK(PluginResourceTextures::instance().entries().size() == 1);
|
||||
|
||||
const uint64_t loaded_generation = GUI::texture_library_generation();
|
||||
const auto loaded = plugin_textures(true);
|
||||
REQUIRE(loaded.size() == 3);
|
||||
std::vector<std::string> names;
|
||||
for (const GUI::TextureLibraryEntry& entry : loaded)
|
||||
names.push_back(entry.name);
|
||||
CHECK(std::find(names.begin(), names.end(), "alpha") != names.end());
|
||||
CHECK(std::find(names.begin(), names.end(), "beta") != names.end());
|
||||
CHECK(std::find(names.begin(), names.end(), "gamma") != names.end());
|
||||
CHECK(std::find(names.begin(), names.end(), "notes") == names.end());
|
||||
|
||||
// Every pack entry names its contributing pack; shipped and user entries carry no pack.
|
||||
for (const GUI::TextureLibraryEntry& entry : GUI::texture_library(true)) {
|
||||
if (entry.source == GUI::TextureSource::Plugin) {
|
||||
CHECK_FALSE(entry.pack_name.empty());
|
||||
CHECK(entry.pack_name == "Texture Pack");
|
||||
} else {
|
||||
CHECK(entry.pack_name.empty());
|
||||
}
|
||||
}
|
||||
|
||||
// A no-argument call reuses the cached listing until a pack callback moves the generation.
|
||||
CHECK(plugin_textures(false).size() == 3);
|
||||
|
||||
manager.set_capability_enabled({ PluginCapabilityType::ResourceTexture, "Texture Pack", plugin_key }, false);
|
||||
CHECK(GUI::texture_library_generation() > loaded_generation);
|
||||
CHECK(PluginResourceTextures::instance().entries().empty());
|
||||
CHECK(plugin_textures(false).empty());
|
||||
|
||||
manager.set_capability_enabled({ PluginCapabilityType::ResourceTexture, "Texture Pack", plugin_key }, true);
|
||||
CHECK(plugin_textures(false).size() == 3);
|
||||
|
||||
REQUIRE(manager.unload_plugin(plugin_key));
|
||||
CHECK(PluginResourceTextures::instance().entries().empty());
|
||||
CHECK(plugin_textures(false).empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Two distinctly named packs each list as one contiguous run",
|
||||
"[PluginResourceTexture][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("texture-contiguous");
|
||||
|
||||
// Loaded out of name order, so it is the listing's pack-name sort that orders the runs.
|
||||
const std::string key_zeta = "Pack_Zeta";
|
||||
const std::string key_alpha = "Pack_Alpha";
|
||||
|
||||
const fs::path dir_zeta = write_plugin(
|
||||
data_dir_guard, key_zeta, make_resource_texture_source("Zeta Pack", default_texture_dir_body()));
|
||||
const fs::path dir_alpha = write_plugin(
|
||||
data_dir_guard, key_alpha, make_resource_texture_source("Alpha Pack", default_texture_dir_body()));
|
||||
|
||||
write_gray_png(dir_zeta / "textures" / "zeta_one.png", 0x20);
|
||||
write_gray_png(dir_zeta / "textures" / "zeta_two.png", 0x40);
|
||||
write_gray_png(dir_alpha / "textures" / "alpha_one.png", 0x60);
|
||||
write_gray_png(dir_alpha / "textures" / "alpha_two.png", 0x80);
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
install_resource_texture_wiring();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE(load_and_wait(manager, key_zeta, error));
|
||||
REQUIRE(load_and_wait(manager, key_alpha, error));
|
||||
|
||||
std::vector<GUI::TextureLibraryEntry> pack_entries;
|
||||
for (const GUI::TextureLibraryEntry& entry : GUI::texture_library(true))
|
||||
if (entry.source == GUI::TextureSource::Plugin)
|
||||
pack_entries.push_back(entry);
|
||||
REQUIRE(pack_entries.size() == 4);
|
||||
|
||||
const auto count_pack = [&pack_entries](const std::string& name) {
|
||||
return std::count_if(pack_entries.begin(), pack_entries.end(),
|
||||
[&name](const GUI::TextureLibraryEntry& e) { return e.pack_name == name; });
|
||||
};
|
||||
CHECK(count_pack("Zeta Pack") == 2);
|
||||
CHECK(count_pack("Alpha Pack") == 2);
|
||||
|
||||
// Collapsing consecutive entries by pack name must leave one run per pack: a name never reappears
|
||||
// after another name intervenes, which is what lets the picker draw one section per pack.
|
||||
std::vector<std::string> runs;
|
||||
for (const GUI::TextureLibraryEntry& entry : pack_entries)
|
||||
if (runs.empty() || runs.back() != entry.pack_name)
|
||||
runs.push_back(entry.pack_name);
|
||||
|
||||
std::vector<std::string> sorted_runs = runs;
|
||||
std::sort(sorted_runs.begin(), sorted_runs.end());
|
||||
CHECK(std::unique(sorted_runs.begin(), sorted_runs.end()) == sorted_runs.end());
|
||||
CHECK(runs == std::vector<std::string>({ "Alpha Pack", "Zeta Pack" }));
|
||||
|
||||
manager.unload_plugin(key_zeta);
|
||||
manager.unload_plugin(key_alpha);
|
||||
}
|
||||
|
||||
TEST_CASE("A second pack declaring a loaded capability name is refused",
|
||||
"[PluginResourceTexture][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("texture-capability-clash");
|
||||
|
||||
// Distinct package names, one capability name: the loader allows only the first.
|
||||
const std::string key_first = "Clash_First";
|
||||
const std::string key_second = "Clash_Second";
|
||||
const std::string capability = "Shared Textures";
|
||||
|
||||
const fs::path dir_first = write_plugin(
|
||||
data_dir_guard, key_first,
|
||||
make_resource_texture_source("Clash Package One", default_texture_dir_body(), capability));
|
||||
write_plugin(data_dir_guard, key_second,
|
||||
make_resource_texture_source("Clash Package Two", default_texture_dir_body(), capability));
|
||||
|
||||
write_gray_png(dir_first / "textures" / "one.png", 0x20);
|
||||
write_gray_png(dir_first / "textures" / "two.png", 0x40);
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
install_resource_texture_wiring();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE(load_and_wait(manager, key_first, error));
|
||||
REQUIRE(manager.is_plugin_loaded(key_first));
|
||||
|
||||
const std::vector<GUI::TextureLibraryEntry> before = plugin_textures(true);
|
||||
REQUIRE(before.size() == 2);
|
||||
for (const GUI::TextureLibraryEntry& entry : before)
|
||||
CHECK(entry.pack_name == capability);
|
||||
|
||||
// The second package claims the capability name the first already owns, so the load is refused.
|
||||
std::string second_error;
|
||||
CHECK_FALSE(load_and_wait(manager, key_second, second_error));
|
||||
CHECK_FALSE(manager.is_plugin_loaded(key_second));
|
||||
|
||||
// The first pack's textures are untouched by the refused load.
|
||||
const std::vector<GUI::TextureLibraryEntry> after = plugin_textures(true);
|
||||
REQUIRE(after.size() == before.size());
|
||||
for (size_t i = 0; i < before.size(); ++i) {
|
||||
CHECK(after[i].name == before[i].name);
|
||||
CHECK(after[i].path == before[i].path);
|
||||
CHECK(after[i].pack_name == before[i].pack_name);
|
||||
}
|
||||
|
||||
manager.unload_plugin(key_first);
|
||||
}
|
||||
|
||||
TEST_CASE("A resource-texture pack with no images contributes no textures", "[PluginResourceTexture][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("texture-empty");
|
||||
|
||||
const std::string plugin_key = "Empty_Pack";
|
||||
const fs::path plugin_dir =
|
||||
write_plugin(data_dir_guard, plugin_key, make_resource_texture_source("Empty Pack", default_texture_dir_body()));
|
||||
fs::create_directories(plugin_dir / "textures"); // valid, but empty
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
install_resource_texture_wiring();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE(load_and_wait(manager, plugin_key, error));
|
||||
CHECK(manager.is_plugin_loaded(plugin_key));
|
||||
CHECK(plugin_textures(true).empty());
|
||||
|
||||
manager.unload_plugin(plugin_key);
|
||||
}
|
||||
|
||||
// ── Hostile get_texture_dir() overrides ─────────────────────────────────────────────────────────
|
||||
|
||||
TEST_CASE("A texture directory outside the plugin root contributes no textures", "[PluginResourceTexture][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("texture-hostile");
|
||||
ScopedResourcesDir resources_dir_guard("texture-hostile-res");
|
||||
write_text_file(fs::path(resources_dir_guard.dir) / "sentinel.png"); // would list if it were scanned
|
||||
|
||||
const std::string data_pack = "Data_Dir_Pack";
|
||||
write_plugin(data_dir_guard, data_pack,
|
||||
make_resource_texture_source("Data Dir Pack", "return r\"" + data_dir_guard.dir.string() + "\""));
|
||||
const std::string resources_pack = "Resources_Dir_Pack";
|
||||
write_plugin(data_dir_guard, resources_pack,
|
||||
make_resource_texture_source("Resources Dir Pack", "return r\"" + resources_dir_guard.dir.string() + "\""));
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
install_resource_texture_wiring();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE(load_and_wait(manager, data_pack, error));
|
||||
REQUIRE(load_and_wait(manager, resources_pack, error));
|
||||
|
||||
// The packs load; their out-of-root directories are simply refused.
|
||||
CHECK(manager.is_plugin_loaded(data_pack));
|
||||
CHECK(manager.is_plugin_loaded(resources_pack));
|
||||
CHECK(PluginResourceTextures::instance().entries().empty());
|
||||
CHECK(plugin_textures(true).empty());
|
||||
|
||||
manager.unload_plugin(data_pack);
|
||||
manager.unload_plugin(resources_pack);
|
||||
}
|
||||
|
||||
TEST_CASE("A raising get_texture_dir leaves the pack loaded with no textures", "[PluginResourceTexture][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("texture-raising");
|
||||
|
||||
const std::string plugin_key = "Raising_Pack";
|
||||
write_plugin(data_dir_guard, plugin_key,
|
||||
make_resource_texture_source("Raising Pack", "raise RuntimeError(\"no textures today\")"));
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
install_resource_texture_wiring();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE(load_and_wait(manager, plugin_key, error));
|
||||
CHECK(error.empty());
|
||||
CHECK(manager.is_plugin_loaded(plugin_key));
|
||||
CHECK(PluginResourceTextures::instance().entries().empty());
|
||||
CHECK(plugin_textures(true).empty());
|
||||
|
||||
manager.unload_plugin(plugin_key);
|
||||
}
|
||||
|
||||
// ── Decoding parity ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
TEST_CASE("Pack images decode through the same path as hand-picked files", "[PluginResourceTexture]")
|
||||
{
|
||||
ensure_wx_image_handlers();
|
||||
|
||||
ScopedTemporaryDir pack_root("tex-pack");
|
||||
ScopedTemporaryDir hand_root("tex-hand");
|
||||
const fs::path pack_dir = pack_root.path() / "textures";
|
||||
fs::create_directories(pack_dir);
|
||||
|
||||
// PNG: grayscale, so load_texture_image_data passes it through verbatim.
|
||||
const fs::path pack_png = pack_dir / "grain.png";
|
||||
write_gray_png(pack_png, 0x40);
|
||||
const std::vector<unsigned char> png_bytes = read_file_bytes(pack_png);
|
||||
REQUIRE_FALSE(png_bytes.empty());
|
||||
write_bytes(hand_root.path() / "grain.png", png_bytes);
|
||||
|
||||
// BMP: not a PNG, so it goes through wxImage and is re-encoded; the same file must give the same
|
||||
// bytes wherever it sits.
|
||||
const std::vector<unsigned char> bmp_bytes = make_gray_bmp(4, 4, 0x40);
|
||||
const fs::path pack_bmp = pack_dir / "bump.bmp";
|
||||
write_bytes(pack_bmp, bmp_bytes);
|
||||
const fs::path hand_bmp = hand_root.path() / "bump.bmp";
|
||||
write_bytes(hand_bmp, bmp_bytes);
|
||||
|
||||
// The collector lists both pack files, so these are the paths a pack would serve.
|
||||
std::string collect_error;
|
||||
const std::vector<std::string> pack_files =
|
||||
collect_resource_texture_files(pack_dir.string(), pack_root.string(), collect_error);
|
||||
REQUIRE(collect_error.empty());
|
||||
CHECK(pack_files.size() == 2);
|
||||
|
||||
std::string pack_error;
|
||||
std::string hand_error;
|
||||
|
||||
const auto pack_png_decoded = GUI::load_texture_image_data(pack_png.string(), pack_error);
|
||||
const auto hand_png_decoded = GUI::load_texture_image_data((hand_root.path() / "grain.png").string(), hand_error);
|
||||
REQUIRE(pack_png_decoded != nullptr);
|
||||
REQUIRE(hand_png_decoded != nullptr);
|
||||
CHECK(*pack_png_decoded == png_bytes); // supported PNG is passed through unchanged
|
||||
CHECK(*pack_png_decoded == *hand_png_decoded);
|
||||
|
||||
const auto pack_bmp_decoded = GUI::load_texture_image_data(pack_bmp.string(), pack_error);
|
||||
const auto hand_bmp_decoded = GUI::load_texture_image_data(hand_bmp.string(), hand_error);
|
||||
REQUIRE(pack_bmp_decoded != nullptr);
|
||||
REQUIRE(hand_bmp_decoded != nullptr);
|
||||
REQUIRE_FALSE(pack_bmp_decoded->empty());
|
||||
CHECK(*pack_bmp_decoded == *hand_bmp_decoded);
|
||||
}
|
||||
|
||||
TEST_CASE("Reinstalling a pack with different bytes at the same path changes the decoded content",
|
||||
"[PluginResourceTexture][Python]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("texture-reinstall");
|
||||
|
||||
const std::string plugin_key = "Reinstall_Pack";
|
||||
const fs::path plugin_dir =
|
||||
write_plugin(data_dir_guard, plugin_key, make_resource_texture_source("Reinstall Pack", default_texture_dir_body()));
|
||||
const fs::path texture = plugin_dir / "textures" / "grain.png";
|
||||
write_gray_png(texture, 0x10);
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
install_resource_texture_wiring();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE(load_and_wait(manager, plugin_key, error));
|
||||
|
||||
auto loaded = plugin_textures(true);
|
||||
REQUIRE(loaded.size() == 1);
|
||||
const std::string path = loaded.front().path;
|
||||
|
||||
std::string decode_error;
|
||||
const auto first = GUI::load_texture_image_data(path, decode_error);
|
||||
REQUIRE(first != nullptr);
|
||||
|
||||
REQUIRE(manager.unload_plugin(plugin_key));
|
||||
|
||||
// The reinstalled pack writes different bytes to the same file path.
|
||||
write_gray_png(texture, 0xE0);
|
||||
REQUIRE(load_and_wait(manager, plugin_key, error));
|
||||
|
||||
loaded = plugin_textures(true);
|
||||
REQUIRE(loaded.size() == 1);
|
||||
CHECK(loaded.front().path == path);
|
||||
|
||||
const auto second = GUI::load_texture_image_data(path, decode_error);
|
||||
REQUIRE(second != nullptr);
|
||||
CHECK(*first != *second);
|
||||
}
|
||||
|
||||
// ── Wheel metadata ──────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
TEST_CASE("A minimal resource-texture wheel is accepted", "[PluginResourceTexture][Wheel]")
|
||||
{
|
||||
ScopedTemporaryDir dir("texture-wheel");
|
||||
const fs::path wheel = dir.path() / "texture_pack-1.0-py3-none-any.whl";
|
||||
|
||||
const std::string dist_info = "texture_pack-1.0.dist-info";
|
||||
const std::string metadata =
|
||||
"Metadata-Version: 2.1\n"
|
||||
"Name: texture_pack\n"
|
||||
"Version: 1.0\n"
|
||||
"Summary: Resource texture pack fixture\n"
|
||||
"Author: tests\n";
|
||||
const std::string wheel_metadata =
|
||||
"Wheel-Version: 1.0\n"
|
||||
"Generator: manual\n"
|
||||
"Root-Is-Purelib: true\n"
|
||||
"Tag: py3-none-any\n";
|
||||
const std::string record = dist_info + "/METADATA,,\n" + dist_info + "/WHEEL,,\n" + dist_info + "/RECORD,,\n";
|
||||
const std::string top_level = "texture_pack\n";
|
||||
|
||||
{
|
||||
Zipper zipper(wheel.string(), Zipper::NO_COMPRESSION);
|
||||
zipper.add_entry(dist_info + "/METADATA", metadata.data(), metadata.size());
|
||||
zipper.add_entry(dist_info + "/WHEEL", wheel_metadata.data(), wheel_metadata.size());
|
||||
zipper.add_entry(dist_info + "/RECORD", record.data(), record.size());
|
||||
// read_wheel_plugin_metadata leaves `error` set when an optional top_level.txt is missing.
|
||||
zipper.add_entry(dist_info + "/top_level.txt", top_level.data(), top_level.size());
|
||||
zipper.finalize();
|
||||
}
|
||||
|
||||
PluginDescriptor descriptor;
|
||||
std::string error;
|
||||
REQUIRE(read_wheel_plugin_metadata(wheel, descriptor, error));
|
||||
INFO("wheel metadata error: " << error);
|
||||
CHECK(error.empty());
|
||||
CHECK(descriptor.name == "texture_pack");
|
||||
CHECK(descriptor.version == "1.0");
|
||||
CHECK(descriptor.entry_package == "texture_pack");
|
||||
}
|
||||
|
||||
// ── .3mf round trip ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
TEST_CASE("A project keeps a pack texture after the pack is uninstalled",
|
||||
"[PluginResourceTexture][PluginLifecycle][Python][3mf]")
|
||||
{
|
||||
ScopedPluginManager plugin_system;
|
||||
if (!plugin_system.initialized)
|
||||
SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
|
||||
|
||||
ScopedDataDir data_dir_guard("texture-3mf");
|
||||
|
||||
const std::string plugin_key = "Texture_Pack_3mf";
|
||||
const fs::path plugin_dir =
|
||||
write_plugin(data_dir_guard, plugin_key, make_resource_texture_source("Texture Pack", default_texture_dir_body()));
|
||||
write_gray_png(plugin_dir / "textures" / "grain.png", 0x60);
|
||||
|
||||
PluginManager& manager = PluginManager::instance();
|
||||
install_resource_texture_wiring();
|
||||
manager.discover_plugins(/*async=*/false, /*clear=*/true);
|
||||
|
||||
std::string error;
|
||||
REQUIRE(load_and_wait(manager, plugin_key, error));
|
||||
|
||||
const auto loaded = plugin_textures(true);
|
||||
REQUIRE(loaded.size() == 1);
|
||||
|
||||
std::string decode_error;
|
||||
const auto pack_bytes = GUI::load_texture_image_data(loaded.front().path, decode_error);
|
||||
REQUIRE(pack_bytes != nullptr);
|
||||
REQUIRE_FALSE(pack_bytes->empty());
|
||||
|
||||
// Build a project the way the gizmo would: the layer carries the pack texture's bytes.
|
||||
Model model;
|
||||
ModelObject* object = model.add_object();
|
||||
ModelVolume* volume = object->add_volume(make_cube(10., 10., 10.));
|
||||
object->add_instance();
|
||||
TextureDisplacementLayer layer;
|
||||
layer.slot = 0;
|
||||
layer.name = loaded.front().name;
|
||||
layer.path = loaded.front().path;
|
||||
layer.image_data = pack_bytes;
|
||||
volume->texture_displacement_layers.push_back(layer);
|
||||
|
||||
ScopedTemporaryFile first(".3mf");
|
||||
store_project(model, first.string());
|
||||
|
||||
// Uninstall the pack; the project still has to open and re-save with the same image bytes.
|
||||
REQUIRE(manager.unload_plugin(plugin_key));
|
||||
CHECK(plugin_textures(true).empty());
|
||||
|
||||
ScopedTemporaryDir backup_dir("orca_tex_pack_dst");
|
||||
Model reloaded;
|
||||
REQUIRE(load_project(first.string(), reloaded, backup_dir));
|
||||
REQUIRE(reloaded.objects.size() == 1);
|
||||
REQUIRE(reloaded.objects.front()->volumes.size() == 1);
|
||||
const std::vector<TextureDisplacementLayer>& reloaded_layers =
|
||||
reloaded.objects.front()->volumes.front()->texture_displacement_layers;
|
||||
REQUIRE(reloaded_layers.size() == 1);
|
||||
REQUIRE(reloaded_layers.front().image_data);
|
||||
CHECK(*reloaded_layers.front().image_data == *pack_bytes);
|
||||
|
||||
ScopedTemporaryFile second(".3mf");
|
||||
store_project(reloaded, second.string());
|
||||
|
||||
ScopedTemporaryDir backup_dir2("orca_tex_pack_dst2");
|
||||
Model reloaded_again;
|
||||
REQUIRE(load_project(second.string(), reloaded_again, backup_dir2));
|
||||
REQUIRE(reloaded_again.objects.size() == 1);
|
||||
REQUIRE(reloaded_again.objects.front()->volumes.size() == 1);
|
||||
const std::vector<TextureDisplacementLayer>& again_layers =
|
||||
reloaded_again.objects.front()->volumes.front()->texture_displacement_layers;
|
||||
REQUIRE(again_layers.size() == 1);
|
||||
REQUIRE(again_layers.front().image_data);
|
||||
CHECK(*again_layers.front().image_data == *pack_bytes);
|
||||
}
|
||||
Reference in New Issue
Block a user