- fix Model Importer
- remove unnecessary hack from ProjectAssetManager git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10179 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
65f384c06a
commit
2a77175db8
@ -84,8 +84,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
||||
private final List<String> folderNames = new LinkedList<String>();
|
||||
private final List<FileObject> jarItems = new LinkedList<FileObject>();
|
||||
private URLClassLoader loader;
|
||||
private boolean disableAbsolutePaths;
|
||||
|
||||
|
||||
public ProjectAssetManager(Project prj, String folderName) {
|
||||
super(true);
|
||||
this.project = prj;
|
||||
@ -98,13 +97,13 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* be used and the filename is loaded from the path argument directly.
|
||||
* Creates
|
||||
* <code>ProjectAssetManager</code> for dummy projects.
|
||||
*
|
||||
* @param path Path on disk to find assets from and the filename is loaded
|
||||
* from the path argument directly.
|
||||
*/
|
||||
public ProjectAssetManager(FileObject path, boolean disableAbsolutePaths) {
|
||||
public ProjectAssetManager(FileObject path) {
|
||||
super(true);
|
||||
if (path == null) {
|
||||
this.project = new DummyProject(this);
|
||||
@ -113,12 +112,7 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
||||
}
|
||||
String projectRootPath = project.getProjectDirectory().getPath();
|
||||
logger.log(Level.INFO, "Add locator: {0}", projectRootPath);
|
||||
this.disableAbsolutePaths = disableAbsolutePaths;
|
||||
if (disableAbsolutePaths) {
|
||||
registerLocator(projectRootPath, RelativeOnlyFileLocator.class);
|
||||
} else {
|
||||
registerLocator(projectRootPath, "com.jme3.asset.plugins.FileLocator");
|
||||
}
|
||||
registerLocator(projectRootPath, "com.jme3.asset.plugins.FileLocator");
|
||||
for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) {
|
||||
di.prepareManager(this);
|
||||
}
|
||||
@ -126,33 +120,19 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
||||
}
|
||||
|
||||
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
|
||||
* if no such asset exists.
|
||||
*
|
||||
* Returns the
|
||||
* <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
|
||||
* @return Either a FileObject for the asset or null if not found.
|
||||
*/
|
||||
public FileObject getAssetFileObject(AssetKey assetKey) {
|
||||
if (isAbsolutePathsDisabled()) {
|
||||
String fileName = assetKey.getName().substring(assetKey.getFolder().length());
|
||||
return getAssetFolder().getFileObject(fileName);
|
||||
} else {
|
||||
return getAssetFolder().getFileObject(assetKey.getName());
|
||||
}
|
||||
return getAssetFolder().getFileObject(assetKey.getName());
|
||||
}
|
||||
|
||||
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) {
|
||||
// String path = (String) wiz.getProperty("path");
|
||||
AssetKey modelKey = (AssetKey) wiz.getProperty("mainkey");
|
||||
boolean keepFiles = (Boolean) wiz.getProperty("keepfiles");
|
||||
|
||||
@ -126,27 +114,12 @@ public final class ImportModel implements ActionListener {
|
||||
if (manager == null) {
|
||||
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>();
|
||||
int i = 0;
|
||||
for (FileObject source : assetList) {
|
||||
AssetKey assetKey = assetKeys.get(i++);
|
||||
for (Iterator<FileObject> it = assetList.iterator(); it.hasNext();) {
|
||||
FileObject source = it.next();
|
||||
String folderName = importPath + "/" + importManager.getRelativeAssetPath(source.getParent().getPath());
|
||||
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);
|
||||
if (dest == null) {
|
||||
dest = FileUtil.createFolder(manager.getAssetFolder(), folderName);
|
||||
@ -170,6 +143,7 @@ public final class ImportModel implements ActionListener {
|
||||
if (fileObj != null) {
|
||||
DataObject obj = DataObject.find(fileObj);
|
||||
AssetData data = obj.getLookup().lookup(AssetData.class);
|
||||
AssetKey assetKey = data.getAssetKey();
|
||||
if (data != null) {
|
||||
if (obj instanceof SpatialAssetDataObject) {
|
||||
// Delete models that are not J3O.
|
||||
|
@ -80,7 +80,7 @@ public final class ModelImporterVisualPanel1 extends JPanel {
|
||||
manager = null;
|
||||
dataObject = null;
|
||||
data = null;
|
||||
manager = new ProjectAssetManager(FileUtil.toFileObject(path).getParent(), true);
|
||||
manager = new ProjectAssetManager(FileUtil.toFileObject(path).getParent());
|
||||
try {
|
||||
dataObject = DataObject.find(FileUtil.toFileObject(path));
|
||||
data = dataObject != null ? dataObject.getLookup().lookup(AssetData.class) : null;
|
||||
|
Loading…
x
Reference in New Issue
Block a user