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

Hi @normen



Is it posible to set up the SDK so I can see j3md files from a library on the Material Definiton dropdown on the Material Editor? What should I do?



Let say that I add a library through the JME User Contribution repo. This library is a jar file and has 2 j3md files located on com.terra.matdef package. I want to create a new j3m file for one of this j3md files but I see “Common” j3md files and j3md files from assets/MatDefs on Material Definiton dropdown when I create the new j3m file. Is there a way to made that SDK populates the dropdown with the j3md files from the library?





PS: Perhaps, specifying (in some place) the packages where SDK should look for j3md can be a feasible (without impact on SDK perfomance) solution.

It only adds those that are in the assets folder at the moment, I guess some kind of ServiceProvider (similar to the AssetManagerConfigurator) for that would be feasible. Better yet it would look them up in the classpath of the project itself.



Edit: Actually it should do the latter because otherwise its not possible to say if that j3md is available in that project at all…

Btw, if this is about the ShaderBlow thing, I was thinking if its maybe good to supply that as an AssetPack… Or a completely different kind of plugin that allows you to add the shaders and j3md etc. to your projects assets.

ShaderBlow has shaders (.vert and .frag files) and j3md files but it also has Filters, PostProcesors and Controls (java files). So far, I know AssetPack does not include java files, Is that correct?

Well they’d end up in the assets folder which is probably not good, I’d have to extend the AssetPack format for java file support (which might be a good idea at some point). Still I’d like a different kind of support for these as they are also not simple java libraries, I guess often users would want to change the shader sources. Something similar to AssetPacks but for shaders maybe. Maybe the ShaderBlow plugin can at the same time be a testing ground for such a thing :slight_smile:

I think the idea behing ShaderBlow is a collention of shaders, matDefs, filters, controlers, etc. Collection of resources/assets. Users would add ShaderBlow to their projects and would use the resourses without any modification (out of the box; they may copy a matDef into project’s assets folder and add new functionality of course).

@H said:
I think the idea behing ShaderBlow is a collention of shaders, matDefs, filters, controlers, etc. Collection of resources/assets. Users would add ShaderBlow to their projects and would use the resourses without any modification (out of the box; they may copy a matDef into project's assets folder and add new functionality of course).

So then its down to scanning the classpath.

Ok, I will try to do it but I’m not familiar with netbean / netbean plugin development, so I will need time.

@H said:
Ok, I will try to do it but I'm not familiar with netbean / netbean plugin development, so I will need time.

The ProjectAssetManager has the classpath of the project, it also has the method where the list of j3md files is generated.
@normen said:
The ProjectAssetManager has the classpath of the project, it also has the method where the list of j3md files is generated.


I took a quick view to jme3-materialeditor project and to ProjectAssetManager class. Currently getMAtDefs look into asset folder. I think I should modify ProjectAssetManager.getMatDefs method in order to search for j3md files in project classpath too, right?
@H said:
I took a quick view to jme3-materialeditor project and to ProjectAssetManager class. Currently getMAtDefs look into asset folder. I think I should modify ProjectAssetManager.getMatDefs method in order to search for j3md files in project classpath too, right?

exactly :) You should also check how the MaterialEditor loads the files, as it should then also be able to stream them from a jar.
@normen said:
exactly :) You should also check how the MaterialEditor loads the files, as it should then also be able to stream them from a jar.


Is this for in the SDK or while running an application? The only reason I ask is because Java provides no reliable way to wild-card search the class resources in a deployed application.
@pspeed said:
Is this for in the SDK or while running an application? The only reason I ask is because Java provides no reliable way to wild-card search the class resources in a deployed application.

SDK. And there it works, it goes down to jar level etc. I already do all kinds of magic with that ;)

Hi @normen



I’ve installed sdk RC2 and checkout all project from trunk repo folder. Then I open engine project, sdk project. After that, I open all the modules called jme3-…



I see compilation error on SDK modules: SDK can not resolve imports related to engine classes:

import com.jme3.material.MatParam;

import com.jme3.material.Material;

import com.jme3.system.JmeSystem;



What are the step required to import SDK source code into SDK?

What should I need to do in order to solve this error?

Read the manual as always ^^ You have to build the main freeform project once to get the libraries over (the one in the trunk folder).

@normen said:
Read the manual as always ^^ You have to build the main freeform project once to get the libraries over (the one in the trunk folder).


Sorry for that. It's working now, thanks.

ProjectAssetManager has:
[java]
private LinkedList<FileObject> jarItems = new LinkedList<FileObject>();
private LinkedList<ClassPathItem> classPathItems = new LinkedList<ClassPathItem>();
[/java]

Those attributes have a list of jars. Should I use one of those 2 attribute? or should I use:
[java]private Project project;[/java]

Project has getProjectDirectory(); and getLookup(); methods but I don't know if I should use them.

have you implemented something similar to this? can you send me alink to the code in order to use it as reference?
Any help will be very appreciate

Check the changes on getMatDefs():



[java]

public String[] getMatDefs() {

FileObject assetsFolder = getAssetFolder();

if (assetsFolder == null) {

return new String[]{};

}

Enumeration<FileObject> assets = (Enumeration<FileObject>) assetsFolder.getChildren(true);

ArrayList<String> list = new ArrayList<String>();

while (assets.hasMoreElements()) {

FileObject asset = assets.nextElement();

if (asset.getExt().equalsIgnoreCase(“j3md”)) {

list.add(getRelativeAssetPath(asset.getPath()));

}

}



// 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.getExt().equalsIgnoreCase(“j3md”)) {

list.add(getRelativeAssetPath(jarEntryAsset.getPath()));

}

}



}



return list.toArray(new String[list.size()]);

}

[/java]



This is what I have implemented so far. I need to find out if classPathItems contains all jars added to a project or should I get the jar file list from other place?.



I need to get j3md files from project’s src file also.



Updated: Material Definitions is populated with the j3md files from the list of jars on classPathItems

1 Like

Cool. You should make sure if its jar files yeah, all kinds of things like folders etc. could be on the classpath.

Okay, I added the change in the nightly version, we should probably check it a bit before adding it to stable.

Edit: Ah whatever, seems to work, did so before as well :wink:

@normen said:
Okay, I added the change in the nightly version, we should probably check it a bit before adding it to stable.
Edit: Ah whatever, seems to work, did so before as well ;)


cool!!

I will check it.