|
@@ -1,168 +1,161 @@
|
|
|
-package com.fdkankan.project.tieta.utils;
|
|
|
-
|
|
|
-import cn.hutool.core.io.FileUtil;
|
|
|
-import com.alibaba.fastjson.JSON;
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.util.Objects;
|
|
|
-
|
|
|
-public class ConvertUtil {
|
|
|
-
|
|
|
- public static void main(String[] args) throws Exception {
|
|
|
-
|
|
|
- String srcPath = args[0];
|
|
|
- System.out.println(srcPath);
|
|
|
- String targetPath = args[1];
|
|
|
- System.out.println(targetPath);
|
|
|
-
|
|
|
- convert(srcPath, targetPath);
|
|
|
-// scanner.close();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param sourcePath 原始资源目录
|
|
|
- * @param targetPath 目标资源目录
|
|
|
- * @return boolean true-转换成功 false-转换失败
|
|
|
- */
|
|
|
- public static void convert(String sourcePath, String targetPath) throws Exception {
|
|
|
-
|
|
|
- String obj2TxtPath = null;
|
|
|
-
|
|
|
- try {
|
|
|
- if(!sourcePath.endsWith(File.separator)){
|
|
|
- sourcePath = sourcePath + File.separator;
|
|
|
- }
|
|
|
- if(!targetPath.endsWith(File.separator)){
|
|
|
- targetPath = targetPath + File.separator;
|
|
|
- }
|
|
|
- String targetDataPath = targetPath + "data";
|
|
|
- FileUtil.mkdir(new File(targetDataPath));
|
|
|
- String targetImagePath = targetPath + "images";
|
|
|
- FileUtil.mkdir(new File(targetImagePath));
|
|
|
-
|
|
|
- obj2TxtPath = sourcePath.substring(0, sourcePath.length() - 1) + "_obj2txt";
|
|
|
- FileUtil.mkdir(obj2TxtPath);
|
|
|
- //调用算法生成modeldata.txt
|
|
|
- String extrasPath = obj2TxtPath + File.separator + "extras";
|
|
|
- FileUtil.mkdir(extrasPath);
|
|
|
- FileUtil.copyContent(new File(sourcePath + "data" + File.separator + "mesh"), new File(extrasPath), true);
|
|
|
-
|
|
|
- //写data.json
|
|
|
- writeDataJson(obj2TxtPath);
|
|
|
-
|
|
|
- //调用算法建模
|
|
|
- build3dModel(obj2TxtPath);
|
|
|
-
|
|
|
- //校验算法是否正常结束
|
|
|
- String uploadJsonPath = obj2TxtPath + File.separator + "results" +File.separator+"upload.json";
|
|
|
- boolean success = checkComputeCompleted(uploadJsonPath, 5, 300);
|
|
|
- if(!success){
|
|
|
- throw new RuntimeException("计算失败,obj2TxtPath:" + obj2TxtPath);
|
|
|
- }
|
|
|
-
|
|
|
- //压缩成dam
|
|
|
- String damPath = targetImagePath + File.separator + "tieta.dam";
|
|
|
- CreateObjUtil.convertTxtToDam( obj2TxtPath + File.separator + "results" +File.separator+"modeldata.txt", damPath);
|
|
|
-
|
|
|
- //复制贴图
|
|
|
- String uploadData = FileUtil.readUtf8String(uploadJsonPath);
|
|
|
- JSONObject uploadJson = null;
|
|
|
- JSONArray array = null;
|
|
|
- if(uploadData!=null) {
|
|
|
- uploadJson = JSONObject.parseObject(uploadData);
|
|
|
- array = uploadJson.getJSONArray("upload");
|
|
|
- }
|
|
|
- JSONObject fileJson = null;
|
|
|
- String fileName = "";
|
|
|
- for(int i = 0, len = array.size(); i < len; i++) {
|
|
|
- fileJson = array.getJSONObject(i);
|
|
|
- fileName = fileJson.getString("file");
|
|
|
- //文件不存在抛出异常
|
|
|
- if (!new File(obj2TxtPath + File.separator + "results" + File.separator + fileName).exists()) {
|
|
|
- throw new Exception(obj2TxtPath + File.separator + "results" + File.separator + fileName + "文件不存在");
|
|
|
- }
|
|
|
-
|
|
|
- //tex文件夹
|
|
|
- if (fileJson.getIntValue("clazz") == 15) {
|
|
|
- FileUtil.copy(obj2TxtPath + File.separator + "results" + File.separator + fileName,
|
|
|
- targetImagePath + File.separator + "tieta_texture/" + fileName.replace("tex/", ""),true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //复制文件
|
|
|
- FileUtil.copyContent(new File(sourcePath + "data"), new File(targetDataPath), true);
|
|
|
- if(FileUtil.exist(targetDataPath + "/floorplan.json")){
|
|
|
- String floorplanJson = FileUtil.readUtf8String(targetDataPath + "/floorplan.json");
|
|
|
- JSONObject jsonObject = JSON.parseObject(floorplanJson);
|
|
|
- Integer currentId = jsonObject.getInteger("currentId");
|
|
|
- if(Objects.nonNull(currentId) && currentId == 0){
|
|
|
- FileUtil.del(targetDataPath + "/floorplan.json");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- String finalSourcePath = sourcePath;
|
|
|
- if(FileUtil.exist(finalSourcePath + "images/4k/")){
|
|
|
- FileUtil.listFileNames(sourcePath + "images/4k/").stream().forEach(v->{
|
|
|
- FileUtil.copy(finalSourcePath + "images/4k/" + v, targetImagePath + "/pan/high/" + v.replaceAll("-", ""), true);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if(FileUtil.exist(finalSourcePath + "images/512/")){
|
|
|
- FileUtil.listFileNames(finalSourcePath + "images/512/").stream().forEach(v->{
|
|
|
- FileUtil.copy(finalSourcePath + "images/512/" + v, targetImagePath + "/pan/low/" + v.replaceAll("-", ""), true);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- if(FileUtil.exist(finalSourcePath + "images/8k/")) {
|
|
|
- FileUtil.listFileNames(finalSourcePath + "images/8k/").stream().forEach(v -> {
|
|
|
- FileUtil.copy(finalSourcePath + "images/8k/" + v, targetImagePath + "/pan/8k/" + v.replaceAll("-", ""), true);
|
|
|
- });
|
|
|
-
|
|
|
- }
|
|
|
- FileUtil.copy(sourcePath + "images/vision.txt", targetImagePath + "/vision.txt", true);
|
|
|
-
|
|
|
- //生成vison.modeldata
|
|
|
- CreateObjUtil.convertTxtToVisionmodeldata(targetImagePath + "/vision.txt", targetImagePath + "/vision.modeldata");
|
|
|
- }finally {
|
|
|
-// FileUtil.del(obj2TxtPath);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static void writeDataJson(String path){
|
|
|
- JSONObject dataJson = new JSONObject();
|
|
|
- dataJson.put("obj2txt", true);
|
|
|
- dataJson.put("split_type", "SPLIT_V6");
|
|
|
- dataJson.put("data_describe", "double spherical");
|
|
|
- dataJson.put("skybox_type", "SKYBOX_V5");
|
|
|
- FileUtil.writeUtf8String(dataJson.toString(), path + File.separator + "data.json");
|
|
|
- }
|
|
|
-
|
|
|
- public static void build3dModel(String folderName) throws Exception {
|
|
|
- System.out.println("开始建模");
|
|
|
- String command = "sudo bash /home/ubuntu/bin/Launcher.sh " + folderName;
|
|
|
- CmdUtils.callLineSh(command);
|
|
|
- System.out.println("计算完毕:" + command);
|
|
|
- }
|
|
|
-
|
|
|
- public static boolean checkComputeCompleted(String uploadJsonPath, int maxCheckTimes, long waitTime) throws Exception {
|
|
|
- int checkTimes = 1;
|
|
|
- boolean exist = false;
|
|
|
-
|
|
|
- do {
|
|
|
- if ((new File(uploadJsonPath)).exists()) {
|
|
|
- exist = true;
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- Thread.sleep(waitTime);
|
|
|
- ++checkTimes;
|
|
|
- } while(checkTimes <= maxCheckTimes);
|
|
|
-
|
|
|
- return exist;
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+//package com.fdkankan.project.tieta.utils;
|
|
|
+//
|
|
|
+//import cn.hutool.core.io.FileUtil;
|
|
|
+//import com.alibaba.fastjson.JSON;
|
|
|
+//import com.alibaba.fastjson.JSONArray;
|
|
|
+//import com.alibaba.fastjson.JSONObject;
|
|
|
+//
|
|
|
+//import java.io.File;
|
|
|
+//import java.util.Objects;
|
|
|
+//
|
|
|
+//public class ConvertUtil {
|
|
|
+//
|
|
|
+// private static String result_dir = "results";
|
|
|
+//
|
|
|
+// private static String floorplanJson_Name = "floorplan.json";
|
|
|
+//
|
|
|
+// /**
|
|
|
+// *
|
|
|
+// * @param sourcePath 原始资源目录
|
|
|
+// * @param targetPath 目标资源目录
|
|
|
+// * @return boolean true-转换成功 false-转换失败
|
|
|
+// */
|
|
|
+// public static void convert(String sourcePath, String targetPath) throws Exception {
|
|
|
+//
|
|
|
+// String obj2TxtPath = null;
|
|
|
+//
|
|
|
+// try {
|
|
|
+// if(!sourcePath.endsWith(File.separator)){
|
|
|
+// sourcePath = sourcePath + File.separator;
|
|
|
+// }
|
|
|
+// if(!targetPath.endsWith(File.separator)){
|
|
|
+// targetPath = targetPath + File.separator;
|
|
|
+// }
|
|
|
+// String targetDataPath = targetPath + "data";
|
|
|
+// FileUtil.mkdir(new File(targetDataPath));
|
|
|
+// String targetImagePath = targetPath + "images";
|
|
|
+// FileUtil.mkdir(new File(targetImagePath));
|
|
|
+//
|
|
|
+// obj2TxtPath = sourcePath.substring(0, sourcePath.length() - 1) + "_obj2txt";
|
|
|
+// FileUtil.mkdir(obj2TxtPath);
|
|
|
+// //调用算法生成modeldata.txt
|
|
|
+// String extrasPath = obj2TxtPath + File.separator + "extras";
|
|
|
+// FileUtil.mkdir(extrasPath);
|
|
|
+// FileUtil.copyContent(new File(sourcePath + "data" + File.separator + "mesh"), new File(extrasPath), true);
|
|
|
+//
|
|
|
+// //写data.json
|
|
|
+// writeDataJson(obj2TxtPath);
|
|
|
+//
|
|
|
+// //调用算法建模
|
|
|
+// build3dModel(obj2TxtPath);
|
|
|
+//
|
|
|
+// //校验算法是否正常结束
|
|
|
+// String uploadJsonPath = obj2TxtPath + File.separator + result_dir +File.separator+"upload.json";
|
|
|
+// boolean success = checkComputeCompleted(uploadJsonPath, 5, 300);
|
|
|
+// if(!success){
|
|
|
+// throw new RuntimeException("计算失败,obj2TxtPath:" + obj2TxtPath);
|
|
|
+// }
|
|
|
+//
|
|
|
+// //压缩成dam
|
|
|
+// String damPath = targetImagePath + File.separator + "tieta.dam";
|
|
|
+// CreateObjUtil.convertTxtToDam( obj2TxtPath + File.separator + result_dir +File.separator+"modeldata.txt", damPath);
|
|
|
+//
|
|
|
+// //复制贴图
|
|
|
+// String uploadData = FileUtil.readUtf8String(uploadJsonPath);
|
|
|
+// JSONObject uploadJson = null;
|
|
|
+// JSONArray array = null;
|
|
|
+// if(uploadData!=null) {
|
|
|
+// uploadJson = JSONObject.parseObject(uploadData);
|
|
|
+// array = uploadJson.getJSONArray("upload");
|
|
|
+// }
|
|
|
+// JSONObject fileJson = null;
|
|
|
+// String fileName = "";
|
|
|
+// for(int i = 0, len = array.size(); i < len; i++) {
|
|
|
+// fileJson = array.getJSONObject(i);
|
|
|
+// fileName = fileJson.getString("file");
|
|
|
+// //文件不存在抛出异常
|
|
|
+// if (!new File(obj2TxtPath + File.separator + result_dir + File.separator + fileName).exists()) {
|
|
|
+// throw new Exception(obj2TxtPath + File.separator + result_dir + File.separator + fileName + "文件不存在");
|
|
|
+// }
|
|
|
+//
|
|
|
+// //tex文件夹
|
|
|
+// if (fileJson.getIntValue("clazz") == 15) {
|
|
|
+// FileUtil.copy(obj2TxtPath + File.separator + result_dir + File.separator + fileName,
|
|
|
+// targetImagePath + File.separator + "tieta_texture/" + fileName.replace("tex/", ""),true);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// //复制文件
|
|
|
+// FileUtil.copyContent(new File(sourcePath + "data"), new File(targetDataPath), true);
|
|
|
+// if(FileUtil.exist(targetDataPath + "/" + floorplanJson_Name)){
|
|
|
+// String floorplanJson = FileUtil.readUtf8String(targetDataPath + "/" + floorplanJson_Name);
|
|
|
+// JSONObject jsonObject = JSON.parseObject(floorplanJson);
|
|
|
+// Integer currentId = jsonObject.getInteger("currentId");
|
|
|
+// if(Objects.nonNull(currentId) && currentId == 0){
|
|
|
+// FileUtil.del(targetDataPath + "/" + floorplanJson_Name);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// String finalSourcePath = sourcePath;
|
|
|
+// if(FileUtil.exist(finalSourcePath + "images/4k/")){
|
|
|
+// FileUtil.listFileNames(sourcePath + "images/4k/").stream().forEach(v->{
|
|
|
+// FileUtil.copy(finalSourcePath + "images/4k/" + v, targetImagePath + "/pan/high/" + v.replaceAll("-", ""), true);
|
|
|
+// });
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(FileUtil.exist(finalSourcePath + "images/512/")){
|
|
|
+// FileUtil.listFileNames(finalSourcePath + "images/512/").stream().forEach(v->{
|
|
|
+// FileUtil.copy(finalSourcePath + "images/512/" + v, targetImagePath + "/pan/low/" + v.replaceAll("-", ""), true);
|
|
|
+// });
|
|
|
+// }
|
|
|
+//
|
|
|
+// if(FileUtil.exist(finalSourcePath + "images/8k/")) {
|
|
|
+// FileUtil.listFileNames(finalSourcePath + "images/8k/").stream().forEach(v -> {
|
|
|
+// FileUtil.copy(finalSourcePath + "images/8k/" + v, targetImagePath + "/pan/8k/" + v.replaceAll("-", ""), true);
|
|
|
+// });
|
|
|
+//
|
|
|
+// }
|
|
|
+// FileUtil.copy(sourcePath + "images/vision.txt", targetImagePath + "/vision.txt", true);
|
|
|
+//
|
|
|
+// //生成vison.modeldata
|
|
|
+// CreateObjUtil.convertTxtToVisionmodeldata(targetImagePath + "/vision.txt", targetImagePath + "/vision.modeldata");
|
|
|
+// }finally {
|
|
|
+//// FileUtil.del(obj2TxtPath);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static void writeDataJson(String path){
|
|
|
+// JSONObject dataJson = new JSONObject();
|
|
|
+// dataJson.put("obj2txt", true);
|
|
|
+// dataJson.put("split_type", "SPLIT_V6");
|
|
|
+// dataJson.put("data_describe", "double spherical");
|
|
|
+// dataJson.put("skybox_type", "SKYBOX_V5");
|
|
|
+// FileUtil.writeUtf8String(dataJson.toString(), path + File.separator + "data.json");
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static void build3dModel(String folderName) throws Exception {
|
|
|
+// System.out.println("开始建模");
|
|
|
+// String command = "sudo bash /home/ubuntu/bin/Launcher.sh " + folderName;
|
|
|
+// CmdUtils.callLineSh(command);
|
|
|
+// System.out.println("计算完毕:" + command);
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static boolean checkComputeCompleted(String uploadJsonPath, int maxCheckTimes, long waitTime) throws Exception {
|
|
|
+// int checkTimes = 1;
|
|
|
+// boolean exist = false;
|
|
|
+//
|
|
|
+// do {
|
|
|
+// if ((new File(uploadJsonPath)).exists()) {
|
|
|
+// exist = true;
|
|
|
+// break;
|
|
|
+// }
|
|
|
+//
|
|
|
+// Thread.sleep(waitTime);
|
|
|
+// ++checkTimes;
|
|
|
+// } while(checkTimes <= maxCheckTimes);
|
|
|
+//
|
|
|
+// return exist;
|
|
|
+// }
|
|
|
+//
|
|
|
+//}
|