|
@@ -1,10 +1,11 @@
|
|
|
package com.fdkk.sxz.util;
|
|
|
|
|
|
-import com.fdkk.sxz.proto.*;
|
|
|
-import com.google.protobuf.TextFormat;
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
import com.fdkk.sxz.constant.ConstantFileName;
|
|
|
import com.fdkk.sxz.constant.ConstantFilePath;
|
|
|
+import com.fdkk.sxz.proto.*;
|
|
|
import com.fdkk.sxz.proto.format.JsonFormat;
|
|
|
+import com.google.protobuf.TextFormat;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.io.*;
|
|
@@ -16,82 +17,82 @@ public class CreateObjUtil {
|
|
|
|
|
|
//开始建模
|
|
|
public static void build3dModel(String folderName, String isModel) throws Exception {
|
|
|
- log.info("开始建模");
|
|
|
+ CreateObjUtil.log.info("开始建模");
|
|
|
String command = "bash /home/ubuntu/bin/Launcher.sh " + folderName;
|
|
|
- callshell(command);
|
|
|
- log.info("计算完毕:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("计算完毕:" + command);
|
|
|
}
|
|
|
|
|
|
//开始建模
|
|
|
public static void fbxToObj(String filePath, String fbxPath, String objPath) throws Exception {
|
|
|
- log.info("fbx转换obj开始");
|
|
|
+ CreateObjUtil.log.info("fbx转换obj开始");
|
|
|
String command = "bash /home/shell/fbx/fbx.sh " + filePath + " " + fbxPath + " " + objPath;
|
|
|
- callshell(command);
|
|
|
- log.info("fbx转换obj完毕:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("fbx转换obj完毕:" + command);
|
|
|
}
|
|
|
|
|
|
//开始建模
|
|
|
public static void unRar(String objPath, String glbPath) throws Exception {
|
|
|
- log.info("解压rar开始");
|
|
|
+ CreateObjUtil.log.info("解压rar开始");
|
|
|
String command = "unrar e " + objPath + " " + glbPath;
|
|
|
- callshell(command);
|
|
|
- log.info("解压rar完毕:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("解压rar完毕:" + command);
|
|
|
}
|
|
|
|
|
|
public static void unZip(String objPath, String glbPath) throws Exception {
|
|
|
- log.info("解压zip开始");
|
|
|
+ CreateObjUtil.log.info("解压zip开始");
|
|
|
String command = "unzip -O GBK/GB18030CP936 " + objPath + " -d " + glbPath;
|
|
|
- callshell(command);
|
|
|
- log.info("解压zip完毕:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("解压zip完毕:" + command);
|
|
|
}
|
|
|
|
|
|
//开始建模
|
|
|
public static void objToGlb(String objPath, String glbPath) throws Exception {
|
|
|
- log.info("obj转换glb开始");
|
|
|
+ CreateObjUtil.log.info("obj转换glb开始");
|
|
|
String command = "obj2gltf " + objPath + " " + glbPath;
|
|
|
- log.info("执行obj转换glb命令路径-{}", command);
|
|
|
- callshell(command);
|
|
|
- log.info("obj转换glb完毕:" + command);
|
|
|
+ CreateObjUtil.log.info("执行obj转换glb命令路径-{}", command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("obj转换glb完毕:" + command);
|
|
|
}
|
|
|
|
|
|
public static void ossUtilCp(String fileUrl, String path) throws Exception {
|
|
|
String command = "bash /opt/ossutil/oss.sh " + fileUrl + " " + path;
|
|
|
Long start = System.currentTimeMillis();
|
|
|
- log.info("开始oss下载文件:" + command);
|
|
|
- callshell(command);
|
|
|
- log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
+ CreateObjUtil.log.info("开始oss下载文件:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
}
|
|
|
|
|
|
public static void ossCommonUtilCp(String fileUrl, String path) throws Exception {
|
|
|
String command = "/usr/bin/bash /opt/ossutil/ossCommon.sh " + fileUrl + File.separator + " " + path;
|
|
|
Long start = System.currentTimeMillis();
|
|
|
- log.info("开始oss下载文件:" + command);
|
|
|
- callshell(command);
|
|
|
- log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
+ CreateObjUtil.log.info("开始oss下载文件:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
}
|
|
|
|
|
|
public static void ossUploadCommon(String fileUrl, String path) throws Exception {
|
|
|
String command = "bash /opt/ossutil/ossUploadCommon.sh " + fileUrl + " " + path;
|
|
|
Long start = System.currentTimeMillis();
|
|
|
- log.info("开始oss下载文件:" + command);
|
|
|
- callshell(command);
|
|
|
- log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
+ CreateObjUtil.log.info("开始oss下载文件:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("oss下载文件完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
}
|
|
|
|
|
|
public static void panoCutaway(String fileUrl) throws Exception {
|
|
|
String command = "krpanotools makepano -config=templates/vtour-multires.config " + fileUrl;
|
|
|
Long start = System.currentTimeMillis();
|
|
|
- log.info("全景图切图开始:" + command);
|
|
|
- callshell(command);
|
|
|
- log.info("全景图切图完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
+ CreateObjUtil.log.info("全景图切图开始:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("全景图切图完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
}
|
|
|
|
|
|
public static void objHandle(String fileUrl) throws Exception {
|
|
|
String command = "python3 /opt/ossutil/NewResortForOne.py " + fileUrl;
|
|
|
Long start = System.currentTimeMillis();
|
|
|
- log.info("python处理obj文件开始:" + command);
|
|
|
- callshell(command);
|
|
|
- log.info("python处理obj文件完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
+ CreateObjUtil.log.info("python处理obj文件开始:" + command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("python处理obj文件完成,时间为:" + (System.currentTimeMillis() - start));
|
|
|
|
|
|
}
|
|
|
|
|
@@ -99,35 +100,35 @@ public class CreateObjUtil {
|
|
|
public void convertobjTotxt(String folderName) throws Exception {
|
|
|
//obj
|
|
|
String command = "/home/ubuntu/photoscan-pro/main/mesh/mesh " + folderName;
|
|
|
- callshell(command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
//camera
|
|
|
command = "/home/ubuntu/photoscan-pro/main/read_camera/read_camera " + folderName;
|
|
|
- callshell(command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
|
|
|
String prefix = ConstantFilePath.CREATE_BIG_SCENE_PATH + folderName + File.separator + "data" + File.separator;
|
|
|
String srcpath = prefix + "mesh.txt";
|
|
|
String despath = prefix + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam";
|
|
|
|
|
|
- convertTxtToDam(srcpath, despath);
|
|
|
+ CreateObjUtil.convertTxtToDam(srcpath, despath);
|
|
|
//dam转换成lzma
|
|
|
command = "lzma /home/ubuntu/photo_data/bigscene/" + folderName + "/data/dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam";
|
|
|
- callshell(command);
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
|
|
|
srcpath = prefix + "vision.txt";
|
|
|
despath = prefix + "vision.modeldata";
|
|
|
- convertTxtToVisionmodeldata(srcpath, despath);
|
|
|
+ CreateObjUtil.convertTxtToVisionmodeldata(srcpath, despath);
|
|
|
}
|
|
|
|
|
|
public static void convertDamToLzma(String folderName) throws Exception {
|
|
|
try {
|
|
|
String command = "lzma " + ConstantFilePath.BUILD_MODEL_PATH + folderName + File.separator + ConstantFileName.modelUUID + "_50k.dam";
|
|
|
- log.info("开始转换lzma");
|
|
|
- callshell(command);
|
|
|
- log.info("转换lzma完毕");
|
|
|
+ CreateObjUtil.log.info("开始转换lzma");
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("转换lzma完毕");
|
|
|
} catch (Exception e) {
|
|
|
StringWriter trace = new StringWriter();
|
|
|
e.printStackTrace(new PrintWriter(trace));
|
|
|
- log.error(trace.toString());
|
|
|
+ CreateObjUtil.log.error(trace.toString());
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -135,34 +136,48 @@ public class CreateObjUtil {
|
|
|
public static void convertDamToLzma2(String folderName) throws Exception {
|
|
|
try {
|
|
|
String command = "lzma " + ConstantFilePath.BUILD_MODEL_PATH + folderName + File.separator + ConstantFileName.modelUUID + "_50k2.dam";
|
|
|
- log.info("开始转换lzma");
|
|
|
- callshell(command);
|
|
|
- log.info("转换lzma完毕");
|
|
|
+ CreateObjUtil.log.info("开始转换lzma");
|
|
|
+ CreateObjUtil.callshell(command);
|
|
|
+ CreateObjUtil.log.info("转换lzma完毕");
|
|
|
} catch (Exception e) {
|
|
|
StringWriter trace = new StringWriter();
|
|
|
e.printStackTrace(new PrintWriter(trace));
|
|
|
- log.error(trace.toString());
|
|
|
+ CreateObjUtil.log.error(trace.toString());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static void convertTxtToDam(String srcpath, String despath) throws Exception {
|
|
|
- BigSceneProto.binary_mesh.Builder builder = BigSceneProto.binary_mesh.newBuilder();
|
|
|
- InputStream inputStream = new FileInputStream(srcpath);
|
|
|
- InputStreamReader reader = new InputStreamReader(inputStream, "ASCII");
|
|
|
- TextFormat.merge(reader, builder);
|
|
|
- byte[] buf = builder.build().toByteArray();
|
|
|
|
|
|
- //把序列化后的数据写入本地磁盘
|
|
|
- ByteArrayInputStream stream = new ByteArrayInputStream(buf);
|
|
|
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(despath));//设置输出路径
|
|
|
- BufferedInputStream bis = new BufferedInputStream(stream);
|
|
|
- int b = -1;
|
|
|
- while ((b = bis.read()) != -1) {
|
|
|
- bos.write(b);
|
|
|
+ InputStream inputStream = null;
|
|
|
+ InputStreamReader reader = null;
|
|
|
+ BufferedInputStream bis = null;
|
|
|
+ BufferedOutputStream bos = null;
|
|
|
+ try {
|
|
|
+ BigSceneProto.binary_mesh.Builder builder = BigSceneProto.binary_mesh.newBuilder();
|
|
|
+ inputStream = new FileInputStream(srcpath);
|
|
|
+ reader = new InputStreamReader(inputStream, "ASCII");
|
|
|
+ TextFormat.merge(reader, builder);
|
|
|
+ byte[] buf = builder.build().toByteArray();
|
|
|
+
|
|
|
+ //把序列化后的数据写入本地磁盘
|
|
|
+ ByteArrayInputStream stream = new ByteArrayInputStream(buf);
|
|
|
+ bos = new BufferedOutputStream(new FileOutputStream(despath));
|
|
|
+ bis = new BufferedInputStream(stream);
|
|
|
+ int b = -1;
|
|
|
+ while ((b = bis.read()) != -1) {
|
|
|
+ bos.write(b);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ CreateObjUtil.log.info("convertTxtToDam报错{}", e.getMessage());
|
|
|
+ } finally {
|
|
|
+ IoUtil.close(inputStream);
|
|
|
+ IoUtil.close(reader);
|
|
|
+ IoUtil.close(bis);
|
|
|
+ IoUtil.close(bos);
|
|
|
}
|
|
|
- bis.close();
|
|
|
- bos.close();
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public static void convertTxtToDamChange(String srcpath, String despath) throws Exception {
|
|
@@ -241,15 +256,15 @@ public class CreateObjUtil {
|
|
|
} catch (Exception e) {
|
|
|
StringWriter trace = new StringWriter();
|
|
|
e.printStackTrace(new PrintWriter(trace));
|
|
|
- log.error(trace.toString());
|
|
|
- log.error(srcpath + "|||" + despath + "convert失败");
|
|
|
+ CreateObjUtil.log.error(trace.toString());
|
|
|
+ CreateObjUtil.log.error(srcpath + "|||" + despath + "convert失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void convertTxtToVisionmodeldata(String srcpath, String despath) throws Exception {
|
|
|
try {
|
|
|
Visionmodeldata.NavigationInfo.Builder builder = Visionmodeldata.NavigationInfo.newBuilder();
|
|
|
- String jsonFormat = readTxtFileToJson(srcpath);
|
|
|
+ String jsonFormat = CreateObjUtil.readTxtFileToJson(srcpath);
|
|
|
JsonFormat.merge(jsonFormat, builder);
|
|
|
byte[] buf = builder.build().toByteArray();
|
|
|
|
|
@@ -266,8 +281,8 @@ public class CreateObjUtil {
|
|
|
} catch (Exception e) {
|
|
|
StringWriter trace = new StringWriter();
|
|
|
e.printStackTrace(new PrintWriter(trace));
|
|
|
- log.error(trace.toString());
|
|
|
- log.error(srcpath + "|||" + despath + "convert失败");
|
|
|
+ CreateObjUtil.log.error(trace.toString());
|
|
|
+ CreateObjUtil.log.error(srcpath + "|||" + despath + "convert失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -293,14 +308,14 @@ public class CreateObjUtil {
|
|
|
} catch (Exception e) {
|
|
|
StringWriter trace = new StringWriter();
|
|
|
e.printStackTrace(new PrintWriter(trace));
|
|
|
- log.error(trace.toString());
|
|
|
+ CreateObjUtil.log.error(trace.toString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void convertTxtToVisionmodeldataCommon(String srcpath, String despath) throws Exception {
|
|
|
try {
|
|
|
Common.NavigationInfo.Builder builder = Common.NavigationInfo.newBuilder();
|
|
|
- String jsonFormat = readTxtFileToJson(srcpath);
|
|
|
+ String jsonFormat = CreateObjUtil.readTxtFileToJson(srcpath);
|
|
|
JsonFormat.merge(jsonFormat, builder);
|
|
|
byte[] buf = builder.build().toByteArray();
|
|
|
|
|
@@ -317,13 +332,13 @@ public class CreateObjUtil {
|
|
|
} catch (Exception e) {
|
|
|
StringWriter trace = new StringWriter();
|
|
|
e.printStackTrace(new PrintWriter(trace));
|
|
|
- log.error(trace.toString());
|
|
|
+ CreateObjUtil.log.error(trace.toString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static void callshell(String command) {
|
|
|
try {
|
|
|
- log.warn("开始调用脚本 :" + command);
|
|
|
+ CreateObjUtil.log.warn("开始调用脚本 :" + command);
|
|
|
Process process = Runtime.getRuntime().exec(command);
|
|
|
//process.waitFor();
|
|
|
/*
|
|
@@ -342,11 +357,11 @@ public class CreateObjUtil {
|
|
|
outGobbler.start();
|
|
|
int exitValue = process.waitFor();
|
|
|
if (0 != exitValue) {
|
|
|
- log.error("调用脚本失败 :" + exitValue);
|
|
|
+ CreateObjUtil.log.error("调用脚本失败 :" + exitValue);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log.error("调用脚本失败 :" + e.getMessage());
|
|
|
+ CreateObjUtil.log.error("调用脚本失败 :" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -410,7 +425,7 @@ public class CreateObjUtil {
|
|
|
if (file.isFile() && file.exists()) {
|
|
|
flag = true;
|
|
|
}
|
|
|
- log.info("等待...");
|
|
|
+ CreateObjUtil.log.info("等待...");
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
@@ -435,7 +450,7 @@ public class CreateObjUtil {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log.error("readTxtFileToJson :" + e.getMessage());
|
|
|
+ CreateObjUtil.log.error("readTxtFileToJson :" + e.getMessage());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
@@ -491,7 +506,7 @@ public class CreateObjUtil {
|
|
|
// convertTxtToDamChange("G:\\protobuf\\modeldata.txt", "G:\\protobuf\\" + ConstantFileName.modelUUID+"_50k2.dam");
|
|
|
// convertTxtToVisionmodeldata("F:\\文档\\WeChat Files\\Iove-bing\\FileStorage\\File\\2020-05\\vision.txt", "F:\\文档\\WeChat Files\\Iove-bing\\FileStorage\\File\\2020-05\\vision.modeldata");
|
|
|
|
|
|
- convertDamToTxtModel("G:\\protobuf\\model.nest", "G:\\protobuf\\model.txt");
|
|
|
+ CreateObjUtil.convertDamToTxtModel("G:\\protobuf\\model.nest", "G:\\protobuf\\model.txt");
|
|
|
// ChangeProtobuf.Model.Builder builder= ChangeProtobuf.Model.newBuilder();
|
|
|
// InputStream inputStream = new FileInputStream("G:\\protobuf\\modeldata.txt");
|
|
|
// InputStreamReader reader = new InputStreamReader(inputStream, "ASCII");
|