|
@@ -1,7 +1,9 @@
|
|
|
package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.util.CharsetUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.core.util.ZipUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -15,8 +17,10 @@ import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
import com.fdkankan.model.constants.UploadFilePath;
|
|
|
import com.fdkankan.model.utils.ComputerUtil;
|
|
|
import com.fdkankan.model.utils.CreateObjUtil;
|
|
|
+import com.fdkankan.scene.bean.SceneJsonBean;
|
|
|
import com.fdkankan.scene.entity.*;
|
|
|
import com.fdkankan.scene.service.*;
|
|
|
+import com.fdkankan.scene.vo.SceneEditControlsVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -24,6 +28,7 @@ import org.springframework.stereotype.Service;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -77,12 +82,12 @@ public class ReverseSceneServiceImpl implements IReverseSceneService {
|
|
|
String zipPath = scenePlusExt.getDataSource();
|
|
|
String zipParentDir = FileUtil.getParent(zipPath, 1);
|
|
|
|
|
|
+ //解压
|
|
|
+ ZipUtil.unzip(zipPath, zipParentDir, CharsetUtil.CHARSET_GBK);
|
|
|
+
|
|
|
//生成vision.txt
|
|
|
int shootCount = this.genVisionTxt(num, zipParentDir);
|
|
|
|
|
|
- //解压
|
|
|
- ZipUtil.unzip(zipPath, CharsetUtil.CHARSET_GBK);
|
|
|
-
|
|
|
//计算模型
|
|
|
this.genModel(num, zipParentDir);
|
|
|
|
|
@@ -107,11 +112,43 @@ public class ReverseSceneServiceImpl implements IReverseSceneService {
|
|
|
scenePlusExt.setUpdateTime(new Date());
|
|
|
scenePlusExtService.updateById(scenePlusExt);
|
|
|
|
|
|
+ this.genSceneJson(num);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void genSceneJson(String num){
|
|
|
+ ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
|
|
|
+ SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
|
|
|
+ SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
|
|
|
+
|
|
|
+ //生成sceneJson
|
|
|
+ SceneJsonBean sceneJson = new SceneJsonBean();
|
|
|
+ BeanUtil.copyProperties(sceneEditInfoExt, sceneJson, "started");
|
|
|
+ BeanUtil.copyProperties(sceneEditInfo, sceneJson);
|
|
|
+ sceneJson.setFloorPlanUpload(JSON.parseArray(sceneEditInfo.getFloorPlanUpload()));
|
|
|
+ SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
|
|
|
+ sceneJson.setControls(sceneEditControlsVO);
|
|
|
+ sceneJson.setNum(num);
|
|
|
+ sceneJson.setCreateTime(scenePlus.getCreateTime());
|
|
|
+
|
|
|
+ sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
|
|
|
+ sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
|
|
|
+ sceneJson.setSceneKind(scenePlusExt.getSceneKind());
|
|
|
+ sceneJson.setModelKind(scenePlusExt.getModelKind());
|
|
|
+ if(StrUtil.isNotEmpty(scenePlusExt.getVideos())){
|
|
|
+ sceneJson.setVideos(scenePlusExt.getVideos());
|
|
|
+ }
|
|
|
+
|
|
|
+ //上传sceneJson文件
|
|
|
+ String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", num);
|
|
|
+ fileServiceInterface.uploadFile(JSON.toJSONBytes(sceneJson), sceneJsonPath);
|
|
|
}
|
|
|
|
|
|
private int genVisionTxt(String num, String zipParentDir) throws Exception {
|
|
|
String workJsonPath = zipParentDir + "/work.json";
|
|
|
- JSONObject jsonObject = JSON.parseObject(workJsonPath);
|
|
|
+ JSONObject jsonObject = JSON.parseObject(FileUtil.readUtf8String(workJsonPath));
|
|
|
JSONArray observers = jsonObject.getJSONArray("observers");
|
|
|
JSONObject visionTxtObj = new JSONObject();
|
|
|
List<JSONObject> sweepLocations = new ArrayList<>();
|
|
@@ -130,7 +167,7 @@ public class ReverseSceneServiceImpl implements IReverseSceneService {
|
|
|
pose.put("translation", translation);
|
|
|
JSONArray positions = observerObj.getJSONArray("position");
|
|
|
for(int j = 0; j < positions.size(); j++){
|
|
|
- Float v = (Float) positions.get(i);
|
|
|
+ BigDecimal v = (BigDecimal) positions.get(i);
|
|
|
if(i == 0){
|
|
|
translation.put("x", v);
|
|
|
}
|
|
@@ -146,7 +183,7 @@ public class ReverseSceneServiceImpl implements IReverseSceneService {
|
|
|
sweepLocation.put("puck", puck);
|
|
|
JSONArray standing_positions = observerObj.getJSONArray("standing_position");
|
|
|
for(int j = 0; j < standing_positions.size(); j++){
|
|
|
- Float v = (Float) standing_positions.get(i);
|
|
|
+ BigDecimal v = (BigDecimal) standing_positions.get(i);
|
|
|
if(i == 0){
|
|
|
puck.put("x", v);
|
|
|
}
|
|
@@ -177,13 +214,13 @@ public class ReverseSceneServiceImpl implements IReverseSceneService {
|
|
|
sweepLocation.put("visibles3", observerObj.get("visible_nodes"));
|
|
|
}
|
|
|
|
|
|
- FileUtil.writeUtf8String(JSON.toJSONString(sweepLocations), zipParentDir + "vision.txt");
|
|
|
+ FileUtil.writeUtf8String(JSON.toJSONString(visionTxtObj), zipParentDir + "/vision.txt");
|
|
|
|
|
|
//转换modedata
|
|
|
- CreateObjUtil.convertTxtToVisionmodeldata(zipParentDir + "vision.txt", zipParentDir + "vision.modeldata");
|
|
|
+ CreateObjUtil.convertTxtToVisionmodeldata(zipParentDir + "/vision.txt", zipParentDir + "/vision.modeldata");
|
|
|
|
|
|
- fileServiceInterface.uploadFile(zipParentDir + "vision.txt", String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt");
|
|
|
- fileServiceInterface.uploadFile(zipParentDir + "vision.modeldata", String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.modeldata");
|
|
|
+ fileServiceInterface.uploadFile(zipParentDir + "/vision.txt", String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.txt");
|
|
|
+ fileServiceInterface.uploadFile(zipParentDir + "/vision.modeldata", String.format(UploadFilePath.IMG_VIEW_PATH, num) + "vision.modeldata");
|
|
|
|
|
|
return observers.size();
|
|
|
}
|
|
@@ -297,7 +334,10 @@ public class ReverseSceneServiceImpl implements IReverseSceneService {
|
|
|
//计算模型
|
|
|
FileUtil.copyContent(new File(zipParentDir + "/src_model/material/"), new File(filePath), true);
|
|
|
FileUtil.copyContent(new File(zipParentDir + "/src_model/mtl/"), new File(filePath), true);
|
|
|
- FileUtil.copyContent(new File(zipParentDir + "/src_model/obj/"), new File(filePath), true);
|
|
|
+ List<File> objFiles = FileUtil.loopFiles(new File(zipParentDir + "/src_model/obj/"));
|
|
|
+ for (File objFile : objFiles) {
|
|
|
+ FileUtil.copyContent(objFile, new File(filePath + "mesh.obj"), true);
|
|
|
+ }
|
|
|
this.writeDataJson(path);
|
|
|
CreateObjUtil.build3dModel(path , "1");
|
|
|
this.uploadFileofterBuildDamModel(path, filePath, num);
|
|
@@ -317,7 +357,7 @@ public class ReverseSceneServiceImpl implements IReverseSceneService {
|
|
|
String uploadJsonPath = path + File.separator + "results" +File.separator+"upload.json";
|
|
|
boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, 5, 1000);
|
|
|
if(!exist){
|
|
|
- throw new BusinessException(ErrorCode.FAILURE_CODE_7013);
|
|
|
+ throw new RuntimeException("模型计算失败, path=" + path);
|
|
|
}
|
|
|
String uploadData = FileUtils.readFile(uploadJsonPath);
|
|
|
JSONObject uploadJson = null;
|