- 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,7 +84,6 @@ 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);
|
||||||
@ -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 path Path on disk to find assets from and the filename is loaded
|
||||||
* @param disableAbsolutePaths If true, absolute asset paths won't
|
* from the path argument directly.
|
||||||
* be used and the filename is loaded 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;
|
|
||||||
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)) {
|
for (AssetManagerConfigurator di : Lookup.getDefault().lookupAll(AssetManagerConfigurator.class)) {
|
||||||
di.prepareManager(this);
|
di.prepareManager(this);
|
||||||
}
|
}
|
||||||
@ -126,34 +120,20 @@ public class ProjectAssetManager extends DesktopAssetManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ProjectAssetManager() {
|
public ProjectAssetManager() {
|
||||||
this(null, false);
|
this(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If true, then this <code>ProjectAssetManager</code> ignores
|
* Returns the
|
||||||
* absolute asset paths.
|
* <code>FileObject</code> for a given asset key, or null if no such asset
|
||||||
* The assumption that asset paths are present physically under the assets
|
* exists. TODO: Only works for real files in the asset folder atm
|
||||||
* 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.
|
|
||||||
*
|
*
|
||||||
* @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()) {
|
|
||||||
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() {
|
private void clearClassLoader() {
|
||||||
if (jarItems.isEmpty() && classPathItems.isEmpty()) {
|
if (jarItems.isEmpty() && classPathItems.isEmpty()) {
|
||||||
|
@ -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");
|
||||||
|
|
||||||
@ -127,26 +115,11 @@ public final class ImportModel implements ActionListener {
|
|||||||
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…
x
Reference in New Issue
Block a user