- add option to add assetpack item as model
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7799 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
3f6f694030
commit
2bcc98512e
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.jme3.gde.assetpack.actions;
|
||||
|
||||
import com.jme3.export.binary.BinaryExporter;
|
||||
import com.jme3.gde.assetpack.AssetConfiguration;
|
||||
import com.jme3.gde.assetpack.AssetPackLoader;
|
||||
import com.jme3.gde.core.assets.ProjectAssetManager;
|
||||
import com.jme3.scene.Spatial;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.Action;
|
||||
import org.openide.nodes.Node;
|
||||
import org.openide.util.Exceptions;
|
||||
import org.w3c.dom.Element;
|
||||
import com.jme3.gde.scenecomposer.SceneComposerTopComponent;
|
||||
import java.io.OutputStream;
|
||||
import org.openide.filesystems.FileObject;
|
||||
|
||||
public final class AddToProjectAction implements Action {
|
||||
|
||||
private final Node context;
|
||||
|
||||
public AddToProjectAction(Node context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent ev) {
|
||||
ProjectAssetManager pm = context.getLookup().lookup(ProjectAssetManager.class);
|
||||
if (pm == null) {
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "AssetManager not found!");
|
||||
return;
|
||||
}
|
||||
Element assetElement = context.getLookup().lookup(Element.class);
|
||||
String type = assetElement.getAttribute("type");
|
||||
try {
|
||||
if ("model".equals(type) || "scene".equals(type)) {
|
||||
AssetConfiguration conf = new AssetConfiguration(assetElement);
|
||||
Spatial model = AssetPackLoader.loadAssetPackModel(pm, conf);
|
||||
if (model != null) {
|
||||
FileObject modelFolder = pm.getAssetFolder().getFileObject("Models");
|
||||
if (modelFolder == null) {
|
||||
modelFolder = pm.getAssetFolder().createFolder("Models");
|
||||
}
|
||||
if (modelFolder.isFolder()) {
|
||||
AssetPackLoader.addModelFiles(pm, conf);
|
||||
SceneComposerTopComponent.findInstance().addModel(model);
|
||||
OutputStream out = modelFolder.createAndOpen(conf.getAssetElement().getAttribute("name") + ".j3o");
|
||||
BinaryExporter.getInstance().save(model, out);
|
||||
out.close();
|
||||
modelFolder.refresh();
|
||||
} else {
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Cannot copy, file 'Models' exists");
|
||||
}
|
||||
} else {
|
||||
Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Error loading model");
|
||||
}
|
||||
} else {
|
||||
AssetConfiguration conf = new AssetConfiguration(assetElement);
|
||||
AssetPackLoader.addAllFiles(pm, conf);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Exceptions.printStackTrace(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValue(String key) {
|
||||
if (key.equals(NAME)) {
|
||||
return "Add to SceneComposer..";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void putValue(String key, Object value) {
|
||||
}
|
||||
|
||||
public void setEnabled(boolean b) {
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener) {
|
||||
}
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener) {
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@
|
||||
package com.jme3.gde.assetpack.browser.nodes;
|
||||
|
||||
import com.jme3.gde.assetpack.actions.AddAssetAction;
|
||||
import com.jme3.gde.assetpack.actions.AddToProjectAction;
|
||||
import com.jme3.gde.assetpack.actions.PreviewAssetAction;
|
||||
import com.jme3.gde.assetpack.browser.AssetPackLibrary;
|
||||
import com.jme3.gde.assetpack.browser.properties.ElementAttributeProperty;
|
||||
@ -45,11 +46,13 @@ public class AssetPackBrowserItem extends AbstractNode {
|
||||
private Project project;
|
||||
private PreviewAssetAction previewAction;
|
||||
private AddAssetAction addAction;
|
||||
private AddToProjectAction addProjectAction;
|
||||
|
||||
public AssetPackBrowserItem(Element item, Project proj) {
|
||||
super(Children.LEAF, proj != null ? Lookups.fixed(item, proj, proj.getLookup().lookup(ProjectAssetManager.class)) : Lookups.fixed(item));
|
||||
addAction = new AddAssetAction(this);
|
||||
previewAction = new PreviewAssetAction(this);
|
||||
addProjectAction = new AddToProjectAction(this);
|
||||
this.item = item;
|
||||
this.project = proj;
|
||||
setName(item.getAttribute("name"));
|
||||
@ -75,6 +78,7 @@ public class AssetPackBrowserItem extends AbstractNode {
|
||||
public Action[] getActions(boolean context) {
|
||||
if (project.getLookup().lookup(AssetPackLibrary.class) != null) {
|
||||
return new Action[]{
|
||||
addProjectAction,
|
||||
addAction,
|
||||
previewAction
|
||||
};
|
||||
@ -88,7 +92,7 @@ public class AssetPackBrowserItem extends AbstractNode {
|
||||
// if (project.getLookup().lookup(AssetPackLibrary.class) != null) {
|
||||
// return addAction;
|
||||
// } else {
|
||||
return previewAction;
|
||||
return previewAction;
|
||||
// }
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ public final class CleanupProjectAction implements Action {
|
||||
if ("png".equalsIgnoreCase(fileObject.getExt())
|
||||
|| "jpg".equalsIgnoreCase(fileObject.getExt())
|
||||
|| "dds".equalsIgnoreCase(fileObject.getExt())
|
||||
|| "dae".equalsIgnoreCase(fileObject.getExt())
|
||||
|| "bmp".equalsIgnoreCase(fileObject.getExt())) {
|
||||
for (String path : paths) {
|
||||
if (fileObject.getPath().endsWith(path)) {
|
||||
|
@ -76,6 +76,7 @@ public final class PublishAssetPackAction implements Action {
|
||||
try {
|
||||
String outFilename = context.getProjectDirectory().getPath() + "/" + wiz.getProperty("filename");
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(new File(outFilename)));
|
||||
out.setLevel(9);
|
||||
zipDir(((AssetPackProject) context).getProjectDirectory(), out, (String) wiz.getProperty("filename"));
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user