mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 01:20:25 +08:00
Tango: fixed sketchfab export ply error, exported objs are now rotated -90deg x-axis by default for sketchfab
This commit is contained in:
@@ -2480,8 +2480,15 @@ bool RTABMapApp::exportMesh(
|
||||
}
|
||||
else if(textureMesh->tex_materials.size())
|
||||
{
|
||||
// With Sketchfab, the OBJ models are rotated 90 degrees on x axis, so rotate -90 to have model in right position
|
||||
pcl::PointCloud<pcl::PointNormal>::Ptr cloud(new pcl::PointCloud<pcl::PointNormal>);
|
||||
pcl::fromPCLPointCloud2(textureMesh->cloud, *cloud);
|
||||
pcl::PCLPointCloud2 tmp = textureMesh->cloud;
|
||||
cloud = rtabmap::util3d::transformPointCloud(cloud, rtabmap::Transform(1,0,0,0, 0,0,1,0, 0,-1,0,0));
|
||||
pcl::toPCLPointCloud2(*cloud, textureMesh->cloud);
|
||||
LOGI("Saving obj (%d vertices, %d polygons) to %s.", (int)textureMesh->cloud.data.size()/textureMesh->cloud.point_step, totalPolygons, filePath.c_str());
|
||||
success = pcl::io::saveOBJFile(filePath, *textureMesh) == 0;
|
||||
textureMesh->cloud = tmp;
|
||||
if(success)
|
||||
{
|
||||
LOGI("Saved obj to %s!", filePath.c_str());
|
||||
|
||||
@@ -1168,41 +1168,6 @@ public class RTABMapActivity extends Activity implements OnClickListener {
|
||||
|
||||
private RTABMapActivity getActivity() {return this;}
|
||||
|
||||
private String[] loadFileList(String directory, final boolean databasesOnly) {
|
||||
File path = new File(directory);
|
||||
String fileList[];
|
||||
try {
|
||||
path.mkdirs();
|
||||
}
|
||||
catch(SecurityException e) {
|
||||
Log.e(TAG, "unable to write on the sd card " + e.toString());
|
||||
}
|
||||
if(path.exists()) {
|
||||
FilenameFilter filter = new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String filename) {
|
||||
File sel = new File(dir, filename);
|
||||
if(databasesOnly)
|
||||
{
|
||||
return filename.compareTo(RTABMAP_TMP_DB) != 0 && filename.endsWith(".db");
|
||||
}
|
||||
else
|
||||
{
|
||||
return sel.isFile();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
fileList = path.list(filter);
|
||||
Arrays.sort(fileList);
|
||||
}
|
||||
else {
|
||||
fileList = new String[0];
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
|
||||
private void standardOptimization() {
|
||||
mExportProgressDialog.setTitle("Post-Processing");
|
||||
mExportProgressDialog.setMessage(String.format("Please wait while optimizing..."));
|
||||
@@ -1800,7 +1765,7 @@ public class RTABMapActivity extends Activity implements OnClickListener {
|
||||
}
|
||||
else if(itemId == R.id.open)
|
||||
{
|
||||
final String[] files = loadFileList(mWorkingDirectory, true);
|
||||
final String[] files = Util.loadFileList(mWorkingDirectory, true);
|
||||
if(files.length > 0)
|
||||
{
|
||||
String[] filesWithSize = new String[files.length];
|
||||
@@ -1885,7 +1850,7 @@ public class RTABMapActivity extends Activity implements OnClickListener {
|
||||
|
||||
File tmpDir = new File(mWorkingDirectory + RTABMAP_TMP_DIR);
|
||||
tmpDir.mkdirs();
|
||||
String[] fileNames = loadFileList(mWorkingDirectory + RTABMAP_TMP_DIR, false);
|
||||
String[] fileNames = Util.loadFileList(mWorkingDirectory + RTABMAP_TMP_DIR, false);
|
||||
if(!DISABLE_LOG) Log.i(TAG, String.format("Deleting %d files in \"%s\"", fileNames.length, mWorkingDirectory + RTABMAP_TMP_DIR));
|
||||
for(int i=0; i<fileNames.length; ++i)
|
||||
{
|
||||
@@ -2164,7 +2129,7 @@ public class RTABMapActivity extends Activity implements OnClickListener {
|
||||
final String zipOutput = mWorkingDirectory+RTABMAP_EXPORT_DIR+fileName+".zip";
|
||||
pathHuman = mWorkingDirectoryHuman + RTABMAP_EXPORT_DIR + fileName + ".zip";
|
||||
|
||||
String[] fileNames = loadFileList(mWorkingDirectory + RTABMAP_TMP_DIR, false);
|
||||
String[] fileNames = Util.loadFileList(mWorkingDirectory + RTABMAP_TMP_DIR, false);
|
||||
if(fileNames.length > 0)
|
||||
{
|
||||
String[] filesToZip = new String[fileNames.length];
|
||||
|
||||
@@ -135,15 +135,14 @@ public class SketchfabActivity extends Activity implements OnClickListener {
|
||||
// verify if we have all files
|
||||
if(extension.compareTo(".obj") == 0)
|
||||
{
|
||||
File objFile = new File(mWorkingDirectory + RTABMapActivity.RTABMAP_TMP_DIR + RTABMapActivity.RTABMAP_TMP_FILENAME + ".obj");
|
||||
File mltFile = new File(mWorkingDirectory + RTABMapActivity.RTABMAP_TMP_DIR + RTABMapActivity.RTABMAP_TMP_FILENAME + ".mtl");
|
||||
File jpgFile = new File(mWorkingDirectory + RTABMapActivity.RTABMAP_TMP_DIR + RTABMapActivity.RTABMAP_TMP_FILENAME + ".jpg");
|
||||
if(objFile.exists() && mltFile.exists() && jpgFile.exists())
|
||||
String[] fileNames = Util.loadFileList(mWorkingDirectory + RTABMapActivity.RTABMAP_TMP_DIR, false);
|
||||
if(fileNames.length > 0)
|
||||
{
|
||||
files = new String[3];
|
||||
files[0] = objFile.getAbsolutePath();
|
||||
files[1] = mltFile.getAbsolutePath();
|
||||
files[2] = jpgFile.getAbsolutePath();
|
||||
files = new String[fileNames.length];
|
||||
for(int i=0; i<fileNames.length; ++i)
|
||||
{
|
||||
files[i] = mWorkingDirectory + RTABMapActivity.RTABMAP_TMP_DIR + "/" + fileNames[i];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -152,7 +151,7 @@ public class SketchfabActivity extends Activity implements OnClickListener {
|
||||
}
|
||||
else if(extension.compareTo(".ply") == 0)
|
||||
{
|
||||
File plyFile = new File(mWorkingDirectory + RTABMapActivity.RTABMAP_TMP_DIR + RTABMapActivity.RTABMAP_TMP_FILENAME + extension);
|
||||
File plyFile = new File(mWorkingDirectory + RTABMapActivity.RTABMAP_TMP_DIR + "/" + RTABMapActivity.RTABMAP_TMP_FILENAME + extension);
|
||||
if(plyFile.exists())
|
||||
{
|
||||
files = new String[1];
|
||||
|
||||
@@ -2,9 +2,12 @@ package com.introlab.rtabmap;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@@ -52,5 +55,39 @@ public class Util {
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] loadFileList(String directory, final boolean databasesOnly) {
|
||||
File path = new File(directory);
|
||||
String fileList[];
|
||||
try {
|
||||
path.mkdirs();
|
||||
}
|
||||
catch(SecurityException e) {
|
||||
Log.e(RTABMapActivity.TAG, "unable to write on the sd card " + e.toString());
|
||||
}
|
||||
if(path.exists()) {
|
||||
FilenameFilter filter = new FilenameFilter() {
|
||||
|
||||
@Override
|
||||
public boolean accept(File dir, String filename) {
|
||||
File sel = new File(dir, filename);
|
||||
if(databasesOnly)
|
||||
{
|
||||
return filename.compareTo(RTABMapActivity.RTABMAP_TMP_DB) != 0 && filename.endsWith(".db");
|
||||
}
|
||||
else
|
||||
{
|
||||
return sel.isFile();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
fileList = path.list(filter);
|
||||
Arrays.sort(fileList);
|
||||
}
|
||||
else {
|
||||
fileList = new String[0];
|
||||
}
|
||||
return fileList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user