Re: 3D loaders - 2 questions
Posted by jfpauly on Nov 10, 2024; 4:51pm
URL: https://forum.jogamp.org/3D-loaders-2-questions-tp4043577p4043614.html
Loading 3ds files with 3ds2java.exe. from Pieter Bos.
This is a two steps process:
1- 3ds file is converted to a c3d file.
2- cd3 is then loaded.
The first step is made once only. Further loadings of the model are done from the c3d file.
/**
*
3ds files process
* Theses files are first converted to c3d with 3ds2java.exe.
* <br>The programù 3ds2java.exe must be in the same directory as the
* 3ds file
* <p>
* To get texture files, they may be in a directory called textures,
* or in the same directory.
* <br>For instance :
* <pre>
*
* /------------+
* | models | ________/------------+
* +------------+ | modelname | ______ modelname.3ds
* +------------+ ______/------------+
* | textures | ___ xxx.JPG ....
* +------------+
*
* </pre> modelname.c3d is written in the same directory and can now be
* imported
*/
Here is the code to process 3ds
private void jMenuItem17ActionPerformed(java.awt.event.ActionEvent evt) {
String path = tools.getFn();
if (path == null) { // user cancel
return;
}
File file = new File(path);
String stuName = file.getName(); // 3ds file name
int point = stuName.lastIndexOf('.'); // point position
String root = stuName.substring(0, point); // get left part
//______Files controls_______________
// 3ds2java.exe is in /dist directory
File file3ds = new File(univers.distFile + "\\" + "3ds2java.exe");
if (file3ds.exists() == false) {
jTextArea1.setText("Please move 3ds2java.exe to /dist directory and try again");
return;
}
//_______________________________
// 3DS file is in /dist directory
int slash = path.lastIndexOf("\\"); // right slash position
String dir3ds = path.substring(0, slash); // get user file directory
if (dir3ds.equals(univers.distFile) == false) { // file should be in same directory than 3ds2java.exe
jTextArea1.setText("Please move " + stuName + " to /dist directory and try again");
return;
}
// end of controls_______________
String c3dName = root + ".c3d"; // build cd3 name
String cdCmd = "cmd cd " + univers.distFile; // go to directory where 3ds2java should be
String cmdStr = "3ds2java.exe " + stuName + " -o " + c3dName; // build 3ds2java input command
Runtime runtime = Runtime.getRuntime(); // get runtime environment
try {
runtime.exec(cdCmd); // go directory
Process process = runtime.exec(cmdStr); // run 3ds2java
process.waitFor();
} catch (IOException | InterruptedException ex) {
jTextArea1.setText("File error");
}
try {
loadC3d(univers.distFile + "\\" + c3dName); // 3DS to C3d convert will use 3ds2java output
} catch (IOException ex) {
Logger.getLogger(DrawPanel.class.getName()).log(Level.SEVERE, null, ex);
}
jTextArea1.setText(path + "loaded.");
}
________________________________________________________________________________________________________
void loadC3d(String c3dName) throws IOException {
Graf.graph2Tg(); // builds a graph to branch the model
try { // call Loader3d class shown in next reply message
Stud.readC3d(univers.animTg, c3dName);
} catch (FileNotFoundException | IncorrectFormatException | NullPointerException e1) {
messages(6);
}
univers.master.addChild(univers.pickGroup);
jTextArea1.setText(c3dName + "loaded.");
}
_____________________________________________________________________________________________________________