|
@@ -1,11 +1,33 @@
|
|
|
package com.fdkankan.openApi.service.www.impl;
|
|
|
|
|
|
-import com.fdkankan.openApi.entity.www.ScenePlus;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.fdkankan.common.constant.*;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+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.openApi.entity.www.*;
|
|
|
import com.fdkankan.openApi.mapper.www.IScenePlusMapper;
|
|
|
-import com.fdkankan.openApi.service.www.IScenePlusService;
|
|
|
+import com.fdkankan.openApi.service.www.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.openApi.vo.www.CreateFicTitiousSceneParamVO;
|
|
|
+import com.fdkankan.web.response.ResultData;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
/**
|
|
|
* <p>
|
|
|
* 场景主表 服务实现类
|
|
@@ -17,4 +39,189 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
|
|
|
|
|
|
+ @Value("${main.url}")
|
|
|
+ private String mainUrl;
|
|
|
+ @Value("${scene.pro.new.url}")
|
|
|
+ private String sceneUrl;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoExtService sceneEditInfoExtService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditControlsService sceneEditControlsService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ScenePlus getByNum(String num) {
|
|
|
+ return this.getOne(new LambdaQueryWrapper<ScenePlus>().eq(ScenePlus::getNum, num));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData createVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
|
|
|
+
|
|
|
+ this.buildScene4CreateVirtualScene(param);
|
|
|
+
|
|
|
+ String website = this.updateScene4CreateVirtualScene(param);
|
|
|
+
|
|
|
+ return ResultData.ok(website);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void buildScene4CreateVirtualScene(CreateFicTitiousSceneParamVO param) throws Exception {
|
|
|
+
|
|
|
+ String num = param.getNum();
|
|
|
+ String objName = param.getObjName();
|
|
|
+ String mtlName = param.getMtlName();
|
|
|
+
|
|
|
+ String localImagePath = String.format(ConstantFilePath.SCENE_IMAGES_PATH_V4, num);
|
|
|
+ String ossImagePath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
|
|
|
+
|
|
|
+ String ossObjPath = ossImagePath + objName;
|
|
|
+ if(!fYunFileService.fileExist(ossObjPath)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_4001, objName);
|
|
|
+ }
|
|
|
+
|
|
|
+ String ossMtlPath = ossImagePath + mtlName;
|
|
|
+ if(!fYunFileService.fileExist(ossMtlPath)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_4001, mtlName);
|
|
|
+ }
|
|
|
+
|
|
|
+ String ossTexturePath = ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/";
|
|
|
+// if(CollUtil.isEmpty(fYunFileService.listRemoteFiles(ossTexturePath))){
|
|
|
+// throw new BusinessException(ErrorCode.FAILURE_CODE_4001, "贴图");
|
|
|
+// }
|
|
|
+
|
|
|
+ String ossVisionTxtPath = ossImagePath + "vision.txt";
|
|
|
+ if(!fYunFileService.fileExist(ossVisionTxtPath)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_4001, "vision.txt");
|
|
|
+ }
|
|
|
+
|
|
|
+ FileUtil.del(localImagePath + "/result/");
|
|
|
+ FileUtil.del(localImagePath + "extras/");
|
|
|
+ fYunFileService.downloadFile(ossObjPath, localImagePath + "extras/" + "mesh.obj");
|
|
|
+ fYunFileService.downloadFile(ossMtlPath, localImagePath + "extras/" + mtlName);
|
|
|
+ fYunFileService.downloadFileByCommand(localImagePath + "extras/", ossTexturePath);
|
|
|
+ fYunFileService.downloadFile(ossVisionTxtPath, localImagePath + "vision.txt");
|
|
|
+
|
|
|
+ //创建data.json
|
|
|
+ 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.toJSONString(), localImagePath + "data.json");
|
|
|
+
|
|
|
+ //调用objToTxt算法
|
|
|
+ CreateObjUtil.build3dModel(localImagePath, "");
|
|
|
+ Thread.sleep(2000);
|
|
|
+
|
|
|
+ String uploadJsonPath = localImagePath + "results/upload.json";
|
|
|
+ boolean exist = ComputerUtil.checkComputeCompleted(uploadJsonPath, 3, 3000);
|
|
|
+ if(!exist){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5042);
|
|
|
+ }
|
|
|
+ String uploadData = FileUtils.readFile(uploadJsonPath);
|
|
|
+ JSONObject uploadJson = null;
|
|
|
+ JSONArray array = null;
|
|
|
+ if(uploadData!=null) {
|
|
|
+ uploadJson = JSONObject.parseObject(uploadData);
|
|
|
+ array = uploadJson.getJSONArray("upload");
|
|
|
+ }
|
|
|
+ if(array == null){
|
|
|
+ log.error("upload.json数据出错");
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5012);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String,String> map = new HashMap<String,String>();
|
|
|
+ JSONObject fileJson = null;
|
|
|
+ String fileName = "";
|
|
|
+ for(int i = 0, len = array.size(); i < len; i++) {
|
|
|
+ fileJson = array.getJSONObject(i);
|
|
|
+ fileName = fileJson.getString("file");
|
|
|
+ String filePath = localImagePath + "results/" + fileName;
|
|
|
+ //文件不存在抛出异常
|
|
|
+ if(!FileUtil.exist(filePath)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_4002, filePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ //tex文件夹
|
|
|
+ if (fileJson.getIntValue("clazz") == 15) {
|
|
|
+ map.put(filePath, ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k_texture_jpg_high1/" + fileName.replace("tex/", ""));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CreateObjUtil.convertTxtToDam(localImagePath + "results/" + "modeldata.txt", localImagePath + "results/" + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
|
|
|
+// CreateObjUtil.convertDamToLzma(imagesBuffer.toString() + File.separator + "results" +File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
|
|
|
+// CreateObjUtil.convertTxtToDam(imagesBuffer.toString() + File.separator + "results" +File.separator+"modeldata.txt", imagesBuffer.toString() + File.separator + "results" + File.separator+ "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
|
|
|
+// map.put(imagesBuffer.toString() + File.separator + "results" +File.separator+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma", "images/images"+param.getNum()+"/"+"dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam.lzma");
|
|
|
+ map.put(localImagePath + "results/" + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam", ossImagePath + "dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
|
|
|
+
|
|
|
+ FileUtils.deleteFile(localImagePath + "vision.modeldata");
|
|
|
+ CreateObjUtil.convertTxtToVisionmodeldata(localImagePath + "vision.txt", localImagePath + "vision.modeldata");
|
|
|
+ map.put(localImagePath + "vision.modeldata", ossImagePath + "vision.modeldata");
|
|
|
+
|
|
|
+ fYunFileService.uploadMulFiles(map);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private String updateScene4CreateVirtualScene(CreateFicTitiousSceneParamVO param){
|
|
|
+
|
|
|
+ ScenePlus scenePlus = this.getByNum(param.getNum());
|
|
|
+ ScenePlusExt scenePlusExt = null;
|
|
|
+ SceneEditInfo sceneEditInfo = null;
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = null;
|
|
|
+ SceneEditControls sceneEditControls = null;
|
|
|
+ if(Objects.nonNull(scenePlus)){
|
|
|
+ scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
|
|
|
+ sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditControls = sceneEditControlsService.getByEditInfoId(sceneEditInfo.getId());
|
|
|
+ }else {
|
|
|
+ scenePlus = new ScenePlus();
|
|
|
+ scenePlusExt = new ScenePlusExt();
|
|
|
+ sceneEditInfo = new SceneEditInfo();
|
|
|
+ sceneEditInfoExt = new SceneEditInfoExt();
|
|
|
+ sceneEditControls = new SceneEditControls();
|
|
|
+ }
|
|
|
+
|
|
|
+ scenePlus.setNum(param.getNum());
|
|
|
+ scenePlus.setUserId(param.getUserId());
|
|
|
+ scenePlus.setTitle("四维看看");
|
|
|
+ scenePlus.setDescription("<p>四维看看 让空间讲故事</p>");
|
|
|
+ scenePlus.setSceneStatus(SceneStatus.SUCCESS.code());
|
|
|
+ scenePlus.setPayStatus(PayStatus.PAY.code());
|
|
|
+ this.saveOrUpdate(scenePlus);
|
|
|
+
|
|
|
+ scenePlusExt.setPlusId(scenePlus.getId());
|
|
|
+ scenePlusExt.setWebSite(mainUrl + "/" + sceneUrl + param.getNum());
|
|
|
+ scenePlusExt.setBuildType("V3");
|
|
|
+ scenePlusExt.setSceneResolution(param.getSceneResolution());
|
|
|
+ scenePlusExt.setSceneFrom(param.getSceneFrom());
|
|
|
+ scenePlusExt.setSceneKind(param.getSceneKind());
|
|
|
+ scenePlusExt.setModelKind(ModelKind.DAM.code());
|
|
|
+ scenePlusExtService.saveOrUpdate(scenePlusExt);
|
|
|
+
|
|
|
+ sceneEditInfo.setScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfo.setVersion(Objects.isNull(sceneEditInfo.getVersion()) ? 0 : sceneEditInfo.getVersion() + 1);
|
|
|
+ sceneEditInfo.setTitle(scenePlus.getTitle());
|
|
|
+ sceneEditInfo.setDescription(scenePlus.getDescription());
|
|
|
+ sceneEditInfoService.saveOrUpdate(sceneEditInfo);
|
|
|
+
|
|
|
+ sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditInfoExt.setScenePlusId(scenePlus.getId());
|
|
|
+ sceneEditInfoExtService.saveOrUpdate(sceneEditInfoExt);
|
|
|
+
|
|
|
+ sceneEditControls.setEditInfoId(sceneEditInfo.getId());
|
|
|
+ sceneEditControlsService.saveOrUpdate(sceneEditControls);
|
|
|
+
|
|
|
+ return scenePlusExt.getWebSite();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ FileUtil.del("D:\\test4\\");
|
|
|
+ }
|
|
|
}
|