Browse Source

场景obj模型转换为b3dm

lyhzzz 1 year ago
parent
commit
24fe2f6136

+ 10 - 33
src/main/java/com/fdkankan/fusion/service/impl/CaseNumServiceImpl.java

@@ -58,6 +58,8 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
     ICaseTagService caseTagService;
     @Autowired
     ICaseTagPointService caseTagPointService;
+    @Autowired
+    ThreadService threadService;
 
     @Override
     public List<CaseNumEntity> getByCaseId(Integer caseId) {
@@ -96,12 +98,12 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
                 model.setModelDateType("obj");
                 model.setType(param.getType());
                 model.setModelType("pointcloud");    //深时点云类型
-                if(param.getType() == 0 || param.getType() == 1 || param.getType() == 4 || param.getType() == 6){           //看看,看见
-                    model.setModelObjUrl(String.format(FilePath.OBJ_LOCAL_PATH,environment ,num) +"/mesh.obj");
-                    model.setModelGlbUrl(getGlbUrl(param.getType(),num,model));
-                    model.setModelType("b3dm");
-                    model.setModelDateType("b3dm");
-                }
+//                if(param.getType() == 0 || param.getType() == 1 || param.getType() == 4 || param.getType() == 6){           //看看,看见
+//                    model.setModelObjUrl(String.format(FilePath.OBJ_LOCAL_PATH,environment ,num) +"/mesh.obj");
+//                    model.setModelGlbUrl(getGlbUrl(param.getType(),num,model));
+//                    model.setModelType("b3dm");
+//                    model.setModelDateType("b3dm");
+//                }
                 model.setNum(num);
                 model.setCreateStatus(1);
                 modelList.add(model);
@@ -119,34 +121,9 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
 
 
     private String getGlbUrl(Integer type, String num,Model model) {
-        String objPath = String.format(FilePath.OBJ_LOCAL_PATH ,environment,num);
-
-        try {
-            if(type == 0 || type == 1 || type == 4 || type == 6){ //看看,看见
-
-                ShellUtil.yunDownload(String.format(FilePath.OBJ_OSS_PATH, num)+"/data/mesh" ,objPath);
-                List<String> localGlbPaths = new ArrayList<>();
-                List<String> ossGlbPaths = new ArrayList<>();
-                File localFile = new File(objPath);
-                this.toGlB(localFile,localGlbPaths);
-                model.setModelSize(FileWriterUtil.setFileSize(localFile.length()));
-
-                if(!localGlbPaths.isEmpty()){
-                    for (String localGlbPath : localGlbPaths) {
-                        File file = new File(localGlbPath);
-                        //model.setModelSize(FileWriterUtil.setFileSize(file.length()));
-                        String ossPath = localGlbPath.replace("/mnt/","");
-                        ShellUtil.yunUpload(localGlbPath,ossPath);
-                        ossGlbPaths.add(queryPath +ossPath+"/tileset.json");
-                    }
-                    return JSONArray.toJSONString(ossGlbPaths);
-                }
+        if(type == 0 || type == 1 || type == 4 || type == 6){ //看看,看见
 
-            }
-        }catch (Exception e){
-            log.info("obj-to-b3dm-error:{},{}",num,model.getModelId(),e);
-        }finally {
-            FileUtil.del(new File(objPath).getParentFile().getPath());
+            threadService.objToB3dm(num,model.getModelId());
         }
 
         return null;

+ 46 - 0
src/main/java/com/fdkankan/fusion/service/impl/ThreadService.java

@@ -2,6 +2,7 @@ package com.fdkankan.fusion.service.impl;
 
 import cn.hutool.core.io.FileUtil;
 import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.fusion.common.FilePath;
 import com.fdkankan.fusion.common.util.*;
 import com.fdkankan.fusion.entity.Model;
@@ -185,4 +186,49 @@ public class ThreadService {
             redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),status.toString());
         }
     }
+
+    @Async
+    public void objToB3dm(String num,Integer modelId) {
+        String objPath = String.format(FilePath.OBJ_LOCAL_PATH ,environment,num);
+        ShellUtil.yunDownload(String.format(FilePath.OBJ_OSS_PATH, num)+"/data/mesh" ,objPath);
+        List<String> localGlbPaths = new ArrayList<>();
+        List<String> ossGlbPaths = new ArrayList<>();
+        File localFile = new File(objPath);
+        this.toGlB(localFile,localGlbPaths);
+        if(!localGlbPaths.isEmpty()){
+            for (String localGlbPath : localGlbPaths) {
+                String ossPath = localGlbPath.replace("/mnt/","");
+                ShellUtil.yunUpload(localGlbPath,ossPath);
+                ossGlbPaths.add(queryPath +ossPath+"/tileset.json");
+            }
+            String ossGlbPath =  JSONArray.toJSONString(ossGlbPaths);
+            LambdaUpdateWrapper<Model> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(Model::getModelId,modelId);
+            wrapper.set(Model::getModelGlbUrl,ossGlbPath);
+            wrapper.set(Model::getModelDateType,"b3dm");
+            wrapper.set(Model::getModelType,"b3dm");
+            modelService.update(wrapper);
+        }
+    }
+
+
+    private void toGlB(File localFile, List<String> localGlbPath) {
+        File[] files = localFile.listFiles();
+        for (File file : files) {
+            if(file.isDirectory()){
+                toGlB(file,localGlbPath);
+            }
+            if(file.getParent().contains("lod_") && file.getParent().contains("lod_0") ){
+                String glbPath =  OBJToGLBUtil.objToB3dm(file.getPath(),file.getParentFile().getPath()+"/b3dm");
+                localGlbPath.add(glbPath);
+                continue;
+            }
+
+            if(file.getName().contains(".obj")){
+                String glbPath =  OBJToGLBUtil.objToB3dm(file.getPath(),file.getParentFile().getPath()+"/b3dm");
+                localGlbPath.add(glbPath);
+            }
+        }
+    }
+
 }