|
@@ -6,9 +6,12 @@ import com.fdkankan.fusion.common.FilePath;
|
|
|
import com.fdkankan.fusion.common.ResultCode;
|
|
|
import com.fdkankan.fusion.exception.BusinessException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
|
|
|
|
|
|
import java.io.*;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.Date;
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
|
@Slf4j
|
|
@@ -86,15 +89,15 @@ public class OBJToGLBUtil {
|
|
|
|
|
|
private static boolean checkMtl(File allFile,File file) {
|
|
|
if(!file.getName().contains("mtl")){
|
|
|
- return false;
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
|
|
|
}
|
|
|
LinkedHashSet<String> imgName = new LinkedHashSet<>();
|
|
|
if(allFile == null || allFile.length()<=0 ){
|
|
|
- return false;
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
|
|
|
}
|
|
|
File[] files = allFile.listFiles();
|
|
|
if(files == null || files.length<=0 ){
|
|
|
- return false;
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_OBJ_ERROR);
|
|
|
}
|
|
|
for (File listFile : files) {
|
|
|
String modelName = listFile.getName();
|
|
@@ -103,12 +106,44 @@ public class OBJToGLBUtil {
|
|
|
LinkedHashSet<String> imgMtl = readMtlFile(file.getPath());
|
|
|
for (String mtlName : imgMtl) {
|
|
|
if(!imgName.contains(mtlName)){
|
|
|
- throw new BusinessException(-1,mtlName +".jpg 图片缺失!");
|
|
|
+ throw new BusinessException(ResultCode.UPLOAD_FILE_MSG_ERROR.code,mtlName +".jpg 图片缺失!");
|
|
|
}
|
|
|
}
|
|
|
+ updateMtlFile(file);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ private static void updateMtlFile(File file) {
|
|
|
+ String mtlStr = FileUtil.readUtf8String(file);
|
|
|
+ String[] split = mtlStr.split("\n");
|
|
|
+ StringBuilder newMtlStr = new StringBuilder();
|
|
|
+ for (String s : split) {
|
|
|
+ if(s.toLowerCase().contains("tr")){
|
|
|
+ String[] split1 = s.split(" ");
|
|
|
+ if(split1.length <=1){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(isNumeric2(split1[1])){
|
|
|
+ String[] split2 = split1[1].split("\\.");
|
|
|
+ int number = Integer.parseInt(split2[0]);
|
|
|
+ if(number >=1){
|
|
|
+ number = 1 - number;
|
|
|
+ }
|
|
|
+ String numStr = number + (split2.length <=1 ?"": "."+split2[1]);
|
|
|
+ s = s.replace(split1[1],numStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newMtlStr.append(s).append("\n");
|
|
|
+ }
|
|
|
+ FileUtil.copyContent(file,new File(file.getPath()+new Date().getTime()+"back"),true);
|
|
|
+ FileUtil.writeString(newMtlStr.toString(),file, StandardCharsets.UTF_8);
|
|
|
+
|
|
|
+ }
|
|
|
+ public static boolean isNumeric2(String str) {
|
|
|
+ return str != null && str.matches("-?\\d+(\\.\\d+)?");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public static LinkedHashSet<String> readMtlFile(String mtlPath) {
|
|
|
LinkedHashSet<String> imgName = new LinkedHashSet<>();
|
|
|
FileInputStream fis = null;
|