Browse Source

场景obj模型转换为b3dm

lyhzzz 1 year ago
parent
commit
f707eb7ec9

+ 2 - 3
src/main/java/com/fdkankan/fusion/common/FilePath.java

@@ -2,15 +2,14 @@ package com.fdkankan.fusion.common;
 
 public class FilePath {
 
-    public final static String LOCAL_BASE_PATH = "/home/tomcat/jar-fusion-8808/";
+    public final static String LOCAL_BASE_PATH = "/mnt/fusion/";
     public final static String MNT_BASE_PATH = "/mnt/fusion/";
 
     public final static String OBJ_OSS_PATH = "scene_view_data/%s";
-    public final static String GLB_OSS_PATH = "fusion/%s/model/glb/%s/mesh.glb";
-    public final static String B3DM_OSS_PATH = "fusion/%s/model/b3dm/%s";
     public final static String VIDEO_OSS_PATH = "fusion/%s/video/%s";
     public final static String File_OSS_PATH = "fusion/%s/file/%s";
     public final static String ICON_OSS_PATH = "fusion/%s/icon/%s";
+    public final static String MODEL_OSS_PATH = "fusion/%s/model/%s";
     public final static String DEFAULT_OSS_PATH = "fusion/default/%s";
 
    // public final static String VIDEO_LOCAL_PATH = "D:\\video\\merge";

+ 13 - 17
src/main/java/com/fdkankan/fusion/service/impl/CaseNumServiceImpl.java

@@ -118,30 +118,20 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
     private String getGlbUrl(Integer type, String num,Model model) {
         if(type == 0 || type == 1 || type == 4 || type == 6){ //看看,看见
             String objPath = String.format(FilePath.OBJ_LOCAL_PATH ,environment,num);
-//            if(uploadToOssUtil.existKey(glbOssPath)){
-//                return queryPath + "/"+glbOssPath;
-//            }
+            String ossGlbPath =String.format(FilePath.MODEL_OSS_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.size() >0){
+            if(!localGlbPaths.isEmpty()){
                 for (String localGlbPath : localGlbPaths) {
                     File file = new File(localGlbPath);
-                    if(file!=null){
-                        model.setModelSize(FileWriterUtil.setFileSize(file.length()));
-                    }
-                    String ossGlbPath = localGlbPath.replace(FilePath.LOCAL_BASE_PATH,"fusion/");
-                    uploadToOssUtil.uploadOss(localGlbPath,ossGlbPath);
-                    if(ossGlbPath.contains("lod_")){
-                        if(ossGlbPath.contains("lod_0")){
-                            ossGlbPaths.add(queryPath  +ossGlbPath);
-                        }
-                        continue;
-                    }
-                    ossGlbPaths.add(queryPath +ossGlbPath);
+                    model.setModelSize(FileWriterUtil.setFileSize(file.length()));
+                    ShellUtil.yunUpload(localGlbPath,objPath);
+                    ossGlbPaths.add(queryPath +ossGlbPath+"/tileset.json");
                 }
                 return JSONArray.toJSONString(ossGlbPaths);
             }
@@ -157,8 +147,14 @@ public class CaseNumServiceImpl extends ServiceImpl<ICaseNumMapper, CaseNumEntit
             if(file.isDirectory()){
                 toGlB(file,localGlbPath);
             }
+            if(file.getParent().contains("lod_") && file.getParent().contains("lod_0") ){
+                String glbPath =  OBJToGLBUtil.objToB3dm(file.getPath(),file.getPath());
+                localGlbPath.add(glbPath);
+                continue;
+            }
+
             if(file.getName().contains(".obj")){
-               String glbPath =  OBJToGLBUtil.objToB3dm(file.getPath(),file.getPath().replace(".obj",".glb") );
+               String glbPath =  OBJToGLBUtil.objToB3dm(file.getPath(),file.getPath());
                localGlbPath.add(glbPath);
             }
         }

+ 10 - 11
src/main/java/com/fdkankan/fusion/service/impl/ThreadService.java

@@ -76,19 +76,18 @@ public class ThreadService {
             }
             redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"20");
 
-            String glbOssPath = String.format(FilePath.GLB_OSS_PATH,environment, model.getModelId());
+            String ossPath = String.format(FilePath.MODEL_OSS_PATH,environment, model.getModelId());
 
             String name = file1.getName();
             if(name.contains("obj") || name.contains("OBJ")){
-                glbOssPath = glbOssPath.replace("mesh.glb",file1.getName().replace(".obj",".glb"));
+                String localPath = FilePath.LOCAL_BASE_PATH +  String.format(FilePath.MODEL_OSS_PATH,environment, model.getModelId());
                 model.setModelDateType("obj");
-                model.setModelType("glb");
-                OBJToGLBUtil.objToB3dm2(file1.getPath(), file1.getPath().replace(".obj",".glb"));
+                model.setModelType("b3dm");
+                OBJToGLBUtil.objToB3dm2(file1.getPath(),localPath);
                 redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"65");
-                uploadToOssUtil.uploadOss(file1.getPath().replace(".obj",".glb"),glbOssPath);
-                if(!uploadToOssUtil.existKey(glbOssPath)){
-                    throw new BusinessException(-1,"缺少.glb文件");
-                }
+                ShellUtil.yunUpload(localPath,ossPath);
+                model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath + ossPath+"/tileset.json")));
+
             }
             if(name.contains(".ply")){
                 model.setModelDateType("ply");
@@ -101,14 +100,14 @@ public class ThreadService {
 
             if("las".equals(model.getModelType()) || "ply".equals(model.getModelType()) ){
                 mntFile =  OBJToGLBUtil.lasOrPlyToBin(file1);
-                glbOssPath = mntFile.getPath().replace("/mnt/","")+"/webcloud";
+                ossPath = mntFile.getPath().replace("/mnt/","")+"/webcloud";
                 redisUtil.set(RedisKeyUtil.modelUpload+model.getModelId(),"65");
                 uploadToOssUtil.uploadFileOss(mntFile );
-                if(!uploadToOssUtil.existKey(glbOssPath+"/cloud.js")){
+                model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath + ossPath)));
+                if(!uploadToOssUtil.existKey(ossPath+"/cloud.js")){
                     throw new BusinessException(-1,"缺少cloud.js文件");
                 }
             }
-            model.setModelGlbUrl(JSONArray.toJSONString(Arrays.asList(queryPath + glbOssPath)));
 
             String b3dmPath = objPathFile.getPath().replace(FilePath.LOCAL_BASE_PATH,"fusion/");
             if(name.contains(".osgb")){