-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathConvert.java
More file actions
89 lines (85 loc) · 2.58 KB
/
Copy pathConvert.java
File metadata and controls
89 lines (85 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package javaforce.gl.model;
import java.io.*;
import javaforce.*;
import javaforce.gl.*;
import javaforce.gl.model.*;
/**
* Converts 3d model files to JF3D.
*
* @author pquiring
*/
public class Convert {
public static void usage() {
System.out.println("Desc : Convert");
System.out.println(" Usage : infile outfile");
System.out.println(" Usage : infolder outfolder");
System.out.println("In formats: .3ds .blend .obj");
System.out.println("Out format: .jf3d");
System.exit(0);
}
public static void main(String[] args) {
if (args == null || args.length != 2) usage();
String in = args[0];
String out = args[1];
File inf = new File(in);
File outf = new File(out);
if (inf.isDirectory() && inf.isDirectory() ) {
doFolder(in ,out);
} else {
if (inf.isDirectory() || outf.isDirectory()) {
usage();
}
doFile(in, out);
}
}
private static void doFile(String in, String out) {
File inf = new File(in);
File outf = new File(out);
if (outf.exists()) {
long inTime = inf.lastModified();
long outTime = outf.lastModified();
if (outTime >= inTime) {
System.out.println(out + " is up-to-date");
return;
}
}
Model model = null;
if (in.toLowerCase().endsWith(".3ds")) {
Model3DS _3ds = new Model3DS();
model = _3ds.load(in);
} else if (in.toLowerCase().endsWith(".blend")) {
ModelBLEND blend = new ModelBLEND();
model = blend.load(in);
} else if (in.toLowerCase().endsWith(".obj")) {
ModelOBJ obj = new ModelOBJ();
model = obj.load(in);
} else if (in.toLowerCase().endsWith(".json")) {
ModelJSON obj = new ModelJSON();
model = obj.load(in);
} else {
usage();
}
if (model == null) {
JFLog.log("ModelConvert:Error:Load mesh failed:" + in);
return;
}
ModelJF3D jf3d = new ModelJF3D();
jf3d.save(model, out);
System.out.println("Converted " + in + " to " + out);
}
private static void doFolder(String in, String out) {
File[] ins = new File(in).listFiles();
for(int a=0;a<ins.length;a++) {
File f = ins[a];
if (f.isDirectory()) continue;
String fn = f.getName();
if (!fn.endsWith(".3ds") && !fn.endsWith(".blend") && !fn.endsWith(".obj") && !fn.endsWith(".json")) continue;
int extlen = 4;
if (fn.endsWith(".json")) extlen = 5;
if (fn.endsWith(".blend")) extlen = 6;
String _in = f.getAbsolutePath();
String _out = out + "/" + fn.substring(0, fn.length() - extlen) + ".jf3d";
doFile(_in, _out);
}
}
}