- fix Model Importer

- remove unnecessary hack from ProjectAssetManager

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10179 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 12 years ago
parent 65f384c06a
commit 2a77175db8
  1. 50
      sdk/jme3-core/src/com/jme3/gde/core/assets/ProjectAssetManager.java
  2. 36
      sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ImportModel.java
  3. 2
      sdk/jme3-model-importer/src/com/jme3/gde/modelimporter/ModelImporterVisualPanel1.java

@ -84,8 +84,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
private final List<String> folderNames = new LinkedList<String>(); private final List<String> folderNames = new LinkedList<String>();
private final List<FileObject> jarItems = new LinkedList<FileObject>(); private final List<FileObject> jarItems = new LinkedList<FileObject>();
private URLClassLoader loader; private URLClassLoader loader;
private boolean disableAbsolutePaths;
public ProjectAssetManager(Project prj, String folderName) { public ProjectAssetManager(Project prj, String folderName) {
super(true); super(true);
this.project = prj; this.project = prj;
@ -98,13 +97,13 @@ public class ProjectAssetManager extends DesktopAssetManager {
} }
/** /**
* Creates <code>ProjectAssetManager</code> for dummy projects. * Creates
* * <code>ProjectAssetManager</code> for dummy projects.
* @param path Path on disk to find assets from *
* @param disableAbsolutePaths If true, absolute asset paths won't * @param path Path on disk to find assets from and the filename is loaded
* be used and the filename is loaded from the path argument directly. * from the path argument directly.
*/ */
public ProjectAssetManager(FileObject path, boolean disableAbsolutePaths) { public ProjectAssetManager(FileObject path) {
super(true); super(true);
if (path == null) { if (path == null) {
this.project = new DummyProject(this); this.project = new DummyProject(this);
@ -113,12 +112,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
} }
String projectRootPath = project.getProjectDirectory().getPath(); String projectRootPath = project.getProjectDirectory().getPath();
logger.log(Level.INFO, "Add locator: {0}", projectRootPath); logger.log(Level.INFO, "Add locator: {0}", projectRootPath);
this.disableAbsolutePaths = disableAbsolutePaths; registerLocator(projectRootPath, "com.jme3.asset.plugins.FileLocator");
if (disableAbsolutePaths) {
registerLocator(projectRootPath, RelativeOnlyFileLocator.class);
} else {
registerLocator(projectRootPath, "com.jme3.asset.plugins.FileLocator");
}
for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) { for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) {
di.prepareManager(this); di.prepareManager(this);
} }
@ -126,33 +120,19 @@ public class ProjectAssetManager extends DesktopAssetManager {
} }
public ProjectAssetManager() { public ProjectAssetManager() {
this(null, false); this(null);
} }
/**
* If true, then this <code>ProjectAssetManager</code> ignores
* absolute asset paths.
* The assumption that asset paths are present physically under the assets
* folder root does not hold true in this case.
*/
public boolean isAbsolutePathsDisabled() {
return disableAbsolutePaths;
}
/** /**
* Returns the <code>FileObject</code> for a given asset key, or null * Returns the
* if no such asset exists. * <code>FileObject</code> for a given asset key, or null if no such asset
* * exists. TODO: Only works for real files in the asset folder atm
*
* @param assetKey The asset key to get the file object for * @param assetKey The asset key to get the file object for
* @return Either a FileObject for the asset or null if not found. * @return Either a FileObject for the asset or null if not found.
*/ */
public FileObject getAssetFileObject(AssetKey assetKey) { public FileObject getAssetFileObject(AssetKey assetKey) {
if (isAbsolutePathsDisabled()) { return getAssetFolder().getFileObject(assetKey.getName());
String fileName = assetKey.getName().substring(assetKey.getFolder().length());
return getAssetFolder().getFileObject(fileName);
} else {
return getAssetFolder().getFileObject(assetKey.getName());
}
} }
private void clearClassLoader() { private void clearClassLoader() {

@ -101,19 +101,7 @@ public final class ImportModel implements ActionListener {
} }
} }
private String correctImportPathLetterCase(String importPath, List<AssetKey> assetKeys) {
for (AssetKey key : assetKeys) {
if (importPath.equalsIgnoreCase(key.getFolder())) {
// Recommend using the folder letter case from asset key.
return key.getFolder();
}
}
// No assets or none match the path. Use original.
return importPath;
}
private void copyModel(WizardDescriptor wiz) { private void copyModel(WizardDescriptor wiz) {
// String path = (String) wiz.getProperty("path");
AssetKey modelKey = (AssetKey) wiz.getProperty("mainkey"); AssetKey modelKey = (AssetKey) wiz.getProperty("mainkey");
boolean keepFiles = (Boolean) wiz.getProperty("keepfiles"); boolean keepFiles = (Boolean) wiz.getProperty("keepfiles");
@ -126,27 +114,12 @@ public final class ImportModel implements ActionListener {
if (manager == null) { if (manager == null) {
throw new IllegalStateException("Cannot find project AssetManager!"); throw new IllegalStateException("Cannot find project AssetManager!");
} }
// Try to correct letter case in import path (this fixes case mismatch issues in Windows)
importPath = correctImportPathLetterCase(importPath, assetKeys);
List<FileObject> deleteList = new LinkedList<FileObject>(); List<FileObject> deleteList = new LinkedList<FileObject>();
int i = 0; for (Iterator<FileObject> it = assetList.iterator(); it.hasNext();) {
for (FileObject source : assetList) { FileObject source = it.next();
AssetKey assetKey = assetKeys.get(i++); String folderName = importPath + "/" + importManager.getRelativeAssetPath(source.getParent().getPath());
try { try {
String folderName;
// Put it in the user's import path if we use relative paths
// (asset keys have folders)
// or loading the model portion of the asset.
// If we are loading dependent assets of J3O or J3M (absolute paths),
// put them in the expected absolute paths.
if (assetKey.equals(modelKey) || assetKey.getFolder().equals("")) {
folderName = importPath + "/" + importManager.getRelativeAssetPath(source.getParent().getPath());
} else {
folderName = assetKey.getFolder();
}
FileObject dest = manager.getAssetFolder().getFileObject(folderName); FileObject dest = manager.getAssetFolder().getFileObject(folderName);
if (dest == null) { if (dest == null) {
dest = FileUtil.createFolder(manager.getAssetFolder(), folderName); dest = FileUtil.createFolder(manager.getAssetFolder(), folderName);
@ -170,6 +143,7 @@ public final class ImportModel implements ActionListener {
if (fileObj != null) { if (fileObj != null) {
DataObject obj = DataObject.find(fileObj); DataObject obj = DataObject.find(fileObj);
AssetData data = obj.getLookup().lookup(AssetData.class); AssetData data = obj.getLookup().lookup(AssetData.class);
AssetKey assetKey = data.getAssetKey();
if (data != null) { if (data != null) {
if (obj instanceof SpatialAssetDataObject) { if (obj instanceof SpatialAssetDataObject) {
// Delete models that are not J3O. // Delete models that are not J3O.

@ -80,7 +80,7 @@ public final class ModelImporterVisualPanel1 extends JPanel {
manager = null; manager = null;
dataObject = null; dataObject = null;
data = null; data = null;
manager = new ProjectAssetManager(FileUtil.toFileObject(path).getParent(), true); manager = new ProjectAssetManager(FileUtil.toFileObject(path).getParent());
try { try {
dataObject = DataObject.find(FileUtil.toFileObject(path)); dataObject = DataObject.find(FileUtil.toFileObject(path));
data = dataObject != null ? dataObject.getLookup().lookup(AssetData.class) : null; data = dataObject != null ? dataObject.getLookup().lookup(AssetData.class) : null;

Loading…
Cancel
Save