implement export cube faces

This commit is contained in:
2019-08-16 12:23:34 +02:00
parent fa94aa632f
commit a8e9e92d96
8 changed files with 83 additions and 83 deletions

View File

@@ -1921,7 +1921,6 @@ void Canvas::export_layers(std::string file_name, std::function<void()> on_compl
void Canvas::export_layers_thread(std::string file_name)
{
static std::array<const char*, 6> plane_names { "front", "right", "back", "left", "top", "bottom" };
auto pb = App::I->show_progress("Export Layers", m_layers.size());
for (int i = 0; i < m_layers.size(); i++)
{
@@ -1933,67 +1932,51 @@ void Canvas::export_layers_thread(std::string file_name)
pb->destroy();
}
void Canvas::export_cubes()
void Canvas::export_cube_faces(std::string file_name, std::function<void()> on_complete)
{
if (App::I->check_license())
{
std::thread t([=] {
BT_SetTerminate();
export_cube_faces_thread(file_name);
if (on_complete)
on_complete();
});
t.detach();
}
}
void Canvas::export_cube_faces_thread(std::string file_name)
{
if (!App::I->check_license())
return;
#ifdef __OBJC__
NSMutableArray* files = [NSMutableArray array];
#endif
std::array<std::string, 6> names {
"pz", "px", "nz", "nx",
"py", "ny"
};
const int stride = m_width * 4;
auto buffer = std::make_unique<uint8_t[]>(m_width * m_height * 4);
auto flipped = std::make_unique<uint8_t[]>(m_width * m_height * 4);
for (int layer = 0; layer < m_layers.size(); layer++)
static std::array<const char*, 6> plane_names{ "front", "right", "back", "left", "top", "bottom" };
auto pb = App::I->show_progress("Export Cube Faces", 7);
App::I->render_task([this] {
draw_merge(false);
});
pb->increment();
for (int i = 0; i < 6; i++)
{
for (int plane = 0; plane < 6; plane++)
{
auto& l = m_layers[layer];
l->m_rtt[plane].bindFramebuffer();
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, buffer.get());
l->m_rtt[plane].unbindFramebuffer();
if (plane < 4)
{
for (int y = 0; y < m_height; y++)
{
int y_rev = m_height - y - 1;
std::copy_n(buffer.get() + y * stride, stride, flipped.get() + y_rev * stride);
}
std::swap(buffer, flipped);
}
else
{
for (int y = 0; y < m_height; y++)
{
auto src = (glm::u8vec4*)(buffer.get() + y * stride);
auto dst = (glm::u8vec4*)(flipped.get() + y * stride);
for (int x = 0; x < m_width; x++)
{
int x_rev = m_width - x - 1;
dst[x_rev] = src[x];
}
//std::copy_backward(src + stride, src, dst + stride);
}
std::swap(buffer, flipped);
}
static char name[128];
sprintf(name, "%s-%02d-%d.png", App::I->work_path.c_str(), layer, plane);
int ret = stbi_write_png(name, m_width, m_height, 4, buffer.get(), 0);
Image face = m_layers_merge.m_rtt[i].get_image();
std::string path = fmt::format("{}/{}-{}.png", App::I->work_path, file_name, plane_names[i]);
face.save_png(path);
pb->increment();
#ifdef __IOS__
save_image_library(name);
save_image_library(name);
#endif
#ifdef __OBJC__
[files addObject:[NSString stringWithUTF8String : name]];
[files addObject : [NSString stringWithUTF8String:path.c_str()] ];
#endif
}
}
}
pb->destroy();
#ifdef __OBJC__
static char name[128];
sprintf(name, "%s.zip", App::I->work_path.c_str());