rindy 2 月之前
父节点
当前提交
c327049fac

+ 2 - 0
src/main/java/com/fdkankan/scene/config/FdkkLaserConfig.java

@@ -59,6 +59,8 @@ public class FdkkLaserConfig {
 
     public Integer laserPort;
 
+    public String buildCallPath;
+
     public Integer getLaserPort() {
         return laserPort;
     }

+ 6 - 1
src/main/java/com/fdkankan/scene/service/impl/BoxModelServiceImpl.java

@@ -18,6 +18,7 @@ import com.fdkankan.model.constants.ConstantFilePath;
 import com.fdkankan.model.constants.UploadFilePath;
 import com.fdkankan.model.utils.ComputerUtil;
 import com.fdkankan.scene.bean.BoxModelBean;
+import com.fdkankan.scene.config.FdkkLaserConfig;
 import com.fdkankan.scene.constant.ConstantFileLocPath;
 import com.fdkankan.scene.entity.SceneEditInfo;
 import com.fdkankan.scene.entity.ScenePlus;
@@ -27,6 +28,7 @@ import com.fdkankan.scene.service.IBoxModelService;
 import com.fdkankan.scene.service.ISceneEditInfoService;
 import com.fdkankan.scene.service.IScenePlusExtService;
 import com.fdkankan.scene.service.IScenePlusService;
+import com.fdkankan.scene.util.OBJToGLBExtUtil;
 import com.fdkankan.scene.vo.BaseJsonDataParamVO;
 import com.fdkankan.scene.vo.DeleteSidParamVO;
 import com.fdkankan.web.response.ResultData;
@@ -36,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import java.io.File;
 import java.io.IOException;
 import java.nio.file.FileSystemException;
@@ -61,6 +64,8 @@ public class BoxModelServiceImpl implements IBoxModelService {
     private IScenePlusExtService scenePlusExtService;
     @Autowired
     private OssUtil ossUtil;
+    @Resource
+    private FdkkLaserConfig fdkkLaserConfig;
 
     @Override
     public ResultData uploadBoxModel(String num, String sid, MultipartFile file) throws Exception {
@@ -101,7 +106,7 @@ public class BoxModelServiceImpl implements IBoxModelService {
             });
 
             //转glb
-            OBJToGLBUtil.objToGlb(srcPath, glbPath);
+            OBJToGLBExtUtil.objToGlb(fdkkLaserConfig.buildCallPath, srcPath, glbPath);
 
             if(!ComputerUtil.checkComputeCompleted(glbPath, 10, 2000)){
                 throw new BusinessException(ErrorCode.FAILURE_CODE_7013);

+ 2 - 0
src/main/java/com/fdkankan/scene/service/impl/SceneDownloadLogServiceImpl.java

@@ -350,6 +350,8 @@ public class SceneDownloadLogServiceImpl extends ServiceImpl<ISceneDownloadLogMa
         params.put("resultPath", resultPath);
         redisUtil.lRightPush(RedisKey.SCENE_DOWNLOADS_TASK_V4, JSONObject.toJSONString(params));
 
+        this.setBuildSceneOffline();
+
         return ResultData.ok(result);
     }
 

+ 5 - 2
src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -49,6 +49,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
@@ -111,6 +112,8 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
     private ICommonService commonService;
     @Autowired
     private ISceneDrawService sceneDrawService;
+    @Resource
+    private FdkkLaserConfig fdkkLaserConfig;
 //    @Autowired
 //    private ISceneDynamicPanelService sceneDynamicPanelService;
 //    @Autowired
@@ -1269,7 +1272,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
         ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
 
-        CmdBuildUtil.BuildModelCommand(target);
+        CmdBuildUtil.BuildModelCommand(fdkkLaserConfig.buildCallPath, target);
 
         String uploadJsonPath= target + File.separator + "results" +File.separator+"upload.json";
         Thread.sleep(2000);
@@ -2089,7 +2092,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
         }
         //下载data.fdage
         FileUtil.copy(path.concat(File.separator).concat("capture").concat(File.separator).concat("data.fdage"), capturePath.concat(File.separator).concat("data.fdage"), true);
-        CmdBuildUtil.BuildModelCommand(target);
+        CmdBuildUtil.BuildModelCommand(fdkkLaserConfig.buildCallPath, target);
 
         //读取upload文件,获取需要上传的文件
         JSONArray array = ComputerUtil.getUploadArray(resultPath + "/upload.json", this.maxCheckTimes, this.waitTime);

+ 3 - 3
src/main/java/com/fdkankan/scene/service/impl/SceneProServiceImpl.java

@@ -214,7 +214,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             Map<String, String> uploadMap = new HashMap<>();
 
             //切图
-            String fragmentCmd = "vips dzsave --tile-size "  + tileSize + " " + origFilePath + " " +  workPath;
+            String fragmentCmd = fdkkLaserConfig.buildCallPath + File.separator + "vips" + File.separator + "bin" + File.separator + "vips dzsave --tile-size "  + tileSize + " " + origFilePath + " " +  workPath;
             CmdUtils.callLine(fragmentCmd);
             if(!ComputerUtil.checkComputeCompleted(dziPath, 5, 200)){
                 throw new BusinessException(ErrorCode.FAILURE_CODE_5052);
@@ -927,7 +927,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             sceneAsynOperLogService.save(sceneAsynOperLog);
             try {
                 //调用算法,不同的类型调用不同的算法
-                CmdBuildUtil.BuildModelCommand(path);
+                CmdBuildUtil.BuildModelCommand(fdkkLaserConfig.buildCallPath, path);
 
                 //算法计算完后,生成压缩文件,上传到oss
                 uploadFileofterBuildDamModel(path, filePath, num, bucket);
@@ -1059,7 +1059,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             try {
                 //调用算法
                 log.info("上传3dtiles模型开始, num:{}, targetPath:{}", num, path);
-                CmdBuildUtil.Obj2Tiles(path);
+                CmdBuildUtil.Obj2Tiles(fdkkLaserConfig.buildCallPath, path);
                 log.info("上传3dtiles模型结束, num:{}, targetPath:{}", num, path);
 
                 //检测计算结果

+ 4 - 4
src/main/java/com/fdkankan/scene/util/CmdBuildUtil.java

@@ -177,7 +177,7 @@ public class CmdBuildUtil {
 
     }
 
-    public static void BuildModelCommand(String inPath) {
+    public static void BuildModelCommand(String buildCallPath, String inPath) {
         String buildModelCommandCmd = "";
         if (CmdBuildUtil.OS.isLinux()) {
             buildModelCommandCmd = CmdConstant.BUILD_MODEL_COMMAND
@@ -185,7 +185,7 @@ public class CmdBuildUtil {
             CmdUtils.callLineSh(buildModelCommandCmd);
 
         } else {
-            buildModelCommandCmd = CmdConstant.BUILD_MODEL_COMMAND_WIN
+            buildModelCommandCmd = buildCallPath + File.separator + CmdConstant.BUILD_MODEL_COMMAND_WIN
                     .replace("@inPath", inPath);
             CmdUtils.callLineWin(buildModelCommandCmd);
 
@@ -259,14 +259,14 @@ public class CmdBuildUtil {
         }
 
     }
-    public static void Obj2Tiles(String inPath) {
+    public static void Obj2Tiles(String buildCallPath, String inPath) {
         String checkLaserCmd = "";
         if (CmdBuildUtil.OS.isLinux()) {
             checkLaserCmd = CmdConstant.OBJ2_TILES
                     .replace("@inPath", inPath);
             CmdUtils.callLineSh(checkLaserCmd);
         } else {
-            checkLaserCmd = CmdConstant.OBJ2_TILES_WIN
+            checkLaserCmd = buildCallPath + File.separator + CmdConstant.OBJ2_TILES_WIN
                     .replace("@inPath", inPath);
             CmdUtils.callLineWin(checkLaserCmd);
 

+ 138 - 0
src/main/java/com/fdkankan/scene/util/OBJToGLBExtUtil.java

@@ -0,0 +1,138 @@
+package com.fdkankan.scene.util;
+
+import cn.hutool.core.img.ImgUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.io.file.FileReader;
+import cn.hutool.core.util.RuntimeUtil;
+import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.common.util.OBJToGLBUtil;
+import lombok.extern.slf4j.Slf4j;
+
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
+
+@Slf4j
+public class OBJToGLBExtUtil extends OBJToGLBUtil {
+
+    public static void objToGlb(String buildCallPath, String objPath, String glbPath) {
+        checkObj(objPath);
+        objPath = getObj(objPath);
+        String command = buildCallPath + File.separator + "obj2gltf.exe -i " + objPath + " -o " + glbPath;
+        log.info("开始执行obj转换gbl命令-{}", command);
+        Process exec = RuntimeUtil.exec(new String[]{command});
+        log.info("结束执行obj转换gbl命令-{}", command);
+    }
+
+    static String getObj(String objPath) {
+        List<File> files = FileUtil.loopFiles(objPath);
+        if (objPath.toLowerCase(Locale.ROOT).contains(".obj")) {
+            return objPath;
+        } else {
+            for(File file2 : files) {
+                if (!file2.isDirectory() && FileUtil.extName(file2.getName()).toLowerCase(Locale.ROOT).equals("obj")) {
+                    return file2.getAbsolutePath();
+                }
+            }
+
+            return "";
+        }
+    }
+
+    private static boolean checkObj(String objPath) {
+        if (objPath.contains(".obg")) {
+            objPath = FileUtil.file(objPath).getParent();
+        }
+
+        File file1 = new File(objPath);
+        File[] files = file1.listFiles();
+        if (files != null && files.length > 0) {
+            File mtlFile = null;
+            File objFile = null;
+
+            for(File file2 : files) {
+                if (file2.getName().endsWith(".obj")) {
+                    objFile = file2;
+                }
+
+                if (file2.getName().endsWith(".mtl")) {
+                    mtlFile = file2;
+                }
+
+                if (FileUtil.getType(file2).equals("jpg") || FileUtil.getType(file2).equals("png")) {
+                    BufferedImage read = ImgUtil.read(file2);
+                    int widthImg = read.getWidth();
+                    int heightImg = read.getHeight();
+                    if (widthImg > 2048 && heightImg > 2048) {
+                        log.info("尺寸大2k,执行压缩");
+                        ImgUtil.scale(file2, file2, 2048, 2048, (Color)null);
+                    }
+                }
+            }
+
+            if (mtlFile != null && objFile != null) {
+                return checkMtl(file1, mtlFile);
+            } else {
+                throw new BusinessException(ErrorCode.FAILURE_CODE_5059);
+            }
+        } else {
+            throw new BusinessException(ErrorCode.FAILURE_CODE_7014);
+        }
+    }
+
+    private static boolean checkMtl(File allFile, File file) {
+        if (!file.getName().endsWith(".mtl")) {
+            return false;
+        } else {
+            LinkedHashSet<String> imgName = new LinkedHashSet();
+            if (allFile != null && allFile.length() > 0L) {
+                File[] files = allFile.listFiles();
+                if (files != null && files.length > 0) {
+                    for(File listFile : files) {
+                        String modelName = listFile.getName();
+                        imgName.add(modelName);
+                    }
+
+                    for(String mtlName : readMtlFile(file.getPath())) {
+                        if (!imgName.contains(mtlName)) {
+                            throw new BusinessException(ErrorCode.FAILURE_CODE_5065);
+                        }
+                    }
+
+                    return true;
+                } else {
+                    return false;
+                }
+            } else {
+                return false;
+            }
+        }
+    }
+
+    private static LinkedHashSet<String> readMtlFile(String mtlPath) {
+        LinkedHashSet<String> imgName = new LinkedHashSet();
+        FileReader fileReader = new FileReader(mtlPath);
+
+        try {
+            for(String line : fileReader.readLines()) {
+                String[] tempsa = line.split("[ ]+");
+                if (tempsa[0].trim().equals("map_Ka")) {
+                    imgName.add(tempsa[1]);
+                }
+
+                if (tempsa[0].trim().equals("map_Kd")) {
+                    imgName.add(tempsa[1]);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return imgName;
+    }
+
+}

+ 4 - 0
src/main/resources/application-standAloneProd.yml

@@ -11,6 +11,8 @@ fdkk:
   isBucket: false
   #是否使用软连接
   isLink: false
+  #算法软件目录
+  buildCallPath: ${BUILD_CALL_PATH}
 aliyun:
   oss:
     env: dev
@@ -120,3 +122,5 @@ url:
 inner:
   customToken:
 
+
+