implement cubes exporter for web viewer
This commit is contained in:
@@ -1254,6 +1254,72 @@ void ui::Canvas::export_anim(std::string data_path)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void ui::Canvas::export_cubes(std::string data_path)
|
||||
{
|
||||
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 (auto i : m_order)
|
||||
{
|
||||
for (int plane = 0; plane < 6; plane++)
|
||||
{
|
||||
auto& l = m_layers[i];
|
||||
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", data_path.c_str(), i, plane);
|
||||
int ret = stbi_write_png(name, m_width, m_height, 4, buffer.get(), 0);
|
||||
|
||||
|
||||
#ifdef __IOS__
|
||||
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
|
||||
NSURL* url = [NSURL fileURLWithPath : [NSString stringWithUTF8String : name]];
|
||||
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImageAtFileURL : url];
|
||||
changeRequest.creationDate = [NSDate date];
|
||||
} completionHandler: ^ (BOOL success, NSError *error) {
|
||||
if (success) {
|
||||
NSLog(@"successfully saved");
|
||||
}
|
||||
else {
|
||||
NSLog(@"error saving to photos : %@", error);
|
||||
}
|
||||
}];
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ui::Canvas::project_save(std::string file_path)
|
||||
{
|
||||
std::thread t(&ui::Canvas::project_save_thread, this, file_path);
|
||||
|
||||
Reference in New Issue
Block a user