[SDK] Is it posible to set up the SDK in order to load j3md files from a jar library to the Material

@H said:
cool!!

I will check it.

Hm.. I checked how its loaded and its loading from the JmeSystem that comes with the SDK.. That means the j3md will not be loaded as its not the project classpath that is used.. We gotta add something to load the data from the ProjectAssetManager instead of JmeSystem (EditableMaterialFile.java, line 180).
@normen said:
Hm.. I checked how its loaded and its loading from the JmeSystem that comes with the SDK.. That means the j3md will not be loaded as its not the project classpath that is used.. We gotta add something to load the data from the ProjectAssetManager instead of JmeSystem (EditableMaterialFile.java, line 180).


Material Definition dropdown has j3md files from jars and from assets folder but has not j3md files from source folder.
j3md template use Common/MatDefs/Misc/SolidColor.vert and Common/MatDefs/Misc/SolidColor.frag. These two files do not exist enymore I think.

Check this image
http://i.imgur.com/Jrsn0.png
@H said:
Material Definition dropdown has j3md files from jars and from assets folder but has not j3md files from source folder.

They are not supposed to, j3md files should be stored in the assets folder.
@normen said:
They are not supposed to, j3md files should be stored in the assets folder.

A game project would has j3md files stored in the assets folder, but I was thinking on a library/plugin though. It may has jm3d files on the source folder just as jme3-core-effects has. So if you want to build some test in the same library then you won't see those j3md files on the dropdown. In this case, the solution is to create the library and the test as different projects. Never mind. I think you are right, it's ok just load j3md from assets folder and from jars.

Any tip on how to load the data from the ProjectAssetManager instead of JmeSystem (EditableMaterialFile.java, line 180)?
@H said:
Any tip on how to load the data from the ProjectAssetManager instead of JmeSystem (EditableMaterialFile.java, line 180)?

You'd have to create an inputStream like JmeSystem does.
@normen said:
You'd have to create an inputStream like JmeSystem does.


Hi normen,

Please, check the following changes:
- Added ProjectAssetManager.getResourceAsStream(String name) method. It gets a j3md file.
- Changes Set intead of Arraylist for j3md file names in order to avoid duplicates.

[patch]
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -7,7 +7,6 @@
import com.jme3.gde.core.assets.ProjectAssetManager;
import com.jme3.material.MatParam;
import com.jme3.material.Material;
-import com.jme3.system.JmeSystem;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -177,7 +176,7 @@
fs = FileUtil.createMemoryFileSystem();
matDef = fs.getRoot().createData(name, "j3md");
OutputStream out = matDef.getOutputStream();
- InputStream in = JmeSystem.getResourceAsStream("/" + getMatDefName());
+ InputStream in = manager.getResourceAsStream(getMatDefName());
if (in != null) {
int input = in.read();
while (input != -1) {
[/patch]

[patch]
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -35,14 +35,18 @@
import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager;
import com.jme3.asset.DesktopAssetManager;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.java.classpath.ClassPath;
@@ -329,7 +333,8 @@
* @return
*/
private String[] collectFilesWithSuffix(String suffix) {
- ArrayList<String> list = new ArrayList<String>();
+// ArrayList<String> list = new ArrayList<String>();
+ Set<String> list = new HashSet<String>();
FileObject assetsFolder = getAssetFolder();
if (assetsFolder != null) {
Enumeration<FileObject> assets = (Enumeration<FileObject>) assetsFolder.getChildren(true);
@@ -495,4 +500,32 @@

public void classPathChanged(ProjectAssetManager manager);
}
+
+ public InputStream getResourceAsStream(String name) {
+ InputStream in = this.getClass().getResourceAsStream(name);
+
+ if (in == null && classPathItems != null) {
+ // TODO I need to find out if classPathItems contains all jars added to a project
+ Iterator<ClassPathItem> classPathItemsIter = classPathItems.iterator();
+ while (classPathItemsIter.hasNext()) {
+ ClassPathItem classPathItem = classPathItemsIter.next();
+ FileObject jarFile = classPathItem.object;
+
+ Enumeration<FileObject> jarEntry = (Enumeration<FileObject>) jarFile.getChildren(true);
+ while (jarEntry.hasMoreElements()) {
+ FileObject jarEntryAsset = jarEntry.nextElement();
+ if (jarEntryAsset.getPath().equalsIgnoreCase(name)) {
+ try {
+ in = jarEntryAsset.getInputStream();
+ } catch (FileNotFoundException ex) {
+ Exceptions.printStackTrace(ex);
}
+ break;
+ }
+ }
+ }
+ }
+
+ return in;
+ }
+}
[/patch]
3 Likes

Looking good, thanks!

Added in r9859.

@normen I installed shaderlib plugin, then i added shaderlib library to my project. But shaders(j3md) are not seen in MaterialEditor. Only JME matdefs are seen.



Is it possible to use MaterialEditor if i have added shaderblowlib to my project?

@mifth said:
@normen I installed shaderlib plugin, then i added shaderlib library to my project. But shaders(j3md) are not seen in MaterialEditor. Only JME matdefs are seen.

Is it possible to use MaterialEditor if i have added shaderblowlib to my project?

Only in the latest nightly, the RC2 with all updates should at least show them in the list though, that part worked for me with external libs.
1 Like
@normen said:
Only in the latest nightly, the RC2 with all updates should at least show them in the list though, that part worked for me with external libs.


Updated plugins and it works well! Thanks a lot!
@normen said:
Only in the latest nightly, the RC2 with all updates should at least show them in the list though, that part worked for me with external libs.


I found another issue. Parameters of shaderblow shaders are not loaded. I see only empty canvas. But JME shaders are with parameters.

http://i.imgur.com/MtgMh.png
@mifth said:
I found another issue. Parameters of shaderblow shaders are not loaded. I see only empty canvas. But JME shaders are with parameters.

http://i.imgur.com/MtgMh.png

Exactly, just like I said.

OOOhhhh!!! My fault. I did not switch Nightlies checkbox on. Everything works cool!!!