// Cancel current model
this.controller.setModel(null);
// Read model in modelLoader executor
this.modelLoader.execute(new Runnable() {
public void run() {
Content modelContent = null;
try {
modelContent = contentManager.getContent(modelName);
} catch (RecorderException ex) {
if (!ignoreException) {
showModelChoiceError(modelName, preferences);
}
return;
}
BranchGroup model = null;
Vector3f modelSize = null;
try {
model = readModel(modelContent);
modelSize = ModelManager.getInstance().getSize(model);
// Copy model to a temporary OBJ content with materials and textures
modelContent = copyToTemporaryOBJContent(model, modelName);
} catch (IOException ex) {
model = null;
} catch (IllegalArgumentException ex) {
// Model is empty
model = null;
}
if (model == null) {
try {
// Copy model content to a temporary content
modelContent = TemporaryURLContent.copyToTemporaryURLContent(modelContent);
} catch (IOException ex2) {
if (!ignoreException) {
showModelChoiceError(modelName, preferences);
}
return;
}
// If content couldn't be loaded, try to load model as a zipped file
ZipInputStream zipIn = null;
try {
URLContent urlContent = (URLContent)modelContent;
// Open zipped stream
zipIn = new ZipInputStream(urlContent.openStream());
// Parse entries to see if one is readable
for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
try {
String entryName = entry.getName();
// Ignore directory entries and entries starting by a dot
if (!entryName.endsWith("/")) {
int slashIndex = entryName.lastIndexOf('/');
String entryFileName = entryName.substring(++slashIndex);
if (!entryFileName.startsWith(".")) {
URL entryUrl = new URL("jar:" + urlContent.getURL() + "!/"
+ URLEncoder.encode(entryName, "UTF-8").replace("+", "%20").replace("%2F", "/"));
modelContent = new TemporaryURLContent(entryUrl);
model = readModel(modelContent);
modelSize = ModelManager.getInstance().getSize(model);
break;
}
}
} catch (IOException ex3) {
// Ignore exception and try next entry
model = null;
} catch (IllegalArgumentException ex3) {
// Model is empty
model = null;
}
}
} catch (IOException ex2) {
model = null;
} finally {
try {
if (zipIn != null) {
zipIn.close();
}
} catch (IOException ex2) {
// Ignore close exception
}
}
}
final BranchGroup readModel = model;
final Vector3f readModelSize = modelSize;
final Content readContent = modelContent;
// Update components in dispatch thread
EventQueue.invokeLater(new Runnable() {
public void run() {
if (readModel != null) {
controller.setModel(readContent);