ModelImportTool
- uses FileObject list of assets instead of AssetKeys
- uses more robust copying
- supports binary ogre files (in theory)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9480 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 13 years ago
parent 740a6fcf9a
commit 77b827ce6b
  1. 38
      sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ImportModel.java
  2. 25
      sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ModelImporterVisualPanel3.java

@ -70,29 +70,29 @@ public final class ImportModel implements ActionListener {
} }
private void copyModel(WizardDescriptor wiz) { private void copyModel(WizardDescriptor wiz) {
// List<AssetKey> keyList = (List<AssetKey>) wiz.getProperty("assetlist");
// String path = (String) wiz.getProperty("path");
AssetKey key = (AssetKey) wiz.getProperty("mainkey"); AssetKey key = (AssetKey) wiz.getProperty("mainkey");
boolean keepFiles = (Boolean) wiz.getProperty("keepfiles"); boolean keepFiles = (Boolean) wiz.getProperty("keepfiles");
List<AssetKey> keyList = (List<AssetKey>) wiz.getProperty("assetlist"); List<FileObject> assetList = (List<FileObject>) wiz.getProperty("assetfiles");
String path = (String) wiz.getProperty("path");
String importPath = (String) wiz.getProperty("destpath"); String importPath = (String) wiz.getProperty("destpath");
ProjectAssetManager manager = context.getLookup().lookup(ProjectAssetManager.class); ProjectAssetManager manager = context.getLookup().lookup(ProjectAssetManager.class);
if (manager == null) { if (manager == null) {
throw new IllegalStateException("Cannot find project AssetManager!"); throw new IllegalStateException("Cannot find project AssetManager!");
} }
List<FileObject> deleteList = new LinkedList<FileObject>(); List<FileObject> deleteList = new LinkedList<FileObject>();
for (Iterator<AssetKey> it = keyList.iterator(); it.hasNext();) { for (Iterator<FileObject> it = assetList.iterator(); it.hasNext();) {
AssetKey assetKey = it.next(); FileObject source = it.next();
File file = new File(path + "/" + assetKey.getFolder() + assetKey.getName());
if (file.exists()) {
FileObject source = FileUtil.toFileObject(file);
File destFolder = new File(manager.getAssetFolderName() + "/" + importPath + "/" + assetKey.getFolder() + "/");
destFolder.mkdirs();
FileObject dest = FileUtil.toFileObject(destFolder);
try { try {
String folderName = importPath + "/" + manager.getRelativeAssetPath(source.getParent().getPath());
FileObject dest = manager.getAssetFolder().getFileObject(folderName);
if (dest == null) {
dest = FileUtil.createFolder(manager.getAssetFolder(), folderName);
}
FileObject fileObj = dest.getFileObject(source.getName(), source.getExt()); FileObject fileObj = dest.getFileObject(source.getName(), source.getExt());
if (fileObj != null) { if (fileObj != null) {
NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation( NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation(
"File "+source.getNameExt()+" exists, overwrite?", "File " + source.getNameExt() + " exists, overwrite?",
NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.YES_NO_OPTION,
NotifyDescriptor.WARNING_MESSAGE); NotifyDescriptor.WARNING_MESSAGE);
Object result = DialogDisplayer.getDefault().notify(msg); Object result = DialogDisplayer.getDefault().notify(msg);
@ -104,19 +104,25 @@ public final class ImportModel implements ActionListener {
} else { } else {
fileObj = source.copy(dest, source.getName(), source.getExt()); fileObj = source.copy(dest, source.getName(), source.getExt());
} }
if (fileObj != null) {
DataObject obj = DataObject.find(fileObj);
AssetData data = obj.getLookup().lookup(AssetData.class);
if (data != null) {
AssetKey assetKey = data.getAssetKey();
if (!(assetKey instanceof TextureKey) && fileObj != null) { if (!(assetKey instanceof TextureKey) && fileObj != null) {
deleteList.add(fileObj); deleteList.add(fileObj);
} }
}
}
} catch (Exception ex) { } catch (Exception ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
} }
} }
}
File file = new File(manager.getAssetFolderName() + "/" + importPath + "/" + key.getName()); FileObject file = manager.getAssetFolder().getFileObject(importPath + "/" + key.getName());
// File outFile = new File(manager.getAssetFolderName() + "/" + importPath + "/" + key.getName().replaceAll(key.getExtension(), "j3o"));
DataObject targetModel; DataObject targetModel;
try { try {
targetModel = DataObject.find(FileUtil.toFileObject(file)); targetModel = DataObject.find(file);
if (targetModel instanceof SpatialAssetDataObject) { if (targetModel instanceof SpatialAssetDataObject) {
//TODO: wtf? why do i have to add the assetmanager? //TODO: wtf? why do i have to add the assetmanager?
((SpatialAssetDataObject) targetModel).getLookupContents().add(manager); ((SpatialAssetDataObject) targetModel).getLookupContents().add(manager);
@ -128,8 +134,6 @@ public final class ImportModel implements ActionListener {
} }
data.saveAsset(); data.saveAsset();
// BinaryExporter exp = BinaryExporter.getInstance();
// exp.save(spat, outFile);
} }
} catch (Exception ex) { } catch (Exception ex) {
Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);

@ -15,6 +15,7 @@ import javax.swing.JPanel;
import org.openide.DialogDisplayer; import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor; import org.openide.NotifyDescriptor;
import org.openide.WizardDescriptor; import org.openide.WizardDescriptor;
import org.openide.filesystems.FileObject;
import org.openide.util.Exceptions; import org.openide.util.Exceptions;
@SuppressWarnings({"unchecked", "serial"}) @SuppressWarnings({"unchecked", "serial"})
@ -26,8 +27,9 @@ public final class ModelImporterVisualPanel3 extends JPanel {
private AssetData data; private AssetData data;
private AssetKey mainKey; private AssetKey mainKey;
private Spatial currentModel; private Spatial currentModel;
private List<AssetKey> assets; private List<FileObject> assets;
private List<AssetKey> failed; private List<AssetKey> assetKeys;
private List<AssetKey> failedKeys;
/** /**
* Creates new form ModelImporterVisualPanel1 * Creates new form ModelImporterVisualPanel1
@ -51,6 +53,9 @@ public final class ModelImporterVisualPanel3 extends JPanel {
manager = (ProjectAssetManager) wiz.getProperty("manager"); manager = (ProjectAssetManager) wiz.getProperty("manager");
mainKey = (AssetKey) wiz.getProperty("mainkey"); mainKey = (AssetKey) wiz.getProperty("mainkey");
data = (AssetData) wiz.getProperty("assetdata"); data = (AssetData) wiz.getProperty("assetdata");
assets = null;
assetKeys = null;
failedKeys = null;
loadModel(mainKey); loadModel(mainKey);
if (currentModel != null) { if (currentModel != null) {
offPanel.attach(currentModel); offPanel.attach(currentModel);
@ -60,8 +65,9 @@ public final class ModelImporterVisualPanel3 extends JPanel {
} }
public void applySettings(WizardDescriptor wiz) { public void applySettings(WizardDescriptor wiz) {
wiz.putProperty("assetlist", assets); wiz.putProperty("assetfiles", assets);
wiz.putProperty("failedlist", failed); wiz.putProperty("assetlist", assetKeys);
wiz.putProperty("failedlist", failedKeys);
wiz.putProperty("model", currentModel); wiz.putProperty("model", currentModel);
if (currentModel != null) { if (currentModel != null) {
offPanel.detach(currentModel); offPanel.detach(currentModel);
@ -83,11 +89,12 @@ public final class ModelImporterVisualPanel3 extends JPanel {
try { try {
currentModel = (Spatial) data.loadAsset(); currentModel = (Spatial) data.loadAsset();
if (currentModel != null) { if (currentModel != null) {
assets = data.getAssetKeyList(); assetKeys = data.getAssetKeyList();
failed = data.getFailedList(); failedKeys = data.getFailedList();
jList1.setListData(assets.toArray()); assets = data.getAssetList();
jList2.setListData(failed.toArray()); jList1.setListData(assetKeys.toArray());
if (failed.size() > 0) { jList2.setListData(failedKeys.toArray());
if (failedKeys.size() > 0) {
statusLabel.setText(org.openide.util.NbBundle.getMessage(ModelImporterVisualPanel3.class, "ModelImporterVisualPanel3.statusLabel.text_missing")); statusLabel.setText(org.openide.util.NbBundle.getMessage(ModelImporterVisualPanel3.class, "ModelImporterVisualPanel3.statusLabel.text_missing"));
infoTextArea.setText(org.openide.util.NbBundle.getMessage(ModelImporterVisualPanel3.class, "ModelImporterVisualPanel3.infoTextArea.text_missing")); infoTextArea.setText(org.openide.util.NbBundle.getMessage(ModelImporterVisualPanel3.class, "ModelImporterVisualPanel3.infoTextArea.text_missing"));
} else { } else {

Loading…
Cancel
Save