|
@@ -116,29 +116,34 @@ public class OBJToGLBUtil {
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
+ try {
|
|
|
+ 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);
|
|
|
}
|
|
|
- String numStr = number + (split2.length <=1 ?"": "."+split2[1]);
|
|
|
- s = s.replace(split1[1],numStr);
|
|
|
}
|
|
|
+ newMtlStr.append(s).append("\n");
|
|
|
}
|
|
|
- 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);
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("备份失败:{}",e);
|
|
|
}
|
|
|
- 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) {
|
|
@@ -233,4 +238,8 @@ public class OBJToGLBUtil {
|
|
|
ShellUtil.execCmd(cmd);
|
|
|
return sourcePath;
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ updateMtlFile(new File("D:\\北厢房\\bxf.mtl"));
|
|
|
+ }
|
|
|
}
|