SDK:
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
This commit is contained in:
		
							parent
							
								
									740a6fcf9a
								
							
						
					
					
						commit
						77b827ce6b
					
				| @ -70,25 +70,25 @@ public final class ImportModel implements ActionListener { | ||||
|     } | ||||
| 
 | ||||
|     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"); | ||||
|         boolean keepFiles = (Boolean) wiz.getProperty("keepfiles"); | ||||
|         List<AssetKey> keyList = (List<AssetKey>) wiz.getProperty("assetlist"); | ||||
|         String path = (String) wiz.getProperty("path"); | ||||
|         List<FileObject> assetList = (List<FileObject>) wiz.getProperty("assetfiles"); | ||||
|         String importPath = (String) wiz.getProperty("destpath"); | ||||
|         ProjectAssetManager manager = context.getLookup().lookup(ProjectAssetManager.class); | ||||
|         if (manager == null) { | ||||
|             throw new IllegalStateException("Cannot find project AssetManager!"); | ||||
|         } | ||||
|         List<FileObject> deleteList = new LinkedList<FileObject>(); | ||||
|         for (Iterator<AssetKey> it = keyList.iterator(); it.hasNext();) { | ||||
|             AssetKey assetKey = 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); | ||||
|         for (Iterator<FileObject> it = assetList.iterator(); it.hasNext();) { | ||||
|             FileObject source = it.next(); | ||||
|             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()); | ||||
|                 if (fileObj != null) { | ||||
|                     NotifyDescriptor.Confirmation msg = new NotifyDescriptor.Confirmation( | ||||
| @ -104,19 +104,25 @@ public final class ImportModel implements ActionListener { | ||||
|                 } else { | ||||
|                     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) { | ||||
|                             deleteList.add(fileObj); | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } catch (Exception ex) { | ||||
|                 Exceptions.printStackTrace(ex); | ||||
|             } | ||||
|         } | ||||
|         } | ||||
|         File file = new File(manager.getAssetFolderName() + "/" + importPath + "/" + key.getName()); | ||||
| //        File outFile = new File(manager.getAssetFolderName() + "/" + importPath + "/" + key.getName().replaceAll(key.getExtension(), "j3o")); | ||||
| 
 | ||||
|         FileObject file = manager.getAssetFolder().getFileObject(importPath + "/" + key.getName()); | ||||
|         DataObject targetModel; | ||||
|         try { | ||||
|             targetModel = DataObject.find(FileUtil.toFileObject(file)); | ||||
|             targetModel = DataObject.find(file); | ||||
|             if (targetModel instanceof SpatialAssetDataObject) { | ||||
|                 //TODO: wtf? why do i have to add the assetmanager? | ||||
|                 ((SpatialAssetDataObject) targetModel).getLookupContents().add(manager); | ||||
| @ -128,8 +134,6 @@ public final class ImportModel implements ActionListener { | ||||
| 
 | ||||
|                 } | ||||
|                 data.saveAsset(); | ||||
| //                BinaryExporter exp = BinaryExporter.getInstance(); | ||||
| //                exp.save(spat, outFile); | ||||
|             } | ||||
|         } catch (Exception ex) { | ||||
|             Exceptions.printStackTrace(ex); | ||||
|  | ||||
| @ -15,6 +15,7 @@ import javax.swing.JPanel; | ||||
| import org.openide.DialogDisplayer; | ||||
| import org.openide.NotifyDescriptor; | ||||
| import org.openide.WizardDescriptor; | ||||
| import org.openide.filesystems.FileObject; | ||||
| import org.openide.util.Exceptions; | ||||
| 
 | ||||
| @SuppressWarnings({"unchecked", "serial"}) | ||||
| @ -26,8 +27,9 @@ public final class ModelImporterVisualPanel3 extends JPanel { | ||||
|     private AssetData data; | ||||
|     private AssetKey mainKey; | ||||
|     private Spatial currentModel; | ||||
|     private List<AssetKey> assets; | ||||
|     private List<AssetKey> failed; | ||||
|     private List<FileObject> assets; | ||||
|     private List<AssetKey> assetKeys; | ||||
|     private List<AssetKey> failedKeys; | ||||
| 
 | ||||
|     /** | ||||
|      * Creates new form ModelImporterVisualPanel1 | ||||
| @ -51,6 +53,9 @@ public final class ModelImporterVisualPanel3 extends JPanel { | ||||
|         manager = (ProjectAssetManager) wiz.getProperty("manager"); | ||||
|         mainKey = (AssetKey) wiz.getProperty("mainkey"); | ||||
|         data = (AssetData) wiz.getProperty("assetdata"); | ||||
|         assets = null; | ||||
|         assetKeys = null; | ||||
|         failedKeys = null; | ||||
|         loadModel(mainKey); | ||||
|         if (currentModel != null) { | ||||
|             offPanel.attach(currentModel); | ||||
| @ -60,8 +65,9 @@ public final class ModelImporterVisualPanel3 extends JPanel { | ||||
|     } | ||||
| 
 | ||||
|     public void applySettings(WizardDescriptor wiz) { | ||||
|         wiz.putProperty("assetlist", assets); | ||||
|         wiz.putProperty("failedlist", failed); | ||||
|         wiz.putProperty("assetfiles", assets); | ||||
|         wiz.putProperty("assetlist", assetKeys); | ||||
|         wiz.putProperty("failedlist", failedKeys); | ||||
|         wiz.putProperty("model", currentModel); | ||||
|         if (currentModel != null) { | ||||
|             offPanel.detach(currentModel); | ||||
| @ -83,11 +89,12 @@ public final class ModelImporterVisualPanel3 extends JPanel { | ||||
|         try { | ||||
|             currentModel = (Spatial) data.loadAsset(); | ||||
|             if (currentModel != null) { | ||||
|                 assets = data.getAssetKeyList(); | ||||
|                 failed = data.getFailedList(); | ||||
|                 jList1.setListData(assets.toArray()); | ||||
|                 jList2.setListData(failed.toArray()); | ||||
|                 if (failed.size() > 0) { | ||||
|                 assetKeys = data.getAssetKeyList(); | ||||
|                 failedKeys = data.getFailedList(); | ||||
|                 assets = data.getAssetList(); | ||||
|                 jList1.setListData(assetKeys.toArray()); | ||||
|                 jList2.setListData(failedKeys.toArray()); | ||||
|                 if (failedKeys.size() > 0) { | ||||
|                     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")); | ||||
|                 } else { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user